From b76fb12d15e94615dfa758a2ea89f7c3b0b7978f Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 28 Sep 2022 20:36:40 +0000 Subject: [PATCH] WIP make NAT playgrounds component-based (#124) --- .../src/nat/ArchiveController.kiss | 4 ++ .../src/nat/components/CatsMatchExp.hx | 3 ++ .../src/nat/components/TagList.hx | 3 ++ .../src/nat/systems/PlaygroundSystem.hx | 3 +- .../src/nat/systems/PlaygroundSystem.kiss | 45 ++++++++++++++----- .../source/EntrySpriteSystem.hx | 3 +- .../source/EntrySpriteSystem.kiss | 3 +- 7 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 projects/nat-archive-tool/src/nat/components/CatsMatchExp.hx create mode 100644 projects/nat-archive-tool/src/nat/components/TagList.hx diff --git a/projects/nat-archive-tool/src/nat/ArchiveController.kiss b/projects/nat-archive-tool/src/nat/ArchiveController.kiss index 63e656a6..57fbf1de 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveController.kiss +++ b/projects/nat-archive-tool/src/nat/ArchiveController.kiss @@ -209,6 +209,9 @@ (whenLet [ps (ui.playgroundSystem)] (set playgroundSystem ps) (archive.addSystem ps) + (set ps.setupProcess true) + (ps.process archive ui) + (set ps.setupProcess false) (ps.switchPlaygroundKey (dictGet archive.playgrounds "default"))) // Just for testing: @@ -338,6 +341,7 @@ (defCommand CreatePlayground [name (Text null) catsMatchExp (Text null)] (archive.changePlaygrounds ->:Void [:DynamicAccess p] (dictSet p name (object catsMatch catsMatchExp))) + // TODO make the corresponding playground entry and return it []) (defCommand SwitchPlayground [name (Text null)] diff --git a/projects/nat-archive-tool/src/nat/components/CatsMatchExp.hx b/projects/nat-archive-tool/src/nat/components/CatsMatchExp.hx new file mode 100644 index 00000000..95783c69 --- /dev/null +++ b/projects/nat-archive-tool/src/nat/components/CatsMatchExp.hx @@ -0,0 +1,3 @@ +package nat.components; + +typedef CatsMatchExp = String; diff --git a/projects/nat-archive-tool/src/nat/components/TagList.hx b/projects/nat-archive-tool/src/nat/components/TagList.hx new file mode 100644 index 00000000..c3dfe6c9 --- /dev/null +++ b/projects/nat-archive-tool/src/nat/components/TagList.hx @@ -0,0 +1,3 @@ +package nat.components; + +typedef TagList = Array; diff --git a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx index fe102c94..d8b6f418 100644 --- a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx +++ b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx @@ -3,7 +3,8 @@ package nat.systems; import kiss.Prelude; import kiss.List; import nat.System; -import nat.components.Position; +import nat.components.*; +import haxe.DynamicAccess; typedef PlaygroundEntryProcessor = (Archive, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void typedef PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void diff --git a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss index d3f4a1af..afde7de5 100644 --- a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss @@ -1,8 +1,12 @@ (load "../Lib.kiss") (prop &mut :String _playgroundKey "") +(prop &mut :TagList currentDefaultTags []) (method :String getPlaygroundKey [] _playgroundKey) +(prop :Map playgroundDefaultTags (new Map)) +(prop :Map playgroundBGColors (new Map)) + (defNew [&prop :ArchiveUI ui :EntryChecker canProcess &prop :PlaygroundEntryProcessor processor @@ -11,28 +15,45 @@ (super ->[archive e] - (and (tagsMatch e "!(or done hidden)") (canProcess archive e)) + (or (tagsMatch e "playground") + (and (tagsMatch e "!(or done hidden)") (canProcess archive e))) ->[archive e &opt ui] - (when (catsMatch e .catsMatch (dictGet archive.playgrounds _playgroundKey)) - (when !(hasComponent e Positions) - (addComponent archive e Positions (new Map))) - (withWritableComponents archive e [positions Positions] - (when !(positions.exists _playgroundKey) - (dictSet positions _playgroundKey (defaultPosition e)))) - (let [pos (dictGet (readComponent e Positions) _playgroundKey)] - (processor archive e pos ui)))) + (if setupProcess + // Read playground information from playground Entries + (when (catsMatch e "(and playground Name)") + (let [name (readComponent e Name)] + (if (hasComponent e CatsMatchExp) + (archive.changePlaygrounds ->:Void [:DynamicAccess p] (set .catsMatch (dictGet p name) (readComponent e CatsMatchExp))) + (addComponent archive e CatsMatchExp .catsMatch (dictGet archive.playgrounds name))) + (dictSet playgroundBGColors name (readComponentOr e Color (object r 0.0 g 0.0 b 0.0 a 1.0))) + (dictSet playgroundDefaultTags name (readComponentOr e TagList [])))) + + // Process Entries belonging to the current playground + (when (catsMatch e .catsMatch (dictGet archive.playgrounds _playgroundKey)) + (when !(hasComponent e Positions) + (addComponent archive e Positions (new Map))) + (withWritableComponents archive e [positions Positions] + (when !(positions.exists _playgroundKey) + (dictSet positions _playgroundKey (defaultPosition e)))) + (let [pos (dictGet (readComponent e Positions) _playgroundKey)] + (processor archive e pos ui))))) (set this.onRemoveEntry onRemoveEntry)) (method switchPlaygroundKey [key] - (when _playgroundKey - (clear)) (set _playgroundKey key) + (clear (or (dictGet playgroundBGColors _playgroundKey) (object r 0.0 g 0.0 b 0.0 a 1.0))) (process ui.controller.archive ui)) -(method :Void clear []) +(method :Void clear [:Color color] + (throw "(PlaygroundSystem.clear ) not implemented")) + +(prop &mut :Bool setupProcess false) (method &override :Void process [:Archive archive &opt :ArchiveUI ui] (when _playgroundKey + (set setupProcess true) + (super.process archive ui) + (set setupProcess false) (super.process archive ui) (doFor e (entries.iterator) (when (hasComponent e Positions) diff --git a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.hx b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.hx index 4a738ffe..7c24d9d0 100644 --- a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.hx +++ b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.hx @@ -8,9 +8,8 @@ import nat.ArchiveController; import nat.ArchiveUI; import nat.Archive; import nat.Entry; -import nat.components.Position; +import nat.components.*; using kiss_flixel.CameraTools; -import nat.components.Positions; import nat.systems.PlaygroundSystem; import flixel.util.FlxSort; diff --git a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss index d050c56f..c2ba605e 100644 --- a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss +++ b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss @@ -32,7 +32,8 @@ (controller.DeSelectEntry e) })) -(method &override :Void clear [] +(method &override :Void clear [:Color color] + (set playState.bgColor (FlxColor.fromRGBFloat color.r color.g color.b color.a)) (playState.debugLayer.clear) (sprites.clear) (playState.entryGroup.kill)