@@ -140,6 +140,8 @@ export default class PracticeTask extends BaseScene {
140140
141141 this . interruptionExitTaskDialog = false ;
142142 this . bottomScreenPanel = null ;
143+ this . powerPanel = null ;
144+ this . interruptionOccured = false ;
143145
144146 ////////////////////////CREATE WORLD//////////////////////////////////////
145147 // game world created in Tiled (https://www.mapeditor.org/)
@@ -317,6 +319,69 @@ export default class PracticeTask extends BaseScene {
317319 this . launchNextScene ( ) ;
318320 }
319321 }
322+
323+ showExitDialogAfterInterruption ( ) {
324+ // a user was interrupted whilst in the middle of an individual trial, in this scenario we won't allow them to
325+ // continue to the next practice trial.
326+ // In all scenarios we will show the exit dialog and the user will need to restart from the beginning of the practice task.
327+
328+ /*
329+ 1. If current animation playing is the walking animation before the route selector apears
330+ 2. If the route selector panel is visible,
331+ 3. If the power up scene is active
332+ 4. If the user has already completed the trial and is crossing the bridge, show the dialog once pickle reaches the end of the bridge
333+ */
334+ let isLastPracticeTrial = pracTrial == nPracTrials - 1 ;
335+
336+ if ( this . player . sprite . x <= decisionPointX && this . player . sprite . anims . currentAnim . key == 'run' && ! isLastPracticeTrial ) {
337+ console . log ( '1A-A' ) ;
338+
339+ // no active panel, stop the player and show the dialog
340+ stopPlayer ( this ) ;
341+ showExitTaskDialog ( this ) ;
342+ } else if ( this . instructionsPanel != null && this . player . sprite . body . velocity . x == 0 && this . player . sprite . anims . currentAnim . key == 'wait' && ! isLastPracticeTrial ) {
343+ console . log ( '1A-B' ) ;
344+
345+ // remove any active feedback message
346+ if ( feedbackMessage ) {
347+ clearTimeout ( routeSelectionTransitionTimer ) ;
348+ feedbackMessage . destroy ( ) ;
349+ feedbackMessage = null ;
350+ }
351+
352+ // remove the route selector panel
353+ this . instructionsPanel . destroy ( ) ;
354+ this . instructionsPanel = null ;
355+
356+ // show the exit task dialog in its place
357+ stopPlayer ( this ) ;
358+ showExitTaskDialog ( this ) ;
359+ } else if ( this . powerPanel != null && [ 'powerup' , 'wait' ] . includes ( this . player . sprite . anims . currentAnim . key ) && ! isLastPracticeTrial ) {
360+ console . log ( '1A-C' ) ;
361+
362+ // mark that an interruption occured so the feedback message dismiss handler doesn't run
363+ this . interruptionOccured = true ;
364+
365+ // remove any active feedback message
366+ if ( feedbackMessage ) {
367+ clearTimeout ( routeSelectionTransitionTimer ) ;
368+ feedbackMessage . destroy ( ) ;
369+ feedbackMessage = null ;
370+ }
371+
372+ // remove the power panel
373+ this . powerPanel . destroy ( ) ;
374+ this . powerPanel = null ;
375+
376+ // show the exit task dialog in its place
377+ stopPlayer ( this ) ;
378+ showExitTaskDialog ( this ) ;
379+ } else {
380+ // do nothing, player will be walking across the bridge, the exit dialog will be shown at the end of the bridge
381+ console . log ( '1A-D' ) ;
382+ this . interruptionExitTaskDialog = true ;
383+ }
384+ }
320385}
321386
322387///////////////////////////////FUNCTIONS FOR CONTROLLING TRIAL SEQUENCE/////////////////////////////////////
@@ -530,7 +595,9 @@ var effortOutcome = function() {
530595 // then play powerup fail anim and progress via slow route
531596 this . time . addEvent ( { delay : pracFeedbackTime + 250 ,
532597 callback : function ( ) {
533- feedbackMessage . destroy ( ) ;
598+ if ( this . interruptionOccured ) { return ; }
599+
600+ feedbackMessage ?. destroy ( ) ;
534601 // then play short 'powerup fail' anim:
535602 this . player . sprite . anims . play ( 'powerupfail' , true ) ;
536603 // and progress via bridge route (with sad face)
@@ -587,6 +654,8 @@ var effortOutcome = function() {
587654 // then player floats across 'high route' and collects coins
588655 this . time . addEvent ( { delay : pracFeedbackTime + 250 ,
589656 callback : function ( ) {
657+ if ( this . interruptionOccured ) { return ; }
658+
590659 let playerSpeedAdjustment = window . innerHeight < 800 ? 4 : 3 ; // slow down the player a bit more on the smaller screens so they dont miss the coins
591660 feedbackMessage ?. destroy ( ) ;
592661 this . player . sprite . anims . play ( 'float' , true ) ;
@@ -601,6 +670,8 @@ var effortOutcome = function() {
601670 // then player floats across 'low route' and collects coins
602671 this . time . addEvent ( { delay : pracFeedbackTime + 250 ,
603672 callback : function ( ) {
673+ if ( this . interruptionOccured ) { return ; }
674+
604675 feedbackMessage ?. destroy ( ) ;
605676 this . player . sprite . anims . play ( 'float' , true ) ;
606677 this . player . sprite . setVelocityX ( playerVelocity / 3 ) ;
@@ -644,7 +715,9 @@ var effortOutcome = function() {
644715 // then play powerup fail anim and progress via slow route
645716 this . time . addEvent ( { delay : pracFeedbackTime + 250 ,
646717 callback : function ( ) {
647- feedbackMessage . destroy ( ) ;
718+ if ( this . interruptionOccured ) { return ; }
719+
720+ feedbackMessage ?. destroy ( ) ;
648721 // then play short 'powerup fail' anim:
649722 this . player . sprite . anims . play ( 'powerupfail' , true ) ;
650723 // and progress via bridge route (with sad face)
@@ -665,6 +738,20 @@ var effortOutcome = function() {
665738
666739// 4. When player hits end of scene, save trial data and move on to the next trial (reload the scene)
667740var pracTrialEnd = function ( ) {
741+ // if the interruption needs to be shown, just show that, no practice trial data will be sent off,
742+ // no maxPressCount update, etc. The user will have to return to the start of the practice trials so
743+ // they will go through the calibration rounds eventually
744+
745+ let isLastPracticeTrial = pracTrial == nPracTrials - 1 ;
746+ // if we encountered an interruption, show the exit dialog but dont increment attempt count.
747+ // theres no need to reset progress since since the game state isn't updated untill we complete all the practice rounds
748+ if ( this . interruptionExitTaskDialog == true && ! isLastPracticeTrial ) {
749+ stopPlayer ( this ) ;
750+ showExitTaskDialog ( this ) ;
751+ this . interruptionExitTaskDialog = false ;
752+ return ;
753+ }
754+
668755 // determine if pressCount exceeded previous practice trials,
669756 // we don't want to update the max press count if we've completed the calibration
670757 if ( GameCache . cache ?. calibrationComplete == true ) {
@@ -692,19 +779,14 @@ var pracTrialEnd = function () {
692779 // savePracTaskData(pracTrial, this.registry.get(`pracTrial${pracTrial}`)); // [for firebase]
693780 //saveTrialDataPav(this.registry.get(`pracTrial${pracTrial}`)); // [for Pavlovia deployment]
694781
695- let isLastPracticeTrial = pracTrial == nPracTrials - 1 ;
696- // if we encountered an interruption, show the exit dialog but dont increment atempt count.
697- // theres no need to reset progress since since the game state isn't updated untill we complete all the practice rounds
698- if ( this . interruptionExitTaskDialog == true && ! isLastPracticeTrial ) {
699- stopPlayer ( this ) ;
700- showExitTaskDialog ( this ) ;
701- this . interruptionExitTaskDialog = false ;
702- } else {
703- // iterate trial number
704- pracTrial ++ ;
705- // move to next trial
706- this . scene . restart ( ) ;
707- }
782+ // iterate trial number
783+ pracTrial ++ ;
784+
785+ // clear any event listners still active so they aren't leaked
786+ eventsCenter . removeAllListeners ( ) ;
787+
788+ // move to next trial
789+ this . scene . restart ( ) ;
708790} ;
709791
710792
0 commit comments