From 9ab0c3d671f6be00f84f5b19546466bd0c03cc0f Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 28 Sep 2022 23:05:12 +0000 Subject: [PATCH] Close #128: ArchiveUI defines cursorPosition() which is used to place entries --- projects/nat-archive-tool/src/nat/Archive.kiss | 4 ++++ projects/nat-archive-tool/src/nat/ArchiveController.kiss | 7 +------ projects/nat-archive-tool/src/nat/ArchiveUI.hx | 7 +++++++ .../nat-archive-tool/src/nat/systems/PlaygroundSystem.hx | 1 + .../src/nat/systems/PlaygroundSystem.kiss | 8 ++++++++ .../nat-flixel-desktop-playground/source/PlayState.hx | 2 ++ .../nat-flixel-desktop-playground/source/PlayState.kiss | 6 +++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/projects/nat-archive-tool/src/nat/Archive.kiss b/projects/nat-archive-tool/src/nat/Archive.kiss index 509bcc6d..d97ce48a 100644 --- a/projects/nat-archive-tool/src/nat/Archive.kiss +++ b/projects/nat-archive-tool/src/nat/Archive.kiss @@ -44,8 +44,12 @@ (method processSystems [&opt :ArchiveUI 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 (let [e (_newEntry)] + (when defaultInitializer + (defaultInitializer e)) (initializer e) (dictSet entries e.id e) (refreshEntry e) diff --git a/projects/nat-archive-tool/src/nat/ArchiveController.kiss b/projects/nat-archive-tool/src/nat/ArchiveController.kiss index d200e61e..36eee16d 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveController.kiss +++ b/projects/nat-archive-tool/src/nat/ArchiveController.kiss @@ -241,12 +241,7 @@ (ui.displayMessage "Entry ${e.id} has no $componentType component"))) []) (defCommand CreateEntry [name (Text null)] - [(archive.createEntry ->e - { - (when (and playgroundSystem (playgroundSystem.currentDefaultTags)) - (addTags archive e (playgroundSystem.currentDefaultTags))) - (addComponent archive e Name name) - })]) + [(archive.createEntry ->e (addComponent archive e Name name))]) (defCommand CreateEntries [names (VarText null)] // createEntry returns a list, so these lists must be flattened diff --git a/projects/nat-archive-tool/src/nat/ArchiveUI.hx b/projects/nat-archive-tool/src/nat/ArchiveUI.hx index 9f9e69a4..58559cf7 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveUI.hx +++ b/projects/nat-archive-tool/src/nat/ArchiveUI.hx @@ -4,6 +4,8 @@ import nat.Entry; import nat.ArchiveController; import kiss_tools.KeyShortcutHandler; import nat.systems.PlaygroundSystem; +import haxe.ds.Option; +import nat.components.Position; interface ArchiveUI { /** @@ -63,4 +65,9 @@ interface ArchiveUI { * Update UI to show that the set of selected entries has changed */ function onSelectionChanged(selectedEntries:Array, lastSelectedEntries:Array):Void; + + /** + * A way to tell NAT where the cursor is + */ + function cursorPosition():Option; } diff --git a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx index d8b6f418..6ec25550 100644 --- a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx +++ b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.hx @@ -5,6 +5,7 @@ import kiss.List; import nat.System; import nat.components.*; 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 PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void diff --git a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss index 2b1b4741..7dc49d10 100644 --- a/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/PlaygroundSystem.kiss @@ -42,6 +42,14 @@ (method switchPlaygroundKey [key] (set _playgroundKey key) (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)) (method :Void clear [:Color color] diff --git a/projects/nat-flixel-desktop-playground/source/PlayState.hx b/projects/nat-flixel-desktop-playground/source/PlayState.hx index e9290586..b73dca33 100644 --- a/projects/nat-flixel-desktop-playground/source/PlayState.hx +++ b/projects/nat-flixel-desktop-playground/source/PlayState.hx @@ -25,6 +25,8 @@ import kiss_tools.FlxKeyShortcutHandler; import nat.systems.PlaygroundSystem; import flash.desktop.Clipboard; import flash.desktop.ClipboardFormats; +import haxe.ds.Option; +import nat.components.Position; @:build(kiss.Kiss.build()) class PlayState extends FlxState implements ArchiveUI {} diff --git a/projects/nat-flixel-desktop-playground/source/PlayState.kiss b/projects/nat-flixel-desktop-playground/source/PlayState.kiss index e8fe123e..37cc5791 100644 --- a/projects/nat-flixel-desktop-playground/source/PlayState.kiss +++ b/projects/nat-flixel-desktop-playground/source/PlayState.kiss @@ -330,4 +330,8 @@ (method :Void onSelectionChanged [:Array selectedEntries :Array lastSelectedEntries] (doFor e (selectedEntries.concat lastSelectedEntries) (whenLet [sprite (dictGet spriteSystem.sprites e.id)] - (sprite.updateColor)))) \ No newline at end of file + (sprite.updateColor)))) + +(method :Option cursorPosition [] + (let [pos (FlxG.mouse.getWorldPosition FlxG.camera)] + (Some (object x pos.x y pos.y z 0.0)))) \ No newline at end of file