@@ -449,9 +449,16 @@ export class Drawer {
449449
450450 updateScene ( scope , question , frames , frameNumber , progress , speed , reason , demo , force ) {
451451 const parsedFrame = frames [ frameNumber ]
452- if ( ! force && this . stepByStepAnimateSpeed && this . checkSteppedToNextFrame ( scope , parsedFrame ) ) {
453- this . startAsynchronousAnimation ( scope , progress , parsedFrame )
454- return
452+ if ( ! force && this . stepByStepAnimateSpeed ) {
453+ if ( this . checkSteppedToNextFrame ( scope , parsedFrame , progress ) ) {
454+ this . startAsynchronousAnimation ( scope , parsedFrame )
455+ return
456+ } else if ( this . checkSteppedToPreviousFrame ( scope , parsedFrame , progress ) ) {
457+ const reversed = true
458+ this . startAsynchronousAnimation ( scope , scope . currentFrame , reversed )
459+ return
460+ }
461+ scope . targetProgress = null
455462 }
456463
457464 /** ************************************* */
@@ -474,14 +481,27 @@ export class Drawer {
474481 }
475482 }
476483
477- startAsynchronousAnimation ( scope , progress , currentFrame ) {
478- scope . targetProgress = progress
479- scope . currentProgress = 0
480- scope . currentFrame = currentFrame
484+ startAsynchronousAnimation ( scope , frameToAnimate , reversed = false ) {
485+ scope . targetProgress = reversed ? 0 : 1
486+ if ( ! reversed && scope . currentProgress === 1 ) {
487+ scope . currentProgress = 0
488+ }
489+ scope . currentFrame = frameToAnimate
490+ scope . reverseAsynchronousAnimation = reversed
491+ }
492+
493+ checkStepped ( scope , selectedFrame , progress ) {
494+ return scope . currentFrame && this . speed === 0 && progress === 1
495+ }
496+
497+ checkSteppedToNextFrame ( scope , selectedFrame , progress ) {
498+ return this . checkStepped ( scope , selectedFrame , progress ) &&
499+ ( scope . currentFrame === selectedFrame . previous || ( scope . currentFrame === selectedFrame && scope . currentProgress !== progress ) )
481500 }
482501
483- checkSteppedToNextFrame ( scope , parsedFrame ) {
484- return scope . currentFrame && scope . currentFrame !== parsedFrame && scope . currentFrame === parsedFrame . previous && this . speed === 0
502+ checkSteppedToPreviousFrame ( scope , selectedFrame , progress ) {
503+ return this . checkStepped ( scope , selectedFrame , progress ) &&
504+ scope . currentFrame . previous === selectedFrame
485505 }
486506
487507 initEndScene ( scope , failure ) {
@@ -525,9 +545,27 @@ export class Drawer {
525545 }
526546
527547 if ( this . stepByStepAnimateSpeed && this . isAsynchronousAnimationOngoing ( scope ) ) {
528- var p = scope . currentProgress + step / 200 * this . getFrameSpeed ( this . currentFrame ) * this . stepByStepAnimateSpeed
529- p = Math . min ( scope . targetProgress , p )
530- this . updateScene ( this . scope , this . question , this . frames , this . currentFrame , p , this . speed , this . reasons [ this . currentFrame ] , false , true )
548+ let frameToShow = this . currentFrame
549+ let progressToShow
550+
551+ if ( scope . reverseAsynchronousAnimation ) {
552+ frameToShow ++
553+ }
554+
555+ const progressDelta = step / 200 * this . getFrameSpeed ( frameToShow ) * this . stepByStepAnimateSpeed
556+
557+ if ( scope . reverseAsynchronousAnimation ) {
558+ progressToShow = scope . currentProgress - progressDelta
559+ if ( progressToShow <= 0 ) {
560+ frameToShow = this . currentFrame
561+ progressToShow = 1
562+ scope . targetProgress = 1
563+ }
564+ } else {
565+ progressToShow = scope . currentProgress + progressDelta
566+ progressToShow = Math . min ( scope . targetProgress , progressToShow )
567+ }
568+ this . updateScene ( this . scope , this . question , this . frames , frameToShow , progressToShow , this . speed , this . reasons [ frameToShow ] , false , true )
531569 }
532570
533571 for ( const moduleName in this . modules ) {
0 commit comments