Pause Movie timers

This commit is contained in:
2023-04-03 10:57:00 -06:00
parent a7e50fcfce
commit 55b8c30407
5 changed files with 87 additions and 32 deletions

View File

@@ -30,16 +30,22 @@
sh)
(method :Void pause []
(FlxG.inputs.remove actionManager)
// TODO !!
null)
(method :Void resume []
// TODO !!
(FlxG.inputs.add actionManager)
null)
(method :Void showPauseMenu [:Continuation resume]
// TODO
null)
// TODO register escape to resume (and register escape to pause lol)
(chooseString "PAUSED" ["Resume"]
->choice
(case choice
("Resume" (resume))
(never otherwise))))
(method :Void showSet [:FlxSprite setSprite :SceneTime time :ScenePerspective perspective :Appearance appearance :FlxCamera camera :Continuation cc]
(case appearance

View File

@@ -14,6 +14,7 @@ import uuid.Uuid;
import haxe.ds.Option;
import kiss_tools.JsonMap;
import kiss_tools.JsonableArray;
import kiss_tools.TimerWithPause;
using kiss.FuzzyMapTools;

View File

@@ -144,14 +144,15 @@
(method pause []
(unless paused
// TODO pause all delays (which will require ditching haxe.Timer!!!)
(TimerWithPause.pause)
(set paused true)
(director.pause)))
(method resume []
(when paused
(set paused false)
(director.resume)))
(director.resume)
(TimerWithPause.resume)))
(method resolvePosition [:Dynamic position]
(typeCase [position]
@@ -194,10 +195,13 @@
(shortcutHandler.start)
(process cc)
})
(set shortcutHandler.onBadKey
->[_ _]
(shortcutHandler.start))
(shortcutHandler.registerItem "{escape} Pause the movie"
->cc (director.showPauseMenu cc))
// TODO (#when debug)
(#when debug
(shortcutHandler.registerItem "[d]efine [l]ight source"
->cc
(director.defineLightSource
@@ -216,12 +220,10 @@
(shortcutHandler.registerItem "skip to [l]abel"
->cc
(let [runners (labelRunners)]
(localVar &mut buttonY 0)
(localVar buttonsPerColumn 25)
(director.chooseString
"Skip to scene?"
(sort (collect (runners.keys)))
->label ((dictGet runners label)))))
->label ((dictGet runners label))))))
(shortcutHandler.start))
@@ -266,19 +268,19 @@
(never otherwise))]
(case delayHandling
(Auto
(Timer.delay cc (* 1000 sec)))
(TimerWithPause.delay cc sec))
(AutoWithSkip
(let [autoDelay
(Timer.delay
(TimerWithPause.delay
->{
(director.stopWaitForInput cc)
(cc)
}
(* 1000 sec))]
sec)]
(director.startWaitForInput
->{
(director.stopWaitForInput cc)
(autoDelay.stop)
(TimerWithPause.stop autoDelay)
(cc)
})))
(Manual

View File

@@ -0,0 +1,15 @@
package kiss_tools;
import kiss.Prelude;
import kiss.List;
import haxe.Timer;
typedef WrappedTimer = {
startTime:Float,
duration:Float,
t:Timer,
f:Void->Void
}
@:build(kiss.Kiss.build())
class TimerWithPause {}

View File

@@ -0,0 +1,31 @@
(var &mut :Array<WrappedTimer> timers [])
(function :WrappedTimer delay [:Void->Void f :Float sec]
(let [wrapped
(object
startTime (Timer.stamp)
duration sec
t null
f f)
wrappedF
->{(timers.remove wrapped)(f)}]
(set wrapped.t (Timer.delay wrappedF (Std.int (* sec 1000))))
(timers.push wrapped)
wrapped))
(function stop [:WrappedTimer timer]
(timer.t.stop)
(timers.remove timer))
(function pause []
(let [now (Timer.stamp)]
(doFor timer timers
(let [elapsed (- now timer.startTime)]
(-= timer.duration elapsed)
(timer.t.stop)))))
(function resume []
(let [oldTimers timers]
(set timers [])
(doFor timer oldTimers
(delay timer.f timer.duration))))