hollywoo methods specify their skippability

This commit is contained in:
2021-12-21 21:17:28 -07:00
parent 9d375a2257
commit a6ce4b1504

View File

@@ -67,7 +67,7 @@
// 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 &builder b &body body] (defMacro hollywooMethod [nameAndType canSkip argList &builder b &body body]
(let [args (expList argList) (let [args (expList argList)
numArgs args.length numArgs args.length
methodName (symbolNameValue nameAndType true) methodName (symbolNameValue nameAndType true)
@@ -75,23 +75,25 @@
`{ `{
(defReaderMacro ,readerMacroStart [stream &builder b] (defReaderMacro ,readerMacroStart [stream &builder b]
(let [nextLineStream (let [nextLineStream
(Stream.fromString (stream.expect "hollywoo macro line" ->(stream.takeLine)))] (Stream.fromString (stream.expect "hollywoo macro line" ->(stream.takeLine)))
(b.callSymbol methodCall
,methodName (b.callSymbol
,(for arg args ,methodName
(exprCase arg ,(for arg args
((exprTyped Continuation cc) (exprCase arg
(b.callSymbol "b.symbol" [(b.str "cc")])) ((exprTyped Continuation cc)
(_ (b.callSymbol "b.symbol" [(b.str "cc")]))
(b.callSymbol "try" [ (_
(b.callSymbol "read" [(b.symbol "nextLineStream")]) (b.callSymbol "try" [
// optional arguments may not be present: (b.callSymbol "read" [(b.symbol "nextLineStream")])
(b.callSymbol "catch" [(b.list [(b.symbol "e")]) (b.callSymbol "b.symbol" [(b.str "null")])]) // optional arguments may not be present:
]))))))) (b.callSymbol "catch" [(b.list [(b.symbol "e")]) (b.callSymbol "b.symbol" [(b.str "null")])])
])))))]
(if ,canSkip methodCall (b.callSymbol "noSkip" [methodCall]))))
(#unless subclass (method ,nameAndType ,argList ,@body)) (#unless subclass (method ,nameAndType ,argList ,@body))
})) }))
(hollywooMethod :Void delay [sec :Continuation cc] (hollywooMethod :Void delay true [sec :Continuation cc]
(case delayHandling (case delayHandling
(Auto (Auto
(Timer.delay cc (* 1000 sec))) (Timer.delay cc (* 1000 sec)))
@@ -117,11 +119,11 @@
})) }))
(otherwise (throw "Unsupported delay type $delayHandling")))) (otherwise (throw "Unsupported delay type $delayHandling"))))
(hollywooMethod newSet [name :Set set] (hollywooMethod newSet true [name :Set set]
(assert isLoading) (assert isLoading)
(dictSet sets name set)) (dictSet sets name set))
(hollywooMethod newSceneFromSet [name :String setKey :SceneTime time :ScenePerspective perspective] (hollywooMethod newSceneFromSet true [name :String setKey :SceneTime time :ScenePerspective perspective]
(assert isLoading) (assert isLoading)
(dictSet scenes name (objectWith (dictSet scenes name (objectWith
[ [
@@ -135,53 +137,53 @@
time time
perspective))) perspective)))
(hollywooMethod newScene [name :Scene<Set,StagePosition,StageFacing,ScreenPosition,Actor,Prop> scene] (hollywooMethod newScene true [name :Scene<Set,StagePosition,StageFacing,ScreenPosition,Actor,Prop> scene]
(assert isLoading) (assert isLoading)
(dictSet scenes name scene)) (dictSet scenes name scene))
(hollywooMethod setScene [name :Continuation cc] (hollywooMethod setScene false [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))
(hollywooMethod newSound [name :Sound s] (hollywooMethod newSound true [name :Sound s]
(assert isLoading) (assert isLoading)
(dictSet sounds name s)) (dictSet sounds name s))
(hollywooMethod playSound [name :Continuation cc &opt :Float volumeMod :Bool waitForEnd] (hollywooMethod playSound true [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))
(hollywooMethod awaitPlaySound [name :Continuation cc &opt :Float volumeMod] (hollywooMethod awaitPlaySound true [name :Continuation cc &opt :Float volumeMod]
(playSound name cc volumeMod true)) (playSound name cc volumeMod true))
(hollywooMethod newSong [name :Song song] (hollywooMethod newSong true [name :Song song]
(assert isLoading) (assert isLoading)
(dictSet songs name song)) (dictSet songs name song))
(hollywooMethod playSong [name :Continuation cc &opt :Float volumeMod :Bool loop :Bool waitForEnd] (hollywooMethod playSong true [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))
(hollywooMethod awaitPlaySong [name :Continuation cc &opt :Float volumeMod] (hollywooMethod awaitPlaySong true [name :Continuation cc &opt :Float volumeMod]
(playSong name cc volumeMod false true)) (playSong name cc volumeMod false true))
(hollywooMethod loopSong [name :Continuation cc &opt :Float volumeMod] (hollywooMethod loopSong true [name :Continuation cc &opt :Float volumeMod]
(playSong name cc volumeMod true false)) (playSong name cc volumeMod true false))
(hollywooMethod stopSong [cc] (hollywooMethod stopSong true [cc]
(director.stopSong) (director.stopSong)
(cc)) (cc))
(hollywooMethod newActor [name :Actor actor] (hollywooMethod newActor true [name :Actor actor]
(assert isLoading) (assert isLoading)
(dictSet actors name actor)) (dictSet actors name actor))
(hollywooMethod addCharacter [actorName :StagePosition position :StageFacing facing :Continuation cc] (hollywooMethod addCharacter false [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
@@ -189,7 +191,7 @@
(appearanceFlag shownCharacters actorName) (appearanceFlag shownCharacters actorName)
cc))) cc)))
(hollywooMethod removeCharacter [actorName :Continuation cc] (hollywooMethod removeCharacter false [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)))
@@ -197,37 +199,37 @@
// 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
(hollywooMethod newProp [name :Prop prop] (hollywooMethod newProp true [name :Prop prop]
(assert isLoading) (assert isLoading)
(dictSet props name prop)) (dictSet props name prop))
(hollywooMethod addPropToScreen [name :ScreenPosition position :Continuation cc] (hollywooMethod addPropToScreen false [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))
(hollywooMethod removeProp [name :Continuation cc] (hollywooMethod removeProp false [name :Continuation cc]
(director.hideProp (dictGet props name) cc)) (director.hideProp (dictGet props name) cc))
// Dialogue: // Dialogue:
(hollywooMethod intercut [:Map<String,String> actorNamesToSceneNames :Continuation cc] (hollywooMethod intercut false [:Map<String,String> actorNamesToSceneNames :Continuation cc]
(set intercutMap actorNamesToSceneNames) (set intercutMap actorNamesToSceneNames)
(cc)) (cc))
(hollywooMethod endIntercut [:Continuation cc] (hollywooMethod endIntercut false [:Continuation cc]
(set intercutMap null) (set intercutMap null)
(cc)) (cc))
(hollywooMethod superText [text :Continuation cc] (hollywooMethod superText true [text :Continuation cc]
(showDialog "" Super "" text cc)) (showDialog "" Super "" text cc))
(hollywooMethod normalSpeech [actorName wryly text :Continuation cc] (hollywooMethod normalSpeech true [actorName wryly text :Continuation cc]
(showDialog actorName (OnScreen (dictGet .characters (_currentScene) actorName)) wryly text cc)) (showDialog actorName (OnScreen (dictGet .characters (_currentScene) actorName)) wryly text cc))
(hollywooMethod voiceOver [actorName wryly text :Continuation cc] (hollywooMethod voiceOver true [actorName wryly text :Continuation cc]
(showDialog actorName (VoiceOver (dictGet actors actorName)) wryly text cc)) (showDialog actorName (VoiceOver (dictGet actors actorName)) wryly text cc))
(hollywooMethod onPhoneSpeech [actorName wryly text :Continuation cc] (hollywooMethod onPhoneSpeech true [actorName wryly text :Continuation cc]
(showDialog actorName (ifLet [charOnScreen (dictGet .characters (_currentScene) actorName)] (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))