From 9d695a3c6c0fae30a1acbfee95bd75309f3a9843 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 7 Jun 2023 11:24:06 -0600 Subject: [PATCH] handle sound captions --- haxe_libraries/hollywoo.hxml | 6 +++--- src/hollywoo_flixel/FlxDirector.kiss | 24 ++++++++++++++++++++++ src/hollywoo_flixel/HollywooFlixelDSL.kiss | 4 ++-- src/test/source/Test.hollywoo | 2 +- src/test/source/TestState.hx | 3 ++- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/haxe_libraries/hollywoo.hxml b/haxe_libraries/hollywoo.hxml index 8e1cc87..729fa1d 100644 --- a/haxe_libraries/hollywoo.hxml +++ b/haxe_libraries/hollywoo.hxml @@ -1,6 +1,6 @@ -# @install: lix --silent download "gh://github.com/kiss-lang/hollywoo#58b6a8b1467b316d807ade6167d4f9c185dda7e6" into hollywoo/0.0.0/github/58b6a8b1467b316d807ade6167d4f9c185dda7e6 -# @run: haxelib run-dir hollywoo "${HAXE_LIBCACHE}/hollywoo/0.0.0/github/58b6a8b1467b316d807ade6167d4f9c185dda7e6" +# @install: lix --silent download "gh://github.com/kiss-lang/hollywoo#b50ef1ef706c0dc126f078a8706195123c1d745a" into hollywoo/0.0.0/github/b50ef1ef706c0dc126f078a8706195123c1d745a +# @run: haxelib run-dir hollywoo "${HAXE_LIBCACHE}/hollywoo/0.0.0/github/b50ef1ef706c0dc126f078a8706195123c1d745a" -lib kiss -lib kiss-tools --cp ${HAXE_LIBCACHE}/hollywoo/0.0.0/github/58b6a8b1467b316d807ade6167d4f9c185dda7e6/src/ +-cp ${HAXE_LIBCACHE}/hollywoo/0.0.0/github/b50ef1ef706c0dc126f078a8706195123c1d745a/src/ -D hollywoo=0.0.0 \ No newline at end of file diff --git a/src/hollywoo_flixel/FlxDirector.kiss b/src/hollywoo_flixel/FlxDirector.kiss index 771290e..61c0afa 100644 --- a/src/hollywoo_flixel/FlxDirector.kiss +++ b/src/hollywoo_flixel/FlxDirector.kiss @@ -476,6 +476,30 @@ (currentSounds.remove sound) (sound.stop)) +(var CAPTION_Y 50) +// This group is just for tracking y gaps where a new caption could appear +(prop &mut :FlxGroup captions null) +(prop :Map captionIds (new Map)) +(method :Void showCaption [:String description :Int id] + (unless captions (set captions (new FlxGroup))) + (let [firstNull (captions.getFirstNull) + row (case firstNull (-1 0) (otherwise firstNull)) + plate (SpriteTools.textPlate "[${description}]" DIALOG_SIZE SUPER_MARGIN)] + (plate.screenCenter) + (set plate.y (+ CAPTION_Y (* plate.height row))) + (captions.add plate) + (dictSet captionIds id plate) + (FlxG.state.add plate))) + +(method :Void hideCaption [:Int id] + (let [plate (dictGet captionIds id)] + (captions.remove plate) + (FlxG.state.remove plate) + (captionIds.remove id))) + +(method :Float getSoundLength [:FlxSound sound] + sound.length) + (savedVar :Float voiceVolume 1.0) (prop :Array currentVoiceTracks []) diff --git a/src/hollywoo_flixel/HollywooFlixelDSL.kiss b/src/hollywoo_flixel/HollywooFlixelDSL.kiss index 3a27973..4426b94 100644 --- a/src/hollywoo_flixel/HollywooFlixelDSL.kiss +++ b/src/hollywoo_flixel/HollywooFlixelDSL.kiss @@ -62,13 +62,13 @@ (setSprite.makeGraphic FlxG.width FlxG.height color true) // Load uniquely so we can draw on sets for specific scenes (newSet name setSprite))) -(method newFlxSound [name path &opt :Float volume] +(method newFlxSound [name path description &opt :Float volume] (set volume (or volume 1)) (assert (<= 0 volume 1)) (let [s (FlxG.sound.load path)] (set s.volume volume) (set s.persist true) - (newSound name s))) + (newSound name s description))) (method newFlxSong [name path] (newSong name path)) diff --git a/src/test/source/Test.hollywoo b/src/test/source/Test.hollywoo index c3b3dd6..2318793 100644 --- a/src/test/source/Test.hollywoo +++ b/src/test/source/Test.hollywoo @@ -4,7 +4,7 @@ // Don't let that stop Hollywoo: {(prop &mut soundPlayed false)(cc)} (preload - (newFlxSound "pageFlip" (assetPath "assets" "pageTurn.wav"))) + (newFlxSound "pageFlip" (assetPath "assets" "pageTurn.wav") "page turning")) {(delay 1 ->:Void (assert soundPlayed)) (cc)} AWAITPLAYSOUND "pageFlip" {(set soundPlayed true) (cc)} diff --git a/src/test/source/TestState.hx b/src/test/source/TestState.hx index 2fc2722..053872f 100644 --- a/src/test/source/TestState.hx +++ b/src/test/source/TestState.hx @@ -3,6 +3,7 @@ package; import kiss.Prelude; import kiss.List; import hollywoo.StagePosition; +import hollywoo.HFloat; import hollywoo_flixel.FlxDirector; import hollywoo_flixel.FlxMovie; import hollywoo_flixel.MovieFlxState; @@ -18,7 +19,7 @@ import flixel.FlxCamera; @:build(kiss.AsyncEmbeddedScript.build("hollywoo-flixel", "src/hollywoo_flixel/HollywooFlixelDSL.kiss", "Test.hollywoo")) class Test extends FlxMovie { public function new(director:FlxDirector) { - super(director, "lightSources.json", "positions.json", "delayLengths.json", "voiceLineMatches.json"); + super(director, "lightSources.json", "positions.json", "delayLengths.json", "voiceLineMatches.json", "propScales.json"); } }