From b50ef1ef706c0dc126f078a8706195123c1d745a Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 7 Jun 2023 11:23:24 -0600 Subject: [PATCH] Togglable sound captions --- src/hollywoo/Director.hx | 4 ++++ src/hollywoo/Movie.kiss | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/hollywoo/Director.hx b/src/hollywoo/Director.hx index 9cd9ccc..4f395fc 100644 --- a/src/hollywoo/Director.hx +++ b/src/hollywoo/Director.hx @@ -59,8 +59,12 @@ interface Director, Actor, Sound, Song, Prop, VoiceTrack, Cam function hideCharacter(character:Character, camera:Camera, cc:Continuation):Void; function playSound(sound:Sound, volumeMod:Float, waitForEnd:Bool, cc:Continuation):Void; + function getSoundLength(sound:Sound):Float; function stopSound(sound:Sound):Void; + function showCaption(description:String, id:Int):Void; + function hideCaption(id:Int):Void; + function playSong(song:Song, volumeMod:Float, loop:Bool, waitForEnd:Bool, cc:Continuation):Void; function stopSong():Void; diff --git a/src/hollywoo/Movie.kiss b/src/hollywoo/Movie.kiss index dbfd1cc..5b51a70 100644 --- a/src/hollywoo/Movie.kiss +++ b/src/hollywoo/Movie.kiss @@ -6,16 +6,22 @@ // This file is designed to be loaded again by subclasses, with macroVar "subclass" set (#unless subclass + // Settings + (savedVar :Bool showCaptions false) + (var MAX_CAPTION_DURATION 3) + (prop &mut :Int captionId 0) // Mostly immutable, reusable resources: (prop :FuzzyMap sets (new FuzzyMap)) (prop :FuzzyMap actors (new FuzzyMap)) (prop :FuzzyMap sounds (new FuzzyMap)) + (prop :FuzzyMap soundDescriptions (new FuzzyMap)) (prop :FuzzyMap songs (new FuzzyMap)) (prop :FuzzyMap props (new FuzzyMap)) (prop :Map voiceTracks (new Map)) (prop :Map> customDialogTypeHandlers (new Map)) (prop :FuzzyMap> voiceLines (new FuzzyMap>)) + // Used to give unique, persistent IDs to voice tracks (prop :Map voiceTracksPerActor (new Map)) @@ -447,14 +453,25 @@ cc))))) -(hollywooMethod newSound true [name :Sound s] +(hollywooMethod newSound true [name :Sound s :String description] (assert isLoading) - (dictSet sounds name s)) + (dictSet sounds name s) + (dictSet soundDescriptions name description)) (hollywooMethod playSound true [name :Continuation cc &opt :Float volumeMod :Bool waitForEnd] (set volumeMod (or volumeMod 1)) (assert (<= 0 volumeMod 1)) - (director.playSound (dictGet sounds name) volumeMod ?waitForEnd cc)) + (localVar &mut :Null id null) + (when showCaptions + (whenLet [desc (dictGet soundDescriptions name)] + (set id captionId++) + (director.showCaption desc id))) + (let [sound (dictGet sounds name)] + (when (and showCaptions id) + (delay (min MAX_CAPTION_DURATION (director.getSoundLength sound)) + (makeCC + (director.hideCaption id)))) + (director.playSound sound volumeMod ?waitForEnd cc))) (hollywooMethod awaitPlaySound true [name :Continuation cc &opt :Float volumeMod] (playSound name cc volumeMod true))