hollywoo reader macros passing cc automatically
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
(loadFrom "hollywoo" "src/hollywoo/HollywooDSL.kiss")
|
(loadFrom "hollywoo" "src/hollywoo/HollywooDSL.kiss")
|
||||||
(loadFrom "hollywoo-flixel" "src/hollywoo_flixel/AssetMacros.kiss")
|
(loadFrom "hollywoo-flixel" "src/hollywoo_flixel/AssetMacros.kiss")
|
||||||
|
|
||||||
|
(defMacroVar subclass true)
|
||||||
|
(loadFrom "hollywoo" "src/hollywoo/Movie.kiss")
|
||||||
|
|
||||||
(method newFlxScene [name set time perspective]
|
(method newFlxScene [name set time perspective]
|
||||||
(let [setSprite (new FlxSprite 0 0)]
|
(let [setSprite (new FlxSprite 0 0)]
|
||||||
(setSprite.loadGraphic (dictGet sets set))
|
(setSprite.loadGraphic (dictGet sets set))
|
||||||
|
@@ -1,65 +1,64 @@
|
|||||||
// Mostly immutable, reusable resources:
|
// This file is designed to be loaded again by subclasses, with macroVar "subclass" set
|
||||||
(prop :Map<String,Set> sets (new Map))
|
(#unless subclass
|
||||||
(prop :Map<String,Actor> actors (new Map))
|
|
||||||
(prop :Map<String,Sound> sounds (new Map))
|
|
||||||
(prop :Map<String,Song> songs (new Map))
|
|
||||||
(prop :Map<String,Prop> props (new Map))
|
|
||||||
|
|
||||||
(prop &mut :DelayHandling delayHandling AutoWithSkip)
|
// Mostly immutable, reusable resources:
|
||||||
|
(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))
|
||||||
|
(prop :Map<String,Prop> props (new Map))
|
||||||
|
|
||||||
// TODO for some reason this won't work when declared in Kiss syntax:
|
(prop &mut :DelayHandling delayHandling AutoWithSkip)
|
||||||
// Mutable representation of frames in time:
|
|
||||||
// var scenes:Map<String, Scene<Set, StagePosition, StageFacing, ScreenPosition, Actor>> = [];
|
|
||||||
(prop :Map<String,Bool> shownScenes (new Map))
|
|
||||||
(prop :Map<String,Bool> shownCharacters (new Map))
|
|
||||||
|
|
||||||
// This is set and unset by doPreload defined in HollywooDSL.kiss
|
// TODO for some reason this won't work when declared in Kiss syntax:
|
||||||
(prop &mut isLoading false)
|
// Mutable representation of frames in time:
|
||||||
|
// var scenes:Map<String, Scene<Set, StagePosition, StageFacing, ScreenPosition, Actor>> = [];
|
||||||
|
(prop :Map<String,Bool> shownScenes (new Map))
|
||||||
|
(prop :Map<String,Bool> shownCharacters (new Map))
|
||||||
|
|
||||||
(function :Appearance appearanceFlag [:Map<String,Bool> map :String key]
|
// This is set and unset by doPreload defined in HollywooDSL.kiss
|
||||||
(if (dictGet map key)
|
(prop &mut isLoading false)
|
||||||
ReAppearance
|
|
||||||
{
|
|
||||||
(dictSet map key true)
|
|
||||||
FirstAppearance
|
|
||||||
}))
|
|
||||||
|
|
||||||
(prop &mut :String sceneKey "")
|
(function :Appearance appearanceFlag [:Map<String,Bool> map :String key]
|
||||||
(method _currentScene [] (dictGet scenes sceneKey))
|
(if (dictGet map key)
|
||||||
|
ReAppearance
|
||||||
|
{
|
||||||
|
(dictSet map key true)
|
||||||
|
FirstAppearance
|
||||||
|
}))
|
||||||
|
|
||||||
(defNew
|
(prop &mut :String sceneKey "")
|
||||||
[
|
(method _currentScene [] (dictGet scenes sceneKey))
|
||||||
// "View" in the Model-View-Controller architecture:
|
|
||||||
&prop :Director<Set,StagePosition,StageFacing,ScreenPosition,Actor,Sound,Song,Prop> director
|
|
||||||
]
|
|
||||||
|
|
||||||
(set director.movie this)
|
(defNew
|
||||||
|
[
|
||||||
|
// "View" in the Model-View-Controller architecture:
|
||||||
|
&prop :Director<Set,StagePosition,StageFacing,ScreenPosition,Actor,Sound,Song,Prop> director
|
||||||
|
]
|
||||||
|
|
||||||
(super))
|
(set director.movie this)
|
||||||
|
|
||||||
|
(super)))
|
||||||
|
|
||||||
// Some real magic happens here. This macro defines a method, AND a reader macro
|
// Some real magic happens here. This macro defines a method, AND a reader macro
|
||||||
// for calling it with cc passed automatically if cc is an argument.
|
// for calling it with cc passed automatically if cc is an argument.
|
||||||
|
|
||||||
(defMacro hollywooMethod [nameAndType argList &body body]
|
(defMacro hollywooMethod [nameAndType argList &builder b &body body]
|
||||||
(let [&mut ccIndex -1
|
(let [args (expList argList)
|
||||||
args (expList argList)
|
|
||||||
numArgs args.length
|
numArgs args.length
|
||||||
methodName (symbolNameValue nameAndType true)
|
methodName (symbolNameValue nameAndType true)
|
||||||
readerMacroStart "$(.toUpperCase methodName) "]
|
readerMacroStart "$(.toUpperCase methodName) "]
|
||||||
(doFor [idx arg] (enumerate args)
|
|
||||||
(exprCase arg
|
|
||||||
(:Continuation cc
|
|
||||||
(set ccIndex idx))
|
|
||||||
(_)))
|
|
||||||
`{
|
`{
|
||||||
(defReaderMacro ,readerMacroStart [stream]
|
(defReaderMacro ,readerMacroStart [stream &builder b]
|
||||||
(ReaderExp.CallExp
|
(b.callSymbol
|
||||||
(ReaderExp.Symbol methodName)
|
,methodName
|
||||||
(for i (range numArgs)
|
,(for arg args
|
||||||
(if (= i ccIndex)
|
(exprCase arg
|
||||||
(ReaderExp.Symbol "cc")
|
((exprTyped Continuation cc)
|
||||||
(read)))))
|
(b.callSymbol "b.symbol" [(b.str "cc")]))
|
||||||
(method ,nameAndType ,argList ,@body)
|
(_
|
||||||
|
(b.callSymbol "read" [(b.symbol "stream")]))))))
|
||||||
|
(#unless subclass (method ,nameAndType ,argList ,@body))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(hollywooMethod :Void delay [sec :Continuation cc]
|
(hollywooMethod :Void delay [sec :Continuation cc]
|
||||||
@@ -87,11 +86,11 @@
|
|||||||
(cc)
|
(cc)
|
||||||
}))))
|
}))))
|
||||||
|
|
||||||
(method newSet [name :Set set]
|
(hollywooMethod newSet [name :Set set]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet sets name set))
|
(dictSet sets name set))
|
||||||
|
|
||||||
(method newSceneFromSet [name :String setKey :SceneTime time :ScenePerspective perspective]
|
(hollywooMethod newSceneFromSet [name :String setKey :SceneTime time :ScenePerspective perspective]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet scenes name (objectWith
|
(dictSet scenes name (objectWith
|
||||||
[
|
[
|
||||||
@@ -105,52 +104,52 @@
|
|||||||
time
|
time
|
||||||
perspective)))
|
perspective)))
|
||||||
|
|
||||||
(method newScene [name :Scene<Set,StagePosition,StageFacing,ScreenPosition,Actor,Prop> scene]
|
(hollywooMethod newScene [name :Scene<Set,StagePosition,StageFacing,ScreenPosition,Actor,Prop> scene]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet scenes name scene))
|
(dictSet scenes name scene))
|
||||||
|
|
||||||
(method setScene [name :Continuation cc]
|
(hollywooMethod setScene [name :Continuation cc]
|
||||||
(set sceneKey name)
|
(set sceneKey name)
|
||||||
(director.showScene
|
(director.showScene
|
||||||
(dictGet scenes name)
|
(dictGet scenes name)
|
||||||
(appearanceFlag shownScenes name)
|
(appearanceFlag shownScenes name)
|
||||||
cc))
|
cc))
|
||||||
|
|
||||||
(method newSound [name :Sound s]
|
(hollywooMethod newSound [name :Sound s]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet sounds name s))
|
(dictSet sounds name s))
|
||||||
|
|
||||||
(method playSound [name :Continuation cc &opt :Float volumeMod :Bool waitForEnd]
|
(hollywooMethod playSound [name :Continuation cc &opt :Float volumeMod :Bool waitForEnd]
|
||||||
(set volumeMod (or volumeMod 1))
|
(set volumeMod (or volumeMod 1))
|
||||||
(assert (<= 0 volumeMod 1))
|
(assert (<= 0 volumeMod 1))
|
||||||
(director.playSound (dictGet sounds name) volumeMod ?waitForEnd cc))
|
(director.playSound (dictGet sounds name) volumeMod ?waitForEnd cc))
|
||||||
|
|
||||||
(method awaitPlaySound [name :Continuation cc &opt :Float volumeMod]
|
(hollywooMethod awaitPlaySound [name :Continuation cc &opt :Float volumeMod]
|
||||||
(playSound name cc volumeMod true))
|
(playSound name cc volumeMod true))
|
||||||
|
|
||||||
(method newSong [name :Song song]
|
(hollywooMethod newSong [name :Song song]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet songs name song))
|
(dictSet songs name song))
|
||||||
|
|
||||||
(method playSong [name :Continuation cc &opt :Float volumeMod :Bool loop :Bool waitForEnd]
|
(hollywooMethod playSong [name :Continuation cc &opt :Float volumeMod :Bool loop :Bool waitForEnd]
|
||||||
(set volumeMod (or volumeMod 1))
|
(set volumeMod (or volumeMod 1))
|
||||||
(assert (<= 0 volumeMod 1))
|
(assert (<= 0 volumeMod 1))
|
||||||
(director.playSong (dictGet songs name) volumeMod ?loop ?waitForEnd cc))
|
(director.playSong (dictGet songs name) volumeMod ?loop ?waitForEnd cc))
|
||||||
|
|
||||||
(method awaitPlaySong [name :Continuation cc &opt :Float volumeMod]
|
(hollywooMethod awaitPlaySong [name :Continuation cc &opt :Float volumeMod]
|
||||||
(playSong name cc volumeMod false true))
|
(playSong name cc volumeMod false true))
|
||||||
|
|
||||||
(method loopSong [name :Continuation cc &opt :Float volumeMod]
|
(hollywooMethod loopSong [name :Continuation cc &opt :Float volumeMod]
|
||||||
(playSong name cc volumeMod true false))
|
(playSong name cc volumeMod true false))
|
||||||
|
|
||||||
(method stopSong []
|
(hollywooMethod stopSong []
|
||||||
(director.stopSong))
|
(director.stopSong))
|
||||||
|
|
||||||
(method newActor [name :Actor actor]
|
(hollywooMethod newActor [name :Actor actor]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet actors name actor))
|
(dictSet actors name actor))
|
||||||
|
|
||||||
(method addCharacter [actorName :StagePosition position :StageFacing facing :Continuation cc]
|
(hollywooMethod addCharacter [actorName :StagePosition position :StageFacing facing :Continuation cc]
|
||||||
(let [character (object stagePosition position stageFacing facing actor (dictGet actors actorName))]
|
(let [character (object stagePosition position stageFacing facing actor (dictGet actors actorName))]
|
||||||
(dictSet .characters (_currentScene) actorName character)
|
(dictSet .characters (_currentScene) actorName character)
|
||||||
(director.showCharacter
|
(director.showCharacter
|
||||||
@@ -159,7 +158,7 @@
|
|||||||
cc)
|
cc)
|
||||||
))
|
))
|
||||||
|
|
||||||
(method removeCharacter [actorName :Continuation cc]
|
(hollywooMethod removeCharacter [actorName :Continuation cc]
|
||||||
(let [c (dictGet .characters (_currentScene) actorName)]
|
(let [c (dictGet .characters (_currentScene) actorName)]
|
||||||
(.remove .characters (_currentScene) actorName)
|
(.remove .characters (_currentScene) actorName)
|
||||||
(director.hideCharacter c cc)))
|
(director.hideCharacter c cc)))
|
||||||
@@ -167,28 +166,28 @@
|
|||||||
// TODO moveCharacter remove them, add them to another scene
|
// TODO moveCharacter remove them, add them to another scene
|
||||||
// TODO moveCharacterAndFollow remove them, add them to another scene, set that the scene
|
// TODO moveCharacterAndFollow remove them, add them to another scene, set that the scene
|
||||||
|
|
||||||
(method newProp [name :Prop prop]
|
(hollywooMethod newProp [name :Prop prop]
|
||||||
(assert isLoading)
|
(assert isLoading)
|
||||||
(dictSet props name prop))
|
(dictSet props name prop))
|
||||||
|
|
||||||
(method addPropToScreen [name :ScreenPosition position :Continuation cc]
|
(hollywooMethod addPropToScreen [name :ScreenPosition position :Continuation cc]
|
||||||
(dictSet .propsOnScreen (_currentScene) name (dictGet props name))
|
(dictSet .propsOnScreen (_currentScene) name (dictGet props name))
|
||||||
(director.showPropOnScreen (dictGet props name) position cc))
|
(director.showPropOnScreen (dictGet props name) position cc))
|
||||||
|
|
||||||
(method removeProp [name :Continuation cc]
|
(hollywooMethod removeProp [name :Continuation cc]
|
||||||
(director.hideProp (dictGet props name) cc))
|
(director.hideProp (dictGet props name) cc))
|
||||||
|
|
||||||
// TODO removeProp
|
// TODO removeProp
|
||||||
|
|
||||||
// Dialogue:
|
// Dialogue:
|
||||||
|
|
||||||
(method superText [text cc]
|
(hollywooMethod superText [text cc]
|
||||||
(director.showDialog "" Super "" text cc))
|
(director.showDialog "" Super "" text cc))
|
||||||
|
|
||||||
(method normalSpeech [actorName wryly text cc]
|
(hollywooMethod normalSpeech [actorName wryly text cc]
|
||||||
(director.showDialog actorName (OnScreen (dictGet .characters (_currentScene) actorName)) wryly text cc))
|
(director.showDialog actorName (OnScreen (dictGet .characters (_currentScene) actorName)) wryly text cc))
|
||||||
|
|
||||||
(method onPhoneSpeech [actorName wryly text cc]
|
(hollywooMethod onPhoneSpeech [actorName wryly text cc]
|
||||||
(director.showDialog actorName (ifLet [charOnScreen (dictGet .characters (_currentScene) actorName)]
|
(director.showDialog actorName (ifLet [charOnScreen (dictGet .characters (_currentScene) actorName)]
|
||||||
(OnScreen charOnScreen)
|
(OnScreen charOnScreen)
|
||||||
(FromPhone (dictGet actors actorName))) wryly text cc))
|
(FromPhone (dictGet actors actorName))) wryly text cc))
|
Reference in New Issue
Block a user