From 9a96fbf429d8c957a7c0dc4fa8d27308427e1a77 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 31 Aug 2023 18:49:39 -0600 Subject: [PATCH] onSkipEnd, start sound loops and current music --- haxe_libraries/kiss-tools.hxml | 4 +- haxe_libraries/kiss.hxml | 6 +-- src/hollywoo/HollywooDSL.kiss | 1 + src/hollywoo/Movie.kiss | 99 ++++++++++++++++++++-------------- 4 files changed, 65 insertions(+), 45 deletions(-) diff --git a/haxe_libraries/kiss-tools.hxml b/haxe_libraries/kiss-tools.hxml index 85b696d..a0d4dff 100644 --- a/haxe_libraries/kiss-tools.hxml +++ b/haxe_libraries/kiss-tools.hxml @@ -1,4 +1,4 @@ -# @install: lix --silent download "gh://github.com/kiss-lang/kiss-tools#483e858ab91e148f030a2e2fcfedee29f3f4fc76" into kiss-tools/0.0.0/github/483e858ab91e148f030a2e2fcfedee29f3f4fc76 +# @install: lix --silent download "gh://github.com/kiss-lang/kiss-tools#aa2b792118f223d75fb0ce926826ad2b00fd07e0" into kiss-tools/0.0.0/github/aa2b792118f223d75fb0ce926826ad2b00fd07e0 -lib kiss --cp ${HAXE_LIBCACHE}/kiss-tools/0.0.0/github/483e858ab91e148f030a2e2fcfedee29f3f4fc76/src/ +-cp ${HAXE_LIBCACHE}/kiss-tools/0.0.0/github/aa2b792118f223d75fb0ce926826ad2b00fd07e0/src/ -D kiss-tools=0.0.0 \ No newline at end of file diff --git a/haxe_libraries/kiss.hxml b/haxe_libraries/kiss.hxml index 95476c5..580186a 100644 --- a/haxe_libraries/kiss.hxml +++ b/haxe_libraries/kiss.hxml @@ -1,12 +1,12 @@ -# @install: lix --silent download "gh://github.com/kiss-lang/kiss#8843ac539a9468e59b432532025ac9a8773db5bf" into kiss/0.0.1/github/8843ac539a9468e59b432532025ac9a8773db5bf -# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/8843ac539a9468e59b432532025ac9a8773db5bf" +# @install: lix --silent download "gh://github.com/kiss-lang/kiss#01801cdf5008f535ca1f871320d69b217fb95477" into kiss/0.0.1/github/01801cdf5008f535ca1f871320d69b217fb95477 +# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/01801cdf5008f535ca1f871320d69b217fb95477" -lib haxe-strings -lib hscript -lib tink_json -lib tink_macro -lib tink_syntaxhub -lib uuid --cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/8843ac539a9468e59b432532025ac9a8773db5bf/src +-cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/01801cdf5008f535ca1f871320d69b217fb95477/src -D kiss=0.0.1 -w -WUnusedPattern --macro kiss.KissFrontend.use() \ No newline at end of file diff --git a/src/hollywoo/HollywooDSL.kiss b/src/hollywoo/HollywooDSL.kiss index 112b9c7..1a27889 100644 --- a/src/hollywoo/HollywooDSL.kiss +++ b/src/hollywoo/HollywooDSL.kiss @@ -105,6 +105,7 @@ (method doCleanup [] (director.cleanup) (set lastInstructionPointer -2) + (set instructions null) (collectedBlocks cleanup) (stagePositions.m.clear) (lightSources.m.clear) diff --git a/src/hollywoo/Movie.kiss b/src/hollywoo/Movie.kiss index 8450577..38a004f 100644 --- a/src/hollywoo/Movie.kiss +++ b/src/hollywoo/Movie.kiss @@ -16,6 +16,9 @@ (prop :Array> dialogHistory []) (var MAX_DIALOG_HISTORY 50) + (prop &mut :String currentSong "") + (prop &mut :Float currentSongVolumeMod 0) + (prop &mut :Bool currentSongLooping false) // Mostly immutable, reusable resources: (prop :FuzzyMap sets (new FuzzyMap)) @@ -98,11 +101,11 @@ (prop &mut :FuzzyMap intercutMap) (prop &mut :Map altIdx (new Map)) - (method :Void processIntercut [actorName :Continuation cc] + (method :Void processIntercut [:Bool skipping :String actorName :Continuation cc] (when intercutMap (whenLet [sceneForActor (try (dictGet intercutMap actorName) (catch [e] null))] (unless (= sceneForActor sceneKey) - (setScene sceneForActor cc) + (setScene skipping sceneForActor cc) (return)))) (cc)) @@ -123,7 +126,7 @@ (when skipping (cc) (return)) - (processIntercut actorName + (processIntercut skipping actorName (makeCC (let [isSilentType ?(whenLet [(Custom type _ _) dialogType] @@ -510,8 +513,15 @@ :Map sceneMusicVolume (new Map) &mut :String playingSceneMusic null ] - + (super) (set director.movie this) + (set onSkipEnd + ->:Void { + (doFor play loopingSoundPlays + (play)) + (when currentSong + (playSong false currentSong ->:Void {} currentSongVolumeMod currentSongLooping false)) + }) (let [shortcutHandler (director.shortcutHandler) cc ->(resume)] @@ -595,9 +605,7 @@ ->label { (resume) ((dictGet runners label)) - }))))) - - (super)) + })))))) @:keep (method :Void _strobe [:Bool skipping :Bool prop :String actorOrPropKey :Float strobeSec :Int times &opt :Continuation cc] @@ -731,19 +739,19 @@ (dictSet sceneMusicVolume scene volumeMod) (when cc (cc))) -(hollywooMethod setCurrentSceneSong [:String songKey :Continuation cc &opt :Float volumeMod] +(hollywooMethod setCurrentSceneSong [:Bool skipping :String songKey :Continuation cc &opt :Float volumeMod] (dictSet sceneMusic sceneKey songKey) (dictSet sceneMusicVolume sceneKey volumeMod) (cond ((= playingSceneMusic songKey) - (changeSongVolume volumeMod cc)) + (changeSongVolume skipping volumeMod cc)) (true (set playingSceneMusic songKey) - (stopSong (makeCC null)) - (loopSong songKey (makeCC null) volumeMod) + (stopSong skipping (makeCC null)) + (loopSong skipping songKey (makeCC null) volumeMod) (cc)))) -(hollywooMethod setScene [name :Continuation cc] +(hollywooMethod setScene [:Bool skipping :String name :Continuation cc] (_hideCurrentScene (makeCC (let [name (FuzzyMapTools.bestMatch scenes name)] @@ -752,11 +760,11 @@ // Keep the song going if it's the same as current. Otherwise, take over! (unless (= playingSceneMusic songKey) (set playingSceneMusic songKey) - (stopSong (makeCC null)) - (loopSong songKey (makeCC null) (dictGet sceneMusicVolume name))) + (stopSong skipping (makeCC null)) + (loopSong skipping songKey (makeCC null) (dictGet sceneMusicVolume name))) (when playingSceneMusic (set playingSceneMusic null) - (stopSong (makeCC null)))) + (stopSong skipping (makeCC null)))) (unless (positionsInScene.exists sceneKey) (dictSet positionsInScene sceneKey [])) (_showScene @@ -765,7 +773,7 @@ .camera (dictGet scenes name) cc))))) -(hollywooMethod playSound [:Bool skipping name :Continuation cc &opt :Float volumeMod :Bool waitForEnd] +(hollywooMethod playSound [:Bool skipping :String name :Continuation cc &opt :Float volumeMod :Bool waitForEnd] (when skipping (cc) (return)) @@ -787,18 +795,19 @@ (unless waitForEnd (cc))) -(hollywooMethod awaitPlaySound [:Bool skipping name :Continuation cc &opt :Float volumeMod] +(hollywooMethod awaitPlaySound [:Bool skipping :String name :Continuation cc &opt :Float volumeMod] + (director.startWaitForInput cc) (playSound skipping name cc volumeMod true)) -(hollywooMethod stopSound [:Bool skipping name :Continuation cc] +(hollywooMethod stopSound [:Bool skipping :String name :Continuation cc] (let [name (FuzzyMapTools.bestMatch sounds name)] (loopingSoundPlays.remove name) (unless skipping (director.stopSound (dictGet sounds name)))) (cc)) -(hollywooMethod loopSound [:Bool skipping name :Continuation cc &opt :Float volumeMod] +(hollywooMethod loopSound [:Bool skipping :String name :Continuation cc &opt :Float volumeMod] // Even when skipping, create a lambda that plays an iteration of the sound, // so if skipping ends and the sound is still supposed to be looping, // we can start it! @@ -806,7 +815,7 @@ (withFunctions [ (:Void playAgain [] - (playSound skipping name + (playSound false name (makeCC (when (loopingSoundPlays.exists name) (playAgain))) @@ -818,27 +827,37 @@ (playAgain)))) (cc)) -// This is never skipped because the music might be expected to continue on to the place -// we skip to: -(hollywooMethod playSong [name :Continuation cc &opt :Float volumeMod :Bool loop :Bool waitForEnd] +(hollywooMethod playSong [:Bool skipping :String name :Continuation cc &opt :Float volumeMod :Bool loop :Bool waitForEnd] (set volumeMod (or volumeMod 1)) (assert (<= 0 volumeMod 1)) - (director.playSong (dictGet songs name) volumeMod ?loop ?waitForEnd cc)) - -(hollywooMethod changeSongVolume [:Float volumeMod :Continuation cc] - (director.changeSongVolume volumeMod cc)) - -(hollywooMethod awaitPlaySong [:Bool skipping name :Continuation cc &opt :Float volumeMod] + (set currentSong (FuzzyMapTools.bestMatch songs name)) + (set currentSongVolumeMod volumeMod) + (set currentSongLooping ?loop) (when skipping (cc) (return)) - (playSong name cc volumeMod false true)) - -(hollywooMethod loopSong [name :Continuation cc &opt :Float volumeMod] - (playSong name cc volumeMod true false)) + (director.playSong (dictGet songs currentSong) volumeMod ?loop ?waitForEnd cc)) -(hollywooMethod stopSong [cc] - (director.stopSong) +(hollywooMethod changeSongVolume [:Bool skipping :Float volumeMod :Continuation cc] + (set currentSongVolumeMod volumeMod) + (when skipping + (cc) + (return)) + (director.changeSongVolume volumeMod cc)) + +(hollywooMethod awaitPlaySong [:Bool skipping :String name :Continuation cc &opt :Float volumeMod] + (when skipping + (cc) + (return)) + (playSong skipping name cc volumeMod false true)) + +(hollywooMethod loopSong [:Bool skipping :String name :Continuation cc &opt :Float volumeMod] + (playSong skipping name cc volumeMod true false)) + +(hollywooMethod stopSong [:Bool skipping cc] + (set currentSong "") + (unless skipping + (director.stopSong)) (cc)) (hollywooMethod autoZProcess [:StagePosition position :Continuation cc] @@ -977,7 +996,7 @@ // TODO themed superText (hollywooMethod normalSpeech [:Bool skipping actorName wryly text :Continuation cc] - (processIntercut actorName + (processIntercut skipping actorName (makeCC (showDialog skipping actorName (OnScreen (dictGet .characters (_currentScene) actorName)) wryly text cc)))) @@ -988,14 +1007,14 @@ (showDialog skipping actorName (VoiceOver (dictGet actors actorName)) wryly text cc)) (hollywooMethod onPhoneSpeech [:Bool skipping actorName wryly text :Continuation cc] - (processIntercut actorName + (processIntercut skipping actorName (makeCC (showDialog skipping actorName (ifLet [charOnScreen (try (dictGet .characters (_currentScene) actorName) (catch [e] null))] (OnScreen charOnScreen) (FromPhone (dictGet actors actorName))) wryly text cc)))) (hollywooMethod customSpeech [:Bool skipping type actorName wryly args text :Continuation cc] - (processIntercut actorName + (processIntercut skipping actorName (makeCC (showDialog skipping actorName (Custom type (dictGet .characters (_currentScene) actorName) args) wryly text cc)))) @@ -1103,10 +1122,10 @@ (when skipping (cc) (return)) - (playSong songKey (makeCC null) volumeMod) + (playSong skipping songKey (makeCC null) volumeMod) (rollCredits skipping creditsTSV (makeCC - (stopSong cc)) + (stopSong skipping cc)) (director.getSongLength (dictGet songs songKey)))) \ No newline at end of file