From 250b092192a605c1403706fcb06e46373fbb5012 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 30 Mar 2023 06:37:21 -0600 Subject: [PATCH] Make stagePositions a JsonMap --- .../src/hollywoo_flixel/FlxMovie.hx | 4 +- .../hollywoo_flixel/HollywooFlixelDSL.kiss | 40 +++++++++---------- projects/hollywoo/src/hollywoo/Director.hx | 6 --- projects/hollywoo/src/hollywoo/Movie.hx | 1 + projects/hollywoo/src/hollywoo/Movie.kiss | 15 ++++--- .../hollywoo/src/hollywoo/StagePosition.hx | 7 ++++ .../hollywoo/src/hollywoo/StagePosition.kiss | 6 +++ 7 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 projects/hollywoo/src/hollywoo/StagePosition.hx create mode 100644 projects/hollywoo/src/hollywoo/StagePosition.kiss diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx index cb3119d5..f9b51ad6 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx @@ -44,13 +44,13 @@ enum FlxScreenPosition { class FlxMovie extends Movie { // Think of HollywooFlixelDSL.kiss as the corresponding Kiss file for this class! - public function new(director:FlxDirector, lightSourceJsonFile:String, ?voiceLinesAssetPath:String, ?positionsJson:String) { + public function new(director:FlxDirector, lightSourceJsonFile:String, positionsJson:String, ?voiceLinesAssetPath:String) { var voiceLinesJson = null; if (voiceLinesAssetPath != null) { voiceLinesJson = Assets.getText(voiceLinesAssetPath); } - super(director, lightSourceJsonFile, new FlxLightSource([], FlxColor.TRANSPARENT), voiceLinesJson, positionsJson); + super(director, lightSourceJsonFile, new FlxLightSource([], FlxColor.TRANSPARENT), positionsJson, voiceLinesJson); } public var uiCamera:FlxCamera; public var screenCamera:FlxCamera; diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss index 2bf71e74..f6c8b2ab 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss @@ -85,24 +85,24 @@ (set DIALOG_WIDTH (- FlxG.width ACTOR_WIDTH ACTOR_WIDTH)) (set DIALOG_HEIGHT (- FlxG.height DIALOG_Y)) #{ - stagePositions["Left"] = { - x: STAGE_LEFT_X, - y: ACTOR_Y, - z: 0.0 - }; - stagePositions["Right"] = { - x: STAGE_RIGHT_X, - y: ACTOR_Y, - z: 0.0 - }; - stagePositions["Left2"] = { - x: STAGE_LEFT_X, - y: ACTOR_Y, - z: STAGE_BEHIND_DY - }; - stagePositions["Right2"] = { - x: STAGE_RIGHT_X, - y: ACTOR_Y, - z: STAGE_BEHIND_DY - }; + stagePositions.put("Left", new StagePosition( + STAGE_LEFT_X, + ACTOR_Y, + 0.0 + )); + stagePositions.put("Right", new StagePosition( + STAGE_RIGHT_X, + ACTOR_Y, + 0.0 + )); + stagePositions.put("Left2", new StagePosition( + STAGE_LEFT_X, + ACTOR_Y, + STAGE_BEHIND_DY + )); + stagePositions.put("Right2", new StagePosition( + STAGE_RIGHT_X, + ACTOR_Y, + STAGE_BEHIND_DY + )); }#) \ No newline at end of file diff --git a/projects/hollywoo/src/hollywoo/Director.hx b/projects/hollywoo/src/hollywoo/Director.hx index 97cfebe9..6365e050 100644 --- a/projects/hollywoo/src/hollywoo/Director.hx +++ b/projects/hollywoo/src/hollywoo/Director.hx @@ -12,12 +12,6 @@ enum Appearance { typedef Continuation = Void -> Void; -typedef StagePosition = { - x:Float, - y:Float, - z:Float, -}; - enum StageFacing { TowardsCharacter(name:String); AwayFromCharacter(name:String); diff --git a/projects/hollywoo/src/hollywoo/Movie.hx b/projects/hollywoo/src/hollywoo/Movie.hx index 89a3fe15..98139b9d 100644 --- a/projects/hollywoo/src/hollywoo/Movie.hx +++ b/projects/hollywoo/src/hollywoo/Movie.hx @@ -8,6 +8,7 @@ import kiss.Stream; import kiss.FuzzyMap; import hollywoo.Scene; import hollywoo.Director; +import hollywoo.StagePosition; import haxe.Json; import uuid.Uuid; import haxe.ds.Option; diff --git a/projects/hollywoo/src/hollywoo/Movie.kiss b/projects/hollywoo/src/hollywoo/Movie.kiss index 25ac5574..96e58f82 100644 --- a/projects/hollywoo/src/hollywoo/Movie.kiss +++ b/projects/hollywoo/src/hollywoo/Movie.kiss @@ -146,15 +146,14 @@ &prop :Director director :String lightSourceJsonFile :LightSource defaultLightSource + :String stagePositionsJson &opt :String voiceLinesJson - &opt :String positionsJson ] [ - :Map stagePositions - (if positionsJson - (haxe.Json.parse (sys.io.File.getContent positionsJson)) - (new Map)) - :JsonMap> lightSources (new JsonMap lightSourceJsonFile (new JsonableArray [] defaultLightSource)) + :JsonMap stagePositions + (new JsonMap stagePositionsJson (new StagePosition 0 0 0)) + :JsonMap> lightSources + (new JsonMap lightSourceJsonFile (new JsonableArray [] defaultLightSource)) ] (set director.movie this) @@ -306,7 +305,7 @@ (hollywooMethod addCharacter false [actorName :Dynamic position :StageFacing facing :Continuation cc] (let [position (typeCase [position] - ([:String pKey] (dictGet stagePositions pKey)) + ([:String pKey] (stagePositions.get pKey)) (otherwise position)) character (object stagePosition position stageFacing facing actor (dictGet actors actorName))] (autoZProcess position @@ -326,7 +325,7 @@ // INSTANTLY move a character: (hollywooMethod moveCharacter false [actorName :Dynamic newPosition :StageFacing newFacing :Continuation cc] (let [newPosition (typeCase [newPosition] - ([:String pKey] (dictGet stagePositions pKey)) + ([:String pKey] (stagePositions.get pKey)) (otherwise newPosition))] (removeCharacter actorName (makeCC diff --git a/projects/hollywoo/src/hollywoo/StagePosition.hx b/projects/hollywoo/src/hollywoo/StagePosition.hx new file mode 100644 index 00000000..79ba3919 --- /dev/null +++ b/projects/hollywoo/src/hollywoo/StagePosition.hx @@ -0,0 +1,7 @@ +package hollywoo; + +import kiss.Prelude; +import kiss.List; + +@:build(kiss.Kiss.build()) +class StagePosition {} diff --git a/projects/hollywoo/src/hollywoo/StagePosition.kiss b/projects/hollywoo/src/hollywoo/StagePosition.kiss new file mode 100644 index 00000000..c1fb94e6 --- /dev/null +++ b/projects/hollywoo/src/hollywoo/StagePosition.kiss @@ -0,0 +1,6 @@ +(defNew [&prop :Float x &prop :Float y &prop :Float z]) + +(method stringify [] "${x}|${y}|${z}") +(method parse [:String data] + (let [[x y z] (for coord (data.split "|") (Std.parseFloat coord))] + (new StagePosition x y z))) \ No newline at end of file