Close #128: ArchiveUI defines cursorPosition() which is used to place entries
This commit is contained in:
@@ -44,8 +44,12 @@
|
|||||||
(method processSystems [&opt :ArchiveUI ui]
|
(method processSystems [&opt :ArchiveUI ui]
|
||||||
(doFor system systems (system.process this ui)))
|
(doFor system systems (system.process this ui)))
|
||||||
|
|
||||||
|
(prop &mut :Entry->Dynamic defaultInitializer null)
|
||||||
|
|
||||||
(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
|
(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
|
||||||
(let [e (_newEntry)]
|
(let [e (_newEntry)]
|
||||||
|
(when defaultInitializer
|
||||||
|
(defaultInitializer e))
|
||||||
(initializer e)
|
(initializer e)
|
||||||
(dictSet entries e.id e)
|
(dictSet entries e.id e)
|
||||||
(refreshEntry e)
|
(refreshEntry e)
|
||||||
|
@@ -241,12 +241,7 @@
|
|||||||
(ui.displayMessage "Entry ${e.id} has no $componentType component"))) [])
|
(ui.displayMessage "Entry ${e.id} has no $componentType component"))) [])
|
||||||
|
|
||||||
(defCommand CreateEntry [name (Text null)]
|
(defCommand CreateEntry [name (Text null)]
|
||||||
[(archive.createEntry ->e
|
[(archive.createEntry ->e (addComponent archive e Name name))])
|
||||||
{
|
|
||||||
(when (and playgroundSystem (playgroundSystem.currentDefaultTags))
|
|
||||||
(addTags archive e (playgroundSystem.currentDefaultTags)))
|
|
||||||
(addComponent archive e Name name)
|
|
||||||
})])
|
|
||||||
|
|
||||||
(defCommand CreateEntries [names (VarText null)]
|
(defCommand CreateEntries [names (VarText null)]
|
||||||
// createEntry returns a list, so these lists must be flattened
|
// createEntry returns a list, so these lists must be flattened
|
||||||
|
@@ -4,6 +4,8 @@ import nat.Entry;
|
|||||||
import nat.ArchiveController;
|
import nat.ArchiveController;
|
||||||
import kiss_tools.KeyShortcutHandler;
|
import kiss_tools.KeyShortcutHandler;
|
||||||
import nat.systems.PlaygroundSystem;
|
import nat.systems.PlaygroundSystem;
|
||||||
|
import haxe.ds.Option;
|
||||||
|
import nat.components.Position;
|
||||||
|
|
||||||
interface ArchiveUI {
|
interface ArchiveUI {
|
||||||
/**
|
/**
|
||||||
@@ -63,4 +65,9 @@ interface ArchiveUI {
|
|||||||
* Update UI to show that the set of selected entries has changed
|
* Update UI to show that the set of selected entries has changed
|
||||||
*/
|
*/
|
||||||
function onSelectionChanged(selectedEntries:Array<Entry>, lastSelectedEntries:Array<Entry>):Void;
|
function onSelectionChanged(selectedEntries:Array<Entry>, lastSelectedEntries:Array<Entry>):Void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A way to tell NAT where the cursor is
|
||||||
|
*/
|
||||||
|
function cursorPosition():Option<Position>;
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import kiss.List;
|
|||||||
import nat.System;
|
import nat.System;
|
||||||
import nat.components.*;
|
import nat.components.*;
|
||||||
import haxe.DynamicAccess;
|
import haxe.DynamicAccess;
|
||||||
|
import haxe.ds.Option;
|
||||||
|
|
||||||
typedef PlaygroundEntryProcessor = (Archive, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
|
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
|
typedef PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
|
||||||
|
@@ -42,6 +42,14 @@
|
|||||||
(method switchPlaygroundKey [key]
|
(method switchPlaygroundKey [key]
|
||||||
(set _playgroundKey key)
|
(set _playgroundKey key)
|
||||||
(clear (or (dictGet playgroundBGColors _playgroundKey) (object r 0.0 g 0.0 b 0.0 a 1.0)))
|
(clear (or (dictGet playgroundBGColors _playgroundKey) (object r 0.0 g 0.0 b 0.0 a 1.0)))
|
||||||
|
(set ui.controller.archive.defaultInitializer ->e
|
||||||
|
{
|
||||||
|
(when (currentDefaultTags)
|
||||||
|
(addTags ui.controller.archive e (currentDefaultTags)))
|
||||||
|
|
||||||
|
(whenLet [(Some position) (ui.cursorPosition)]
|
||||||
|
(addComponent ui.controller.archive e Positions [=>_playgroundKey position]))
|
||||||
|
})
|
||||||
(process ui.controller.archive ui))
|
(process ui.controller.archive ui))
|
||||||
|
|
||||||
(method :Void clear [:Color color]
|
(method :Void clear [:Color color]
|
||||||
|
@@ -25,6 +25,8 @@ import kiss_tools.FlxKeyShortcutHandler;
|
|||||||
import nat.systems.PlaygroundSystem;
|
import nat.systems.PlaygroundSystem;
|
||||||
import flash.desktop.Clipboard;
|
import flash.desktop.Clipboard;
|
||||||
import flash.desktop.ClipboardFormats;
|
import flash.desktop.ClipboardFormats;
|
||||||
|
import haxe.ds.Option;
|
||||||
|
import nat.components.Position;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class PlayState extends FlxState implements ArchiveUI {}
|
class PlayState extends FlxState implements ArchiveUI {}
|
||||||
|
@@ -330,4 +330,8 @@
|
|||||||
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
||||||
(doFor e (selectedEntries.concat lastSelectedEntries)
|
(doFor e (selectedEntries.concat lastSelectedEntries)
|
||||||
(whenLet [sprite (dictGet spriteSystem.sprites e.id)]
|
(whenLet [sprite (dictGet spriteSystem.sprites e.id)]
|
||||||
(sprite.updateColor))))
|
(sprite.updateColor))))
|
||||||
|
|
||||||
|
(method :Option<Position> cursorPosition []
|
||||||
|
(let [pos (FlxG.mouse.getWorldPosition FlxG.camera)]
|
||||||
|
(Some (object x pos.x y pos.y z 0.0))))
|
Reference in New Issue
Block a user