Add the concept of Cameras to hollywoo

This commit is contained in:
2023-03-09 07:09:41 -07:00
parent c781702d5e
commit 6499e27731
10 changed files with 58 additions and 27 deletions

View File

@@ -16,10 +16,11 @@ import hollywoo_flixel.FlxMovie;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.text.FlxText; import flixel.text.FlxText;
import flixel.system.FlxSound; import flixel.system.FlxSound;
import flixel.FlxCamera;
import flixel.util.FlxTimer; import flixel.util.FlxTimer;
import haxe.Constraints; import haxe.Constraints;
import kiss_flixel.SpriteTools; import kiss_flixel.SpriteTools;
import haxe.ds.Option; import haxe.ds.Option;
@:build(kiss.Kiss.build()) @:build(kiss.Kiss.build())
class FlxDirector implements Director<FlxSprite, FlxScreenPosition, ActorFlxSprite, FlxSound, String, FlxSprite, FlxSound> {} class FlxDirector implements Director<FlxSprite, FlxScreenPosition, ActorFlxSprite, FlxSound, String, FlxSprite, FlxSound, FlxCamera> {}

View File

@@ -1,6 +1,6 @@
(prop :FlxActionDigital continueAction) (prop :FlxActionDigital continueAction)
(prop actionManager (new FlxActionManager)) (prop actionManager (new FlxActionManager))
(prop &mut :Movie<FlxSprite,FlxScreenPosition,ActorFlxSprite,FlxSound,String,FlxSprite,FlxSound> movie) (prop &mut :Movie<FlxSprite,FlxScreenPosition,ActorFlxSprite,FlxSound,String,FlxSprite,FlxSound,FlxCamera> movie)
(defAlias &ident flxMovie (cast movie FlxMovie)) (defAlias &ident flxMovie (cast movie FlxMovie))
(loadFrom "hollywoo-flixel" "src/hollywoo_flixel/Aliases.kiss") (loadFrom "hollywoo-flixel" "src/hollywoo_flixel/Aliases.kiss")
@@ -22,7 +22,7 @@
(spriteLayers.push g) (spriteLayers.push g)
(FlxG.state.add g)))) (FlxG.state.add g))))
(method :Void showSet [:FlxSprite setSprite :SceneTime time :ScenePerspective perspective :Appearance appearance :Continuation cc] (method :Void showSet [:FlxSprite setSprite :SceneTime time :ScenePerspective perspective :Appearance appearance :FlxCamera camera :Continuation cc]
(case appearance (case appearance
(FirstAppearance (FirstAppearance
(setSprite.setGraphicSize FlxG.width) (setSprite.setGraphicSize FlxG.width)
@@ -31,10 +31,17 @@
(setSprite.updateHitbox) (setSprite.updateHitbox)
(setSprite.screenCenter)) (setSprite.screenCenter))
(otherwise)) (otherwise))
(FlxG.cameras.remove flxMovie.uiCamera false)
(FlxG.cameras.remove flxMovie.screenCamera false)
(FlxG.cameras.add camera)
(FlxG.cameras.add flxMovie.screenCamera)
(FlxG.cameras.add flxMovie.uiCamera)
(set setSprite.cameras [camera])
(FlxG.state.add setSprite) (FlxG.state.add setSprite)
(cc)) (cc))
(method :Void hideSet [:FlxSprite set :Continuation cc] (method :Void hideSet [:FlxSprite set :FlxCamera camera :Continuation cc]
(FlxG.cameras.remove camera false)
(FlxG.state.remove set) (FlxG.state.remove set)
(cc)) (cc))
@@ -42,9 +49,10 @@
(method :Option<AutoZConfig> autoZConfig [] (Some (object zPerLayer flxMovie.STAGE_BEHIND_DY frontLayer 0))) (method :Option<AutoZConfig> autoZConfig [] (Some (object zPerLayer flxMovie.STAGE_BEHIND_DY frontLayer 0)))
(method :Void showCharacter [:Character<ActorFlxSprite> character :Appearance appearance :Continuation cc] (method :Void showCharacter [:Character<ActorFlxSprite> character :Appearance appearance :FlxCamera camera :Continuation cc]
// TODO on the first appearance, show name and description (maybe? also probably not for all?) // TODO on the first appearance, show name and description (maybe? also probably not for all?)
// TODO also allow for manually defined flipped frames so text on clothing doesn't mirror // TODO also allow for manually defined flipped frames so text on clothing doesn't mirror
(set character.actor.cameras [camera])
(set character.actor.flipX ?!(= character.stageFacing character.actor.defaultFacing)) (set character.actor.flipX ?!(= character.stageFacing character.actor.defaultFacing))
// All actors same width, display centered on x // All actors same width, display centered on x
(character.actor.setGraphicSize flxMovie.ACTOR_WIDTH) (character.actor.setGraphicSize flxMovie.ACTOR_WIDTH)
@@ -62,7 +70,7 @@
(FlxG.state.add character.actor) (FlxG.state.add character.actor)
(cc)) (cc))
(method :Void hideCharacter [:Character<ActorFlxSprite> character :Continuation cc] (method :Void hideCharacter [:Character<ActorFlxSprite> character :FlxCamera camera :Continuation cc]
(FlxG.state.remove character.actor) (FlxG.state.remove character.actor)
(cc)) (cc))
@@ -136,11 +144,13 @@
(set dialogBox (new FlxSprite flxMovie.DIALOG_X flxMovie.DIALOG_Y)) (set dialogBox (new FlxSprite flxMovie.DIALOG_X flxMovie.DIALOG_Y))
(dialogBox.makeGraphic flxMovie.DIALOG_WIDTH flxMovie.DIALOG_HEIGHT DIALOG_BOX_COLOR)) (dialogBox.makeGraphic flxMovie.DIALOG_WIDTH flxMovie.DIALOG_HEIGHT DIALOG_BOX_COLOR))
(set dialogBox.cameras [flxMovie.uiCamera])
(FlxG.state.add dialogBox) (FlxG.state.add dialogBox)
(dialogBox.revive) (dialogBox.revive)
// show the dialog // show the dialog
(unless dialogText (unless dialogText
(set dialogText (new FlxText flxMovie.DIALOG_X flxMovie.DIALOG_Y flxMovie.DIALOG_WIDTH "" DIALOG_SIZE))) (set dialogText (new FlxText flxMovie.DIALOG_X flxMovie.DIALOG_Y flxMovie.DIALOG_WIDTH "" DIALOG_SIZE)))
(set dialogText.cameras [flxMovie.uiCamera])
(FlxG.state.add dialogText) (FlxG.state.add dialogText)
(set dialogText.text text) (set dialogText.text text)
// TODO actually page through the dialog instead of sizing it down? // TODO actually page through the dialog instead of sizing it down?
@@ -152,6 +162,7 @@
// show the speaker name // show the speaker name
(unless speakerNameText (unless speakerNameText
(set speakerNameText (new FlxText flxMovie.DIALOG_X flxMovie.DIALOG_Y 0 "" DIALOG_SIZE))) (set speakerNameText (new FlxText flxMovie.DIALOG_X flxMovie.DIALOG_Y 0 "" DIALOG_SIZE)))
(set speakerNameText.cameras [flxMovie.uiCamera])
(FlxG.state.add speakerNameText) (FlxG.state.add speakerNameText)
(if speakerName (if speakerName
{ {
@@ -278,6 +289,7 @@
(cc)) (cc))
(method :Void showPropOnScreen [:FlxSprite prop :FlxScreenPosition position :Continuation cc] (method :Void showPropOnScreen [:FlxSprite prop :FlxScreenPosition position :Continuation cc]
(set prop.cameras [flxMovie.screenCamera])
// TODO give the prop reveal some time to land (add a delay to the cc) // TODO give the prop reveal some time to land (add a delay to the cc)
(ifLet [(FullControl layer rpos) position] (ifLet [(FullControl layer rpos) position]
(smartShowPropOnScreen prop layer rpos cc) (smartShowPropOnScreen prop layer rpos cc)

View File

@@ -3,6 +3,7 @@ package hollywoo_flixel;
import flixel.FlxState; import flixel.FlxState;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.system.FlxSound; import flixel.system.FlxSound;
import flixel.FlxCamera;
import hollywoo.Director; import hollywoo.Director;
import hollywoo.Movie; import hollywoo.Movie;
import hollywoo_flixel.ActorFlxSprite; import hollywoo_flixel.ActorFlxSprite;
@@ -39,7 +40,7 @@ enum FlxScreenPosition {
/** /**
* Model/controller of a Hollywoo-Flixel film, and main execution script * Model/controller of a Hollywoo-Flixel film, and main execution script
*/ */
class FlxMovie extends Movie<FlxSprite, FlxScreenPosition, ActorFlxSprite, FlxSound, String, FlxSprite, FlxSound> { class FlxMovie extends Movie<FlxSprite, FlxScreenPosition, ActorFlxSprite, FlxSound, String, FlxSprite, FlxSound, FlxCamera> {
// Think of HollywooFlixelDSL.kiss as the corresponding Kiss file for this class! // Think of HollywooFlixelDSL.kiss as the corresponding Kiss file for this class!
public function new(director:FlxDirector, ?voiceLinesAssetPath:String) { public function new(director:FlxDirector, ?voiceLinesAssetPath:String) {
@@ -50,6 +51,8 @@ class FlxMovie extends Movie<FlxSprite, FlxScreenPosition, ActorFlxSprite, FlxSo
super(director, voiceLinesJson); super(director, voiceLinesJson);
} }
public var uiCamera:FlxCamera;
public var screenCamera:FlxCamera;
public var STAGE_LEFT_X:Float; public var STAGE_LEFT_X:Float;
public var STAGE_RIGHT_X:Float; public var STAGE_RIGHT_X:Float;

View File

@@ -64,6 +64,15 @@
(defAlias &ident flxDirector (cast director FlxDirector)) (defAlias &ident flxDirector (cast director FlxDirector))
(preload (preload
(unless uiCamera
(set uiCamera (new flixel.FlxCamera))
(set uiCamera.bgColor FlxColor.TRANSPARENT)
(flixel.FlxG.cameras.add uiCamera)
(set kiss_flixel.SimpleWindow.defaultCamera uiCamera))
(unless screenCamera
(set screenCamera (new flixel.FlxCamera))
(set screenCamera.bgColor FlxColor.TRANSPARENT)
(FlxG.cameras.add screenCamera))
// These are set here so they're defined after FlxG.width and height have been set: // These are set here so they're defined after FlxG.width and height have been set:
(set STAGE_LEFT_X 150.0) (set STAGE_LEFT_X 150.0)
(set STAGE_RIGHT_X (- FlxG.width STAGE_LEFT_X)) (set STAGE_RIGHT_X (- FlxG.width STAGE_LEFT_X))

View File

@@ -11,7 +11,7 @@ AWAITPLAYSOUND "pageFlip"
(defMacro makeSetAndScene [asset] (defMacro makeSetAndScene [asset]
`(preload `(preload
(newFlxSet ,asset ,asset) (newFlxSet ,asset ,asset)
(newSceneFromSet ,asset ,asset Day Exterior))) (newSceneFromSet ,asset ,asset Day Exterior (new FlxCamera))))
(var basicSceneKey AssetPaths.grayBackground1280x720__png) (var basicSceneKey AssetPaths.grayBackground1280x720__png)
(makeSetAndScene basicSceneKey) (makeSetAndScene basicSceneKey)
@@ -51,7 +51,7 @@ ADDCHARACTER "black" Right FacingLeft
// Speaker name not being bumped to right side for stage-right actors while intercutting: // Speaker name not being bumped to right side for stage-right actors while intercutting:
(preload (preload
(newFlxSet "intercutSet" AssetPaths.whiteBackground1280x720__png) (newFlxSet "intercutSet" AssetPaths.whiteBackground1280x720__png)
(newSceneFromSet "intercutScene" "intercutSet" Day Exterior)) (newSceneFromSet "intercutScene" "intercutSet" Day Exterior (new FlxCamera)))
SETSCENE "intercutScene" SETSCENE "intercutScene"
ADDCHARACTER "black" Right FacingLeft ADDCHARACTER "black" Right FacingLeft

View File

@@ -12,6 +12,7 @@ import flixel.FlxSprite;
import flixel.FlxSubState; import flixel.FlxSubState;
import flixel.util.FlxColor; import flixel.util.FlxColor;
import flixel.tweens.FlxTween; import flixel.tweens.FlxTween;
import flixel.FlxCamera;
@:build(kiss.AsyncEmbeddedScript.build("hollywoo-flixel", "src/hollywoo_flixel/HollywooFlixelDSL.kiss", "Test.hollywoo")) @:build(kiss.AsyncEmbeddedScript.build("hollywoo-flixel", "src/hollywoo_flixel/HollywooFlixelDSL.kiss", "Test.hollywoo"))
class Test extends FlxMovie { class Test extends FlxMovie {

View File

@@ -29,13 +29,13 @@ typedef AutoZConfig = {
frontLayer:Int frontLayer:Int
}; };
interface Director<Set:Cloneable<Set>, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack> { interface Director<Set:Cloneable<Set>, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack, Camera> {
var movie(default, default):Movie<Set, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack>; var movie(default, default):Movie<Set, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack, Camera>;
function autoZConfig():Option<AutoZConfig>; function autoZConfig():Option<AutoZConfig>;
function showSet(set:Set, time:SceneTime, perspective:ScenePerspective, appearance:Appearance, cc:Continuation):Void; function showSet(set:Set, time:SceneTime, perspective:ScenePerspective, appearance:Appearance, camera:Camera, cc:Continuation):Void;
function hideSet(set:Set, cc:Continuation):Void; function hideSet(set:Set, camera: Camera, cc:Continuation):Void;
function showCharacter(character:Character<Actor>, appearance:Appearance, cc:Continuation):Void; function showCharacter(character:Character<Actor>, appearance:Appearance, camera:Camera, cc:Continuation):Void;
function hideCharacter(character:Character<Actor>, cc:Continuation):Void; function hideCharacter(character:Character<Actor>, camera:Camera, cc:Continuation):Void;
function playSound(sound:Sound, volumeMod:Float, waitForEnd:Bool, cc:Continuation):Void; function playSound(sound:Sound, volumeMod:Float, waitForEnd:Bool, cc:Continuation):Void;
function stopSound(sound:Sound):Void; function stopSound(sound:Sound):Void;
function playSong(song:Song, volumeMod:Float, loop:Bool, waitForEnd:Bool, cc:Continuation):Void; function playSong(song:Song, volumeMod:Float, loop:Bool, waitForEnd:Bool, cc:Continuation):Void;

View File

@@ -42,4 +42,4 @@ enum CreditsLine {
* Model/controller of a Hollywoo film, and main execution script * Model/controller of a Hollywoo film, and main execution script
*/ */
@:build(kiss.Kiss.build()) @:build(kiss.Kiss.build())
class Movie<Set:Cloneable<Set>, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack> extends AsyncEmbeddedScript {} class Movie<Set:Cloneable<Set>, ScreenPosition, Actor, Sound, Song, Prop, VoiceTrack, Camera> extends AsyncEmbeddedScript {}

View File

@@ -18,7 +18,7 @@
(prop &mut :DelayHandling delayHandling AutoWithSkip) (prop &mut :DelayHandling delayHandling AutoWithSkip)
// Mutable representation of frames in time: // Mutable representation of frames in time:
(prop :FuzzyMap<Scene<Set,ScreenPosition,Actor,Prop>> scenes (new FuzzyMap<Scene<Set,ScreenPosition,Actor,Prop>>)) (prop :FuzzyMap<Scene<Set,ScreenPosition,Actor,Prop,Camera>> scenes (new FuzzyMap<Scene<Set,ScreenPosition,Actor,Prop,Camera>>))
(prop :FuzzyMap<Bool> shownScenes (new FuzzyMap<Bool>)) (prop :FuzzyMap<Bool> shownScenes (new FuzzyMap<Bool>))
(prop :FuzzyMap<Bool> shownCharacters (new FuzzyMap<Bool>)) (prop :FuzzyMap<Bool> shownCharacters (new FuzzyMap<Bool>))
@@ -105,13 +105,13 @@
(if sceneKey (if sceneKey
// hide current scene background // hide current scene background
(let [currentScene (dictGet scenes sceneKey)] (let [currentScene (dictGet scenes sceneKey)]
(director.hideSet currentScene.set (director.hideSet currentScene.set currentScene.camera
(makeCC (makeCC
// hide current scene characters // hide current scene characters
(_ccForEach (_ccForEach
currentScene.characters currentScene.characters
->[:Character<Actor> c :Continuation cc] ->[:Character<Actor> c :Continuation cc]
(director.hideCharacter c cc) (director.hideCharacter c currentScene.camera cc)
(makeCC (makeCC
// hide current scene props, etc. // hide current scene props, etc.
(_ccForEach (_ccForEach
@@ -121,15 +121,15 @@
cc)))))) cc))))))
(cc))) (cc)))
(method _showScene [:Scene<Set,ScreenPosition,Actor,Prop> scene :Appearance appearance :Continuation cc] (method _showScene [:Scene<Set,ScreenPosition,Actor,Prop,Camera> scene :Appearance appearance :Camera camera :Continuation cc]
// Show current scene background // Show current scene background
(director.showSet scene.set scene.time scene.perspective appearance (director.showSet scene.set scene.time scene.perspective appearance camera
(makeCC (makeCC
// Show current scene characters // Show current scene characters
(_ccForEach (_ccForEach
(object iterator ->(scene.characters.keys)) (object iterator ->(scene.characters.keys))
->[:String key :Continuation cc] ->[:String key :Continuation cc]
(director.showCharacter (dictGet scene.characters key) (appearanceFlag shownCharacters key) cc) (director.showCharacter (dictGet scene.characters key) (appearanceFlag shownCharacters key) camera cc)
(makeCC (makeCC
// hide current scene props, etc. // hide current scene props, etc.
(_ccForEach (_ccForEach
@@ -141,7 +141,7 @@
(defNew (defNew
[ [
// "View" in the Model-View-Controller architecture: // "View" in the Model-View-Controller architecture:
&prop :Director<Set,ScreenPosition,Actor,Sound,Song,Prop,VoiceTrack> director &prop :Director<Set,ScreenPosition,Actor,Sound,Song,Prop,VoiceTrack,Camera> director
&opt :String voiceLinesJson &opt :String voiceLinesJson
&opt :String positionsJson &opt :String positionsJson
] ]
@@ -219,7 +219,7 @@
(assert isLoading) (assert isLoading)
(dictSet sets name set)) (dictSet sets name set))
(hollywooMethod newSceneFromSet true [name :String setKey :SceneTime time :ScenePerspective perspective] (hollywooMethod newSceneFromSet true [name :String setKey :SceneTime time :ScenePerspective perspective :Camera camera]
(assert isLoading) (assert isLoading)
(dictSet scenes name (objectWith (dictSet scenes name (objectWith
[ [
@@ -229,6 +229,8 @@
(new FuzzyMap<Character<Actor>>) (new FuzzyMap<Character<Actor>>)
propsOnScreen propsOnScreen
(new FuzzyMap<ScreenProp<ScreenPosition,Prop>>) (new FuzzyMap<ScreenProp<ScreenPosition,Prop>>)
camera
camera
] ]
time time
perspective))) perspective)))
@@ -240,6 +242,7 @@
(_showScene (_showScene
(dictGet scenes name) (dictGet scenes name)
(appearanceFlag shownScenes name) (appearanceFlag shownScenes name)
.camera (dictGet scenes name)
cc)))) cc))))
@@ -305,12 +308,13 @@
(director.showCharacter (director.showCharacter
character character
(appearanceFlag shownCharacters actorName) (appearanceFlag shownCharacters actorName)
.camera (_currentScene)
cc))))) cc)))))
(hollywooMethod removeCharacter false [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 .camera (_currentScene) cc)))
// INSTANTLY move a character: // INSTANTLY move a character:
(hollywooMethod moveCharacter false [actorName :Dynamic newPosition :StageFacing newFacing :Continuation cc] (hollywooMethod moveCharacter false [actorName :Dynamic newPosition :StageFacing newFacing :Continuation cc]

View File

@@ -38,11 +38,12 @@ typedef ScreenProp<ScreenPosition,Prop> = {
prop:Prop prop:Prop
}; };
typedef Scene<Set:Cloneable<Set>, ScreenPosition, Actor, Prop> = { typedef Scene<Set:Cloneable<Set>, ScreenPosition, Actor, Prop, Camera> = {
set:Set, set:Set,
characters:FuzzyMap<Character<Actor>>, characters:FuzzyMap<Character<Actor>>,
propsOnScreen:FuzzyMap<ScreenProp<ScreenPosition,Prop>>, propsOnScreen:FuzzyMap<ScreenProp<ScreenPosition,Prop>>,
// TODO props on stage // TODO props on stage
time:SceneTime, time:SceneTime,
perspective:ScenePerspective perspective:ScenePerspective,
camera:Camera
}; };