playground systems process connections

This commit is contained in:
2022-09-08 01:38:58 +00:00
parent 8e5fde91fb
commit 01df515cc4
3 changed files with 12 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import nat.System;
import nat.components.Position;
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
/**
* Base class for Systems that process Entries in a playground view and displays them in an interactive form

View File

@@ -6,6 +6,7 @@
(defNew [&prop :ArchiveUI ui
:EntryChecker canProcess
&prop :PlaygroundEntryProcessor processor
&prop :PlaygroundConnectionProcessor connectionProcessor
:EntryProcessor onRemoveEntry]
(super
@@ -31,7 +32,14 @@
(method :Void clear [])
(method &override :Void process [:Archive archive &opt :ArchiveUI ui]
(when _playgroundKey (super.process archive ui)))
(when _playgroundKey
(super.process archive ui)
(doFor e (entries.iterator)
(let [pos (dictGet (readComponent e Positions) _playgroundKey)]
(doFor =>e2id _ (readComponentOr e Connections (new Map<String,Int>))
(whenLet [e2 (dictGet archive.entries e2id)
pos2 (dictGet (readComponent e2 Positions) _playgroundKey)]
(connectionProcessor archive e pos e2 pos2 ui)))))))
(method defaultPosition [:Entry e]
(object x 0.0 y 0.0 z 0.0))

View File

@@ -17,6 +17,8 @@
(let [sprite (new EntrySprite this _playgroundKey pos archive e controller)]
(playState.entryGroup.add sprite)
(dictSet sprites e.id sprite)))
->[archive e pos e2 pos2 &opt ui]
~"$e $e2"
->[archive e &opt ui]
{
(whenLet [sprite (dictGet sprites e.id)]