music for hollywoo-flixel
This commit is contained in:
@@ -13,6 +13,7 @@ import hollywoo_flixel.FlxMovie;
|
||||
import flixel.util.FlxColor;
|
||||
import flixel.text.FlxText;
|
||||
import flixel.system.FlxSound;
|
||||
import flixel.util.FlxTimer;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class FlxDirector implements Director<String, FlxStagePosition, FlxStageFacing, FlxScreenPosition, ActorFlxSprite, FlxSound> {}
|
||||
class FlxDirector implements Director<String, FlxStagePosition, FlxStageFacing, FlxScreenPosition, ActorFlxSprite, FlxSound, String> {}
|
||||
|
@@ -102,8 +102,27 @@
|
||||
(cc)
|
||||
}))
|
||||
|
||||
(method :Void playSound [:FlxSound sound :Float volumeMod :Continuation cc]
|
||||
// TODO preserve its original volume
|
||||
(set sound.volume volumeMod)
|
||||
(set sound.onComplete cc)
|
||||
(sound.play))
|
||||
(method :Void playSound [:FlxSound sound :Float volumeMod :Bool waitForEnd :Continuation cc]
|
||||
(let [originalVolume sound.volume
|
||||
restoreOriginalVolume ->(set sound.volume originalVolume)]
|
||||
(*= sound.volume volumeMod)
|
||||
(set sound.onComplete
|
||||
(if waitForEnd
|
||||
->{(restoreOriginalVolume) (cc)}
|
||||
restoreOriginalVolume)))
|
||||
(sound.play)
|
||||
(unless waitForEnd (cc)))
|
||||
|
||||
(prop &mut :FlxSound music)
|
||||
(prop MUSIC_FADE_SEC 1)
|
||||
(prop MUSIC_FADE_STEPS 10)
|
||||
(method :Void playSong [:String song :Float volumeMod :Bool loop :Bool waitForEnd :Continuation cc]
|
||||
(set music (FlxG.sound.play song 0 loop null true (if waitForEnd cc ->{})))
|
||||
(.start (new FlxTimer)
|
||||
(/ MUSIC_FADE_SEC MUSIC_FADE_STEPS)
|
||||
->:Void _ (+= music.volume (/ volumeMod MUSIC_FADE_STEPS))
|
||||
MUSIC_FADE_STEPS)
|
||||
(set music.persist true)
|
||||
(unless waitForEnd (cc)))
|
||||
|
||||
(method :Void stopSong [] (when music (music.stop)))
|
||||
|
@@ -29,4 +29,4 @@ enum FlxScreenPosition {
|
||||
/**
|
||||
* Model/controller of a Hollywoo-Flixel film, and main execution script
|
||||
*/
|
||||
class FlxMovie extends Movie<String, FlxStagePosition, FlxStageFacing, FlxScreenPosition, ActorFlxSprite, FlxSound> {}
|
||||
class FlxMovie extends Movie<String, FlxStagePosition, FlxStageFacing, FlxScreenPosition, ActorFlxSprite, FlxSound, String> {}
|
||||
|
@@ -9,10 +9,12 @@ enum Appearance {
|
||||
|
||||
typedef Continuation = Void -> Void;
|
||||
|
||||
interface Director<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound> {
|
||||
interface Director<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound, Song> {
|
||||
function showScene(scene:Scene<Set, StagePosition, StageFacing, ScreenPosition, Actor>, appearance:Appearance, cc:Continuation):Void;
|
||||
function showCharacter(character:Character<StagePosition, StageFacing, Actor>, appearance:Appearance, cc:Continuation):Void;
|
||||
function playSound(sound:Sound, volumeMod:Float, cc:Continuation):Void;
|
||||
function playSound(sound:Sound, volumeMod:Float, waitForEnd:Bool, cc:Continuation):Void;
|
||||
function playSong(song:Song, volumeMod:Float, loop:Bool, waitForEnd:Bool, cc:Continuation):Void;
|
||||
function stopSong():Void;
|
||||
function waitForInputOrDelay(delaySeconds:Float, cc:Continuation):Void;
|
||||
function showDialog(speakerName:String, type:SpeechType<StagePosition, StageFacing, Actor>, wryly:String, dialog:String, cc:Continuation):Void;
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package hollywoo;
|
||||
|
||||
import haxe.Constraints.Function;
|
||||
import kiss.AsyncEmbeddedScript;
|
||||
import kiss.Prelude;
|
||||
import hollywoo.Scene;
|
||||
@@ -9,7 +10,7 @@ import hollywoo.Director;
|
||||
* Model/controller of a Hollywoo film, and main execution script
|
||||
*/
|
||||
@:build(kiss.Kiss.build())
|
||||
class Movie<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound> extends AsyncEmbeddedScript {
|
||||
class Movie<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound, Song> extends AsyncEmbeddedScript {
|
||||
// TODO for some reason this wasn't working when declared in Movie.kiss:
|
||||
// Mutable representation of frames in time:
|
||||
var scenes:Map<String, Scene<Set, StagePosition, StageFacing, ScreenPosition, Actor>> = [];
|
||||
|
@@ -2,6 +2,7 @@
|
||||
(prop :Map<String,Set> sets (new Map))
|
||||
(prop :Map<String,Actor> actors (new Map))
|
||||
(prop :Map<String,Sound> sounds (new Map))
|
||||
(prop :Map<String,Song> songs (new Map))
|
||||
|
||||
// TODO for some reason this won't work when declared in Kiss syntax:
|
||||
// Mutable representation of frames in time:
|
||||
@@ -26,7 +27,7 @@
|
||||
(defNew
|
||||
[
|
||||
// "View" in the Model-View-Controller architecture:
|
||||
&prop :Director<Set,StagePosition,StageFacing,ScreenPosition,Actor,Sound> director
|
||||
&prop :Director<Set,StagePosition,StageFacing,ScreenPosition,Actor,Sound,Song> director
|
||||
]
|
||||
|
||||
(super))
|
||||
@@ -62,10 +63,31 @@
|
||||
(assert isLoading)
|
||||
(dictSet sounds name s))
|
||||
|
||||
(method playSound [name :Continuation cc &opt :Float volumeMod]
|
||||
(method playSound [name :Continuation cc &opt :Float volumeMod :Bool waitForEnd]
|
||||
(set volumeMod (or volumeMod 1))
|
||||
(assert (<= 0 volumeMod 1))
|
||||
(director.playSound (dictGet sounds name) volumeMod cc))
|
||||
(director.playSound (dictGet sounds name) volumeMod ?waitForEnd cc))
|
||||
|
||||
(method awaitPlaySound [name :Continuation cc &opt :Float volumeMod]
|
||||
(playSound name cc volumeMod true))
|
||||
|
||||
(method newSong [name :Song song]
|
||||
(assert isLoading)
|
||||
(dictSet songs name song))
|
||||
|
||||
(method playSong [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))
|
||||
|
||||
(method awaitPlaySong [name :Continuation cc &opt :Float volumeMod]
|
||||
(playSong name cc volumeMod false true))
|
||||
|
||||
(method loopSong [name :Continuation cc &opt :Float volumeMod]
|
||||
(playSong name cc volumeMod true false))
|
||||
|
||||
(method stopSong []
|
||||
(director.stopSong))
|
||||
|
||||
(method newActor [name :Actor actor]
|
||||
(assert isLoading)
|
||||
|
Reference in New Issue
Block a user