handle sound captions

This commit is contained in:
2023-06-07 11:24:06 -06:00
parent 72e42790ae
commit 9d695a3c6c
5 changed files with 32 additions and 7 deletions

View File

@@ -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

View File

@@ -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<Int,FlxSprite> 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<FlxSound> currentVoiceTracks [])

View File

@@ -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))

View File

@@ -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)}

View File

@@ -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");
}
}