From 8e9da6cbca3606235aa50df96b10e61342de9c7b Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 13 Feb 2023 05:15:22 -0700 Subject: [PATCH] Move EntryRep/id tracking to PlaygroundSystem --- src/nat/ArchiveController.kiss | 2 +- src/nat/ArchiveUI.hx | 2 +- src/nat/CLI.kiss | 2 +- src/nat/systems/PlaygroundSystem.hx | 2 +- src/nat/systems/PlaygroundSystem.kiss | 19 +++++++++++++++++-- src/test/DummyUI.hx | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/nat/ArchiveController.kiss b/src/nat/ArchiveController.kiss index 55fa08d..6df3008 100644 --- a/src/nat/ArchiveController.kiss +++ b/src/nat/ArchiveController.kiss @@ -280,7 +280,7 @@ (method getSelectedEntries [] (_selectedEntries.copy)) -(prop &mut :PlaygroundSystem playgroundSystem null) +(prop &mut :PlaygroundSystem playgroundSystem null) (defNew [&prop :Archive archive &prop :ArchiveUI ui] diff --git a/src/nat/ArchiveUI.hx b/src/nat/ArchiveUI.hx index 54ef2ff..50901d3 100644 --- a/src/nat/ArchiveUI.hx +++ b/src/nat/ArchiveUI.hx @@ -24,7 +24,7 @@ interface ArchiveUI { /** * A PlaygroundSystem that will display interactible entry representations */ - function playgroundSystem():Null; + function playgroundSystem():Null>; /** * Prompt the user to enter text diff --git a/src/nat/CLI.kiss b/src/nat/CLI.kiss index 9763a17..f899465 100644 --- a/src/nat/CLI.kiss +++ b/src/nat/CLI.kiss @@ -117,4 +117,4 @@ (method :Void hidePrefixMap []) -(method :PlaygroundSystem playgroundSystem [] null) \ No newline at end of file +(method :PlaygroundSystem playgroundSystem [] null) \ No newline at end of file diff --git a/src/nat/systems/PlaygroundSystem.hx b/src/nat/systems/PlaygroundSystem.hx index 6ec2555..98ea918 100644 --- a/src/nat/systems/PlaygroundSystem.hx +++ b/src/nat/systems/PlaygroundSystem.hx @@ -15,4 +15,4 @@ typedef PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Positi * (EntrySpriteSystem, for example) */ @:build(kiss.Kiss.build()) -class PlaygroundSystem extends System {} +class PlaygroundSystem extends System {} diff --git a/src/nat/systems/PlaygroundSystem.kiss b/src/nat/systems/PlaygroundSystem.kiss index db3ccbe..33cb778 100644 --- a/src/nat/systems/PlaygroundSystem.kiss +++ b/src/nat/systems/PlaygroundSystem.kiss @@ -6,12 +6,20 @@ (prop :Map playgroundDefaultTags (new Map)) (prop :Map playgroundBGColors (new Map)) +(prop :Map entryReps (new Map)) (defNew [&prop :ArchiveUI ui + &prop :ArchiveController controller :EntryChecker canProcess - &prop :PlaygroundEntryProcessor processor + &prop :PlaygroundEntryProcessor createEntryRep &prop :PlaygroundConnectionProcessor connectionProcessor :EntryProcessor onRemoveEntry] + + [:PlaygroundEntryProcessor processor + ->[archive e pos &opt ui] + (unless (entryReps.exists e.id) + (let [eRep (createEntryRep archive e pos ui)] + (dictSet entryReps e.id eRep)))] (super ->[archive e] @@ -37,7 +45,11 @@ (dictSet positions _playgroundKey (defaultPosition e)))) (let [pos (dictGet (readComponent e Positions) _playgroundKey)] (processor archive e pos ui))))) - (set this.onRemoveEntry onRemoveEntry)) + (set this.onRemoveEntry + ->[archive e &opt ui] { + (onRemoveEntry archive e ui) + (entryReps.remove e.id) + })) (method switchPlaygroundKey [key] (set _playgroundKey key) @@ -75,6 +87,9 @@ (method defaultPosition [:Entry e] (object x 0.0 y 0.0 z 0.0)) +(method getSelectedReps [] + (filter (for e (controller.getSelectedEntries) (dictGet entryReps e.id)))) + // TODO overridable circleContainsEntry function (default is to check only the position, Flixel version will use scaled sprite bounding box) // TODO when a circle contains an entry in the current playground, add it as a child \ No newline at end of file diff --git a/src/test/DummyUI.hx b/src/test/DummyUI.hx index 1a19ff4..a2f02f5 100644 --- a/src/test/DummyUI.hx +++ b/src/test/DummyUI.hx @@ -52,7 +52,7 @@ class DummyUI implements ArchiveUI { public function choosePosition(prompt:String, resolve:Position->Void) { resolve({x: 0, y: 0, z: 0}); } - public function playgroundSystem():Null { + public function playgroundSystem():Null> { return null; } public var shortcutHandler:Null> = null;