From fb851c44e6347bd7a7c8038836138a7eb285ff4b Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 3 Apr 2023 05:02:11 -0600 Subject: [PATCH] Make delayLengths a JsonMap --- src/hollywoo/DelayLength.hx | 7 +++++ src/hollywoo/DelayLength.kiss | 4 +++ src/hollywoo/Movie.kiss | 51 ++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 src/hollywoo/DelayLength.hx create mode 100644 src/hollywoo/DelayLength.kiss diff --git a/src/hollywoo/DelayLength.hx b/src/hollywoo/DelayLength.hx new file mode 100644 index 0000000..e826b48 --- /dev/null +++ b/src/hollywoo/DelayLength.hx @@ -0,0 +1,7 @@ +package hollywoo; + +import kiss.Prelude; +import kiss.List; + +@:build(kiss.Kiss.build()) +class DelayLength {} diff --git a/src/hollywoo/DelayLength.kiss b/src/hollywoo/DelayLength.kiss new file mode 100644 index 0000000..2a32fc6 --- /dev/null +++ b/src/hollywoo/DelayLength.kiss @@ -0,0 +1,4 @@ +(defNew [&prop :Float length]) + +(method stringify [] "$length") +(method parse [:String data] (new DelayLength (Std.parseFloat data))) \ No newline at end of file diff --git a/src/hollywoo/Movie.kiss b/src/hollywoo/Movie.kiss index 495ff33..22d770f 100644 --- a/src/hollywoo/Movie.kiss +++ b/src/hollywoo/Movie.kiss @@ -155,6 +155,7 @@ :String lightSourceJsonFile :LightSource defaultLightSource :String stagePositionsJson + :String delayLengthsJson &opt :String voiceLinesJson ] [ @@ -162,6 +163,8 @@ (new JsonMap stagePositionsJson (new StagePosition 0 0 0)) :JsonMap> lightSources (new JsonMap lightSourceJsonFile (new JsonableArray [] defaultLightSource)) + :JsonMap delayLengths + (new JsonMap delayLengthsJson (new DelayLength 0.5)) ] (set director.movie this) @@ -203,31 +206,35 @@ (#unless subclass (method ,nameAndType ,argList ,@body)) })) -(hollywooMethod :Void delay true [sec :Continuation cc] - (case delayHandling - (Auto - (Timer.delay cc (* 1000 sec))) - (AutoWithSkip - (let [autoDelay - (Timer.delay - ->{ - (director.stopWaitForInput cc) - (cc) - } - (* 1000 sec))] - (director.startWaitForInput +(hollywooMethod :Void delay true [:Dynamic length :Continuation cc] + (let [sec (typeCase [length] + ([:Float sec] sec) + ([:String key] .length (delayLengths.get key)) + (never otherwise))] + (case delayHandling + (Auto + (Timer.delay cc (* 1000 sec))) + (AutoWithSkip + (let [autoDelay + (Timer.delay + ->{ + (director.stopWaitForInput cc) + (cc) + } + (* 1000 sec))] + (director.startWaitForInput + ->{ + (director.stopWaitForInput cc) + (autoDelay.stop) + (cc) + }))) + (Manual + (director.startWaitForInput ->{ (director.stopWaitForInput cc) - (autoDelay.stop) (cc) - }))) - (Manual - (director.startWaitForInput - ->{ - (director.stopWaitForInput cc) - (cc) - })) - (otherwise (throw "Unsupported delay type $delayHandling")))) + })) + (otherwise (throw "Unsupported delay type $delayHandling"))))) (hollywooMethod newSet true [name :Set set] (assert isLoading)