Move EntryRep/id tracking to PlaygroundSystem

This commit is contained in:
2023-02-13 05:15:22 -07:00
parent 98b6bb59d8
commit 8e9da6cbca
6 changed files with 22 additions and 7 deletions

View File

@@ -280,7 +280,7 @@
(method getSelectedEntries []
(_selectedEntries.copy))
(prop &mut :PlaygroundSystem playgroundSystem null)
(prop &mut :PlaygroundSystem<Dynamic> playgroundSystem null)
(defNew [&prop :Archive archive
&prop :ArchiveUI ui]

View File

@@ -24,7 +24,7 @@ interface ArchiveUI {
/**
* A PlaygroundSystem that will display interactible entry representations
*/
function playgroundSystem():Null<PlaygroundSystem>;
function playgroundSystem():Null<PlaygroundSystem<Dynamic>>;
/**
* Prompt the user to enter text

View File

@@ -117,4 +117,4 @@
(method :Void hidePrefixMap [])
(method :PlaygroundSystem playgroundSystem [] null)
(method :PlaygroundSystem<String> playgroundSystem [] null)

View File

@@ -15,4 +15,4 @@ typedef PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Positi
* (EntrySpriteSystem, for example)
*/
@:build(kiss.Kiss.build())
class PlaygroundSystem extends System {}
class PlaygroundSystem<EntryRep> extends System {}

View File

@@ -6,12 +6,20 @@
(prop :Map<String,TagList> playgroundDefaultTags (new Map))
(prop :Map<String,ColorF> playgroundBGColors (new Map))
(prop :Map<String,EntryRep> 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

View File

@@ -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<PlaygroundSystem> {
public function playgroundSystem():Null<PlaygroundSystem<Dynamic>> {
return null;
}
public var shortcutHandler:Null<KeyShortcutHandler<Entry>> = null;