@@ -30,11 +30,28 @@ class $modify(SpamPlayLayer, PlayLayer) {
3030 nextSpam ();
3131 };
3232
33+ void resetLevelFromStart () {
34+ PlayLayer::resetLevelFromStart ();
35+ cue::resetNode (m_fields->currentSpam );
36+ }
37+
3338 void levelComplete () {
3439 PlayLayer::levelComplete ();
3540 cue::resetNode (m_fields->currentSpam );
3641 };
3742
43+ void togglePracticeMode (bool practiceMode) {
44+ PlayLayer::togglePracticeMode (practiceMode);
45+
46+ cue::resetNode (m_fields->currentSpam );
47+ nextSpam ();
48+ };
49+
50+ void onQuit () {
51+ PlayLayer::onQuit ();
52+ cue::resetNode (m_fields->currentSpam );
53+ };
54+
3855 void destroyPlayer (PlayerObject* player, GameObject* object) {
3956 PlayLayer::destroyPlayer (player, object);
4057
@@ -46,41 +63,41 @@ class $modify(SpamPlayLayer, PlayLayer) {
4663
4764 void nextSpam () {
4865 log::trace (" scheduling spam challenge" );
66+
67+ unschedule (schedule_selector (SpamPlayLayer::doSpam));
4968 if (!m_hasCompletedLevel) scheduleOnce (schedule_selector (SpamPlayLayer::doSpam), rng::get (30 .f , 5 .f ) * chanceToDelayPct (m_fields->chance ));
5069 };
5170
5271 void doSpam (float ) {
53- if (!m_isPracticeMode && !m_hasCompletedLevel && !m_playerDied) {
54- log::debug (" Showing spam challenge" );
72+ auto f = m_fields.self ();
5573
56- if (options::isEnabled (THIS_ID)) {
57- if (auto spam = SpamChallenge::create ()) {
58- auto f = m_fields.self ();
74+ if (options::isEnabled (THIS_ID) && !f->currentSpam && !m_isPracticeMode && !m_hasCompletedLevel && !m_playerDied) {
75+ log::debug (" Showing spam challenge" );
5976
60- // handle correct/wrong answer
61- spam->setCallback ([self = WeakRef (this ), challenge = WeakRef (spam)](bool success) {
62- if (auto s = self.lock ()) {
63- log::debug (" spam {}" , success ? " succeeded" : " failed" );
77+ if (auto spam = SpamChallenge::create ()) {
78+ auto f = m_fields.self ();
6479
65- if (!success) s->resetLevelFromStart ();
66- s->nextSpam ();
80+ // handle correct/wrong answer
81+ spam->setCallback ([self = WeakRef (this ), challenge = WeakRef (spam)](bool success) {
82+ if (auto s = self.lock ()) {
83+ if (!success) s->resetLevelFromStart ();
84+ s->nextSpam ();
6785
68- cursor::hide ();
86+ cursor::hide ();
6987
70- if (auto spam = challenge.lock ()) spam->removeFromParent ();
71- };
72- });
88+ if (auto spam = challenge.lock ()) spam->removeFromParent ();
89+ };
90+ });
7391
74- m_uiLayer->addChild (spam, 99 );
75- f->currentSpam = spam;
92+ m_uiLayer->addChild (spam, 99 );
93+ f->currentSpam = spam;
7694
77- cursor::show ();
78- };
79- } else {
80- queueInMainThread ([self = WeakRef (this )]() {
81- if (auto s = self.lock ()) s->nextSpam ();
82- });
95+ cursor::show ();
8396 };
8497 };
98+
99+ queueInMainThread ([self = WeakRef (this )]() {
100+ if (auto s = self.lock ()) s->nextSpam ();
101+ });
85102 };
86103};
0 commit comments