better, multiple-sound-allowing loopSound handling

This commit is contained in:
2023-08-27 23:15:56 -06:00
parent cbff6575ee
commit e2bb87f3d5

View File

@@ -259,8 +259,7 @@
position) position)
(otherwise (throw "Not a position or position key: $position")))) (otherwise (throw "Not a position or position key: $position"))))
(prop &mut :String loopingSoundKey null) (prop &mut :Map<String,Continuation> loopingSoundPlays (new Map))
(prop &mut :Sound loopingSound null)
(#when (or sys hxnodejs) (#when (or sys hxnodejs)
(prop :FuzzyMap<FuzzyMap<String>> assetPaths (new FuzzyMap)) (prop :FuzzyMap<FuzzyMap<String>> assetPaths (new FuzzyMap))
@@ -667,29 +666,30 @@
(hollywooMethod stopSound [:Bool skipping name :Continuation cc] (hollywooMethod stopSound [:Bool skipping name :Continuation cc]
(unless skipping (let [name (FuzzyMapTools.bestMatch sounds name)]
(when (= loopingSound (dictGet sounds name)) (loopingSoundPlays.remove name)
(set loopingSound null)) (unless skipping
(director.stopSound (dictGet sounds name))) (director.stopSound (dictGet sounds name))))
(cc)) (cc))
(hollywooMethod loopSound [:Bool skipping name :Continuation cc &opt :Float volumeMod :Bool recursive] (hollywooMethod loopSound [:Bool skipping name :Continuation cc &opt :Float volumeMod]
(when skipping // Even when skipping, create a lambda that plays an iteration of the sound,
(cc) // so if skipping ends and the sound is still supposed to be looping,
(return)) // we can start it!
(when (and loopingSound !recursive) (let [name (FuzzyMapTools.bestMatch sounds name)]
(stopLoopingSound skipping (makeCC null)) (withFunctions
(print "Warning! The sound '${loopingSoundKey}' was apparently looping already.")) [
(set loopingSoundKey name) (:Void playAgain []
(set loopingSound (dictGet sounds name)) (playSound skipping name
(playSound skipping name (makeCC (loopSound skipping name cc volumeMod true)) volumeMod true) (makeCC
(cc)) (when (loopingSoundPlays.exists name)
(playAgain)))
(hollywooMethod stopLoopingSound [:Bool skipping :Continuation cc] volumeMod
(unless skipping true))
(when loopingSound ]
(director.stopSound loopingSound)) (dictSet loopingSoundPlays name playAgain)
(set loopingSound null)) (unless skipping
(playAgain))))
(cc)) (cc))
(hollywooMethod newSong [name :Song song] (hollywooMethod newSong [name :Song song]