@@ -24,6 +24,7 @@ float randomNumberInAGivenRangeThatGetsAddedOrRemovedFromADifferentNumber(float
2424void DeltaruneAlertLayer::initMaps () {
2525 auto & nameToFile = m_fields->nameToFile ;
2626 auto & nameToSound = m_fields->nameToSound ;
27+ auto & nameToSoundRate = m_fields->nameToSoundRate ;
2728
2829 nameToFile[" Default" ] = " SND_TXT1" ;
2930 nameToFile[" Typewriter" ] = " SND_TXT2" ;
@@ -57,6 +58,24 @@ void DeltaruneAlertLayer::initMaps() {
5758 nameToSound[" Globed" ] = " Tenna" ;
5859 nameToSound[" Globed Error" ] = " Tenna" ;
5960 nameToSound[" Globed notice" ] = " Tenna" ; // I thought it was funny
61+
62+ nameToSoundRate[" Tenna" ] = 3 ;
63+ nameToSoundRate[" Jackenstein" ] = 3 ;
64+ nameToSoundRate[" Gerson" ] = 3 ;
65+ nameToSoundRate[" Queen" ] = 3 ;
66+ }
67+
68+ void DeltaruneAlertLayer::initSoundRate () {
69+ auto & soundRate = m_fields->soundRate ;
70+ auto & soundTimer = m_fields->soundTimer ;
71+ auto & textSound = m_fields->textSound ;
72+ auto & nameToSoundRate = m_fields->nameToSoundRate ;
73+
74+ if (nameToSoundRate.find (textSound) == nameToSoundRate.end ())
75+ return ;
76+
77+ soundRate = nameToSoundRate[textSound];
78+ soundTimer = soundRate;
6079}
6180
6281bool DeltaruneAlertLayer::init (FLAlertLayerProtocol* delegate, char const * title, gd::string desc, char const * btn1, char const * btn2, float width, bool scroll, float height, float textScale) {
@@ -88,6 +107,7 @@ bool DeltaruneAlertLayer::init(FLAlertLayerProtocol* delegate, char const* title
88107 auto & titleNode = m_fields->title ;
89108
90109 initMaps (); // for sounds
110+ initSoundRate ();
91111
92112 this ->m_noElasticity = true ;
93113
@@ -520,25 +540,28 @@ void DeltaruneAlertLayer::rollText(float dt) {
520540 int & linesProgressed = m_fields->linesProgressed ;
521541 int & characterCount = m_fields->characterCount ;
522542 int & rollingLine = m_fields->rollingLine ;
523- bool & playedSound = m_fields->playedSound ;
524543 bool & doneRolling = m_fields->doneRolling ;
525544 bool & rolledPage = m_fields->rolledPage ;
526545 float & lostTime = m_fields->lostTime ;
527546 double const pause = Mod::get ()->getSettingValue <double >(" textRollingPause" ) / 30 ;
547+ auto & soundTimer = m_fields->soundTimer ;
548+ auto & soundRate = m_fields->soundRate ;
528549
529550 if (dt - pause > pause)
530551 lostTime += dt - pause;
531552
532553 bool playSound = true ;
533554 char character;
534555
556+ soundTimer++;
557+
535558 for (bool firstRun{true }; lostTime >= pause || firstRun; firstRun = false ) {
536559 bool newLine = false ;
537560
538561 if (waitQueue != 0 ) {
539562 waitQueue--;
540- playedSound = false ;
541563 playSound = false ;
564+
542565 if (lostTime >= pause && !firstRun) {
543566 lostTime -= pause;
544567 }
@@ -570,7 +593,7 @@ void DeltaruneAlertLayer::rollText(float dt) {
570593 character = line->getString ()[characterCount];
571594 switch (character) {
572595 case ' ' :
573- waitQueue = 1 ;
596+ waitQueue = 0 ;
574597 playSound = false ;
575598 break ;
576599 case ' .' :
@@ -611,8 +634,7 @@ void DeltaruneAlertLayer::rollText(float dt) {
611634 }
612635 }
613636
614- if (!playSound || playedSound) {
615- playedSound = false ;
637+ if (!playSound || soundTimer < soundRate) {
616638 return ;
617639 }
618640
@@ -622,16 +644,18 @@ void DeltaruneAlertLayer::rollText(float dt) {
622644void DeltaruneAlertLayer::playSound (char character) {
623645 auto & nameToFile = m_fields->nameToFile ;
624646 auto & textSound = m_fields->textSound ;
625- auto & playedSound = m_fields->playedSound ;
626- auto & prevSoundNum = m_fields->prevSoundNum ;
647+ auto & soundRate = m_fields->soundRate ;
648+ auto & soundTimer = m_fields->soundTimer ;
649+ auto & prevSoundNum = m_fields->prevSoundNum ;
627650 auto const resFolder = Mod::get ()->getResourcesDir ();
628651
629652 if (nameToFile.find (textSound) == nameToFile.end ()) return ;
630653
631654 handleAprilFools ();
632655
633656 float pitch = 1 .f ;
634- playedSound = true ;
657+
658+ soundTimer = 0 ;
635659
636660 auto & system = m_fields->system ;
637661 auto & channel = m_fields->channel ;
@@ -649,12 +673,12 @@ void DeltaruneAlertLayer::playSound(char character) {
649673 soundNumber = 5 ;
650674 else {
651675 soundNumber = mt () % numSounds + 1 ;
652- while (prevSoundNum == soundNumber) {
653- soundNumber = mt () % numSounds + 1 ;
654- }
676+ while (prevSoundNum == soundNumber) {
677+ soundNumber = mt () % numSounds + 1 ;
678+ }
655679 }
656680
657- prevSoundNum = soundNumber;
681+ prevSoundNum = soundNumber;
658682
659683 file = fmt::format (" snd_txtten{}" , soundNumber);
660684 }
0 commit comments