add connections in NAT playground
This commit is contained in:
@@ -336,8 +336,11 @@
|
||||
(archive.changePlaygrounds ->:Void [:DynamicAccess<Dynamic> p] (dictSet p "default" name))
|
||||
(when playgroundSystem (playgroundSystem.switchPlaygroundKey name)))
|
||||
|
||||
(defCommand RemoveFromPlayground [entries (SelectedEntries 1 null)]
|
||||
(defCommand AddConnections [entries (SelectedEntries 1 null) entriesToConnect (Entries 1 null)]
|
||||
(for e entries
|
||||
(when (hasComponent e Positions)
|
||||
(withWritableComponents archive e [positions Positions]
|
||||
(positions.remove (dictGet archive.playgrounds "default")))) e)))
|
||||
(addConnections archive e entriesToConnect)))
|
||||
|
||||
(defCommand RemoveConnections [entries (SelectedEntries 1 null) entriesToRemove (Entries 1 null)]
|
||||
(for e entries
|
||||
(addConnections archive e entriesToRemove)))
|
||||
)
|
||||
|
||||
@@ -131,3 +131,14 @@
|
||||
(if (hasComponent e Scale)
|
||||
(readComponent e Scale)
|
||||
1.0)))
|
||||
|
||||
(function addConnections [:nat.Archive archive :nat.Entry e :Array<Entry> entriesToConnect]
|
||||
(if (hasComponent e Connections)
|
||||
(withWritableComponents archive e [conn Connections]
|
||||
(doFor e2 entriesToConnect (dictSet conn e2.id 1)))
|
||||
(addComponent archive e Connections (for e2 entriesToConnect =>e2.id 1))))
|
||||
|
||||
(function removeConnections [:nat.Archive archive :nat.Entry e :Array<Entry> entriesToRemove]
|
||||
(when (hasComponent e Connections)
|
||||
(withWritableComponents archive e [conn Connections]
|
||||
(doFor e2 entriesToRemove (conn.remove e2.id)))))
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package nat.components;
|
||||
|
||||
typedef Connections = Map<EntryRef,Int>;
|
||||
@@ -9,6 +9,8 @@
|
||||
[&mut :Bool selected false
|
||||
&mut :Bool isCircle false]
|
||||
(super position.x position.y)
|
||||
(enableMouseClicks false)
|
||||
(set mousePressedCallback ->:Void [_ _ _] null)
|
||||
(cond
|
||||
((hasComponent e Images2)
|
||||
(let [images (readComponent e Images2)]
|
||||
|
||||
@@ -240,12 +240,19 @@
|
||||
Math.POSITIVE_INFINITY))
|
||||
|
||||
(method :Void chooseEntry [prompt :Archive archive resolve]
|
||||
(resolve null))
|
||||
(entryGroup.forEach ->s
|
||||
(set s.mousePressedCallback ->:Void [s _ _] {
|
||||
(entryGroup.forEach ->s
|
||||
(set s.mousePressedCallback ->:Void [_ _ _] null))
|
||||
(resolve .e (cast s EntrySprite))
|
||||
})))
|
||||
|
||||
(method :Void chooseEntries [prompt archive resolve min max]
|
||||
(_chooseEntries prompt archive resolve min max []))
|
||||
|
||||
// TODO is it possible to resolve with less than max?
|
||||
// TODO this version that just delegates to (chooseEntry) should be reusable, which is tricky because ArchiveUI is an interface
|
||||
// It also needs a way to resolve with less than the maximum, which may be infinity
|
||||
(method :Void _chooseEntries [prompt archive resolve min max :Array<Entry> collectedEntries]
|
||||
(let [&mut :Void->Void chooseNextEntry
|
||||
null
|
||||
|
||||
Reference in New Issue
Block a user