From 7e7053e1322406d1bbd58c828a30c96b9fcdfcdd Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 27 Jun 2022 18:22:57 +0000 Subject: [PATCH] pass a UI to NAT entryProcessors --- projects/nat-archive-tool/src/nat/Archive.kiss | 4 ++-- projects/nat-archive-tool/src/nat/CLI.kiss | 2 +- projects/nat-archive-tool/src/nat/System.hx | 2 +- projects/nat-archive-tool/src/nat/System.kiss | 6 +++--- .../nat-archive-tool/src/nat/systems/AttachmentSystem.hx | 2 +- .../nat-archive-tool/src/nat/systems/AttachmentSystem.kiss | 4 ++-- .../src/nat/systems/ImageAttachmentSystem.kiss | 2 +- projects/nat-archive-tool/src/nat/systems/NameSystem.kiss | 2 +- .../src/nat/systems/RemarkableAPISystem.kiss | 2 +- .../src/nat/systems/WikipediaImageSystem.kiss | 6 ++++-- .../source/EntrySpriteSystem.kiss | 4 ++-- .../nat-flixel-desktop-playground/source/PlayState.kiss | 2 +- .../source/TextSpriteSystem.kiss | 2 +- 13 files changed, 21 insertions(+), 19 deletions(-) diff --git a/projects/nat-archive-tool/src/nat/Archive.kiss b/projects/nat-archive-tool/src/nat/Archive.kiss index 73a36cbe..5c96b5d3 100644 --- a/projects/nat-archive-tool/src/nat/Archive.kiss +++ b/projects/nat-archive-tool/src/nat/Archive.kiss @@ -24,8 +24,8 @@ (systems.push system) system) -(method processSystems [] - (doFor system systems (system.process this))) +(method processSystems [&opt :ArchiveUI ui] + (doFor system systems (system.process this ui))) (method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required (let [e (_newEntry)] diff --git a/projects/nat-archive-tool/src/nat/CLI.kiss b/projects/nat-archive-tool/src/nat/CLI.kiss index ed0f5997..16d21139 100644 --- a/projects/nat-archive-tool/src/nat/CLI.kiss +++ b/projects/nat-archive-tool/src/nat/CLI.kiss @@ -80,7 +80,7 @@ (method handleChanges [:Archive archive :ChangeSet changeSet] - (archive.processSystems) + (archive.processSystems this) (doFor e changeSet (print (archive.fullString e)))) diff --git a/projects/nat-archive-tool/src/nat/System.hx b/projects/nat-archive-tool/src/nat/System.hx index 4083cd6e..cf8bf4a9 100644 --- a/projects/nat-archive-tool/src/nat/System.hx +++ b/projects/nat-archive-tool/src/nat/System.hx @@ -3,7 +3,7 @@ package nat; import kiss.Prelude; typedef EntryChecker = (Archive, Entry) -> Bool; -typedef EntryProcessor = (Archive, Entry) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void +typedef EntryProcessor = (Archive, Entry, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void @:build(kiss.Kiss.build()) class System {} diff --git a/projects/nat-archive-tool/src/nat/System.kiss b/projects/nat-archive-tool/src/nat/System.kiss index c24db8e1..61c2d6cd 100644 --- a/projects/nat-archive-tool/src/nat/System.kiss +++ b/projects/nat-archive-tool/src/nat/System.kiss @@ -1,8 +1,8 @@ (prop :Map entries (new Map)) -(method :Void process [:Archive archive] +(method :Void process [:Archive archive &opt :ArchiveUI ui] (doFor e (entries.iterator) - (processEntry archive e))) + (processEntry archive e ui))) (defNew [&prop :EntryChecker canProcessEntry &prop :EntryProcessor processEntry] @@ -17,4 +17,4 @@ (entries.remove e.id) (when onRemoveEntry (onRemoveEntry archive e))))) -// TODO systems may need access to a UI or ArchiveController +// TODO systems may need access to an ArchiveController diff --git a/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.hx b/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.hx index 3d8e6ab9..868aec58 100644 --- a/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.hx +++ b/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.hx @@ -7,7 +7,7 @@ import haxe.Json; using haxe.io.Path; -typedef AttachmentProcessor = (Archive, Entry, Array) -> Dynamic; +typedef AttachmentProcessor = (Archive, Entry, Array, ?ArchiveUI) -> Dynamic; /** * Base System that processes Entries based on whether they have file attachments diff --git a/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.kiss b/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.kiss index 2fec3833..3a9abbdb 100644 --- a/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/AttachmentSystem.kiss @@ -12,5 +12,5 @@ (return true))) false } - ->[archive e] - (processor archive e (filter e.files ->file !(= -1 (extensions.indexOf (file.extension))))))) \ No newline at end of file + ->[archive e &opt ui] + (processor archive e (filter e.files ->file !(= -1 (extensions.indexOf (file.extension)))) ui))) \ No newline at end of file diff --git a/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss index 96cb4d2f..0a54c973 100644 --- a/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/ImageAttachmentSystem.kiss @@ -3,7 +3,7 @@ (defNew [] (super ["jpg" "jpeg" "png"] - ->[archive e imageFiles] + ->[archive e imageFiles &opt ui] (unless (hasComponent e Images) (addComponent archive e Images (object diff --git a/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss b/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss index e4d81b4b..8a1108e5 100644 --- a/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss @@ -6,7 +6,7 @@ (defNew [] (super ->[archive e] (hasComponent e Name) - ->[archive e] (let [name (readComponent e Name)] + ->[archive e &opt ui] (let [name (readComponent e Name)] (if (entriesByName.exists (name.toLowerCase)) (.push (dictGet entriesByName (name.toLowerCase)) e) (dictSet entriesByName (name.toLowerCase) [e])) diff --git a/projects/nat-archive-tool/src/nat/systems/RemarkableAPISystem.kiss b/projects/nat-archive-tool/src/nat/systems/RemarkableAPISystem.kiss index 197576d9..5afd101e 100644 --- a/projects/nat-archive-tool/src/nat/systems/RemarkableAPISystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/RemarkableAPISystem.kiss @@ -3,7 +3,7 @@ (defNew [] (super ->[archive e] false - ->[archive e] null) + ->[archive e &opt ui] null) ~(#extern String js (object diff --git a/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss b/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss index 19f7dac4..e732303e 100644 --- a/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss +++ b/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss @@ -8,7 +8,7 @@ 1)) // named method in case a user will want to run it on selectedEntries instead of on media entries -(method scrapeForImages [archive e] +(method scrapeForImages [archive e &opt ui] (let [:String title (readComponent e Name) :Array wikipediaImageUrls @@ -21,7 +21,9 @@ (.urlDecode (url.withoutDirectory)) // Some symbols shouldn't be decoded because they're invalid in file systems! "\"" "%22"))] - // TODO do this with ui.displayMessage + // TODO write a macro that either does both print and displayMessage if a ui is available + (when ui + (ui.displayMessage "Downloading $title image: $url")) (print url "downloading") (assertProcess "curl" ["--output" filePath url]) filePath))) diff --git a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss index 16ef740d..3993e4ea 100644 --- a/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss +++ b/projects/nat-flixel-desktop-playground/source/EntrySpriteSystem.kiss @@ -9,7 +9,7 @@ (super ->[archive e] ?(and (tagsMatch archive e tagFilterString) (hasComponent e Images)) - ->[archive e] + ->[archive e &opt ui] (unless (sprites.exists e.id) (when !(hasComponent e Positions) (addComponent archive e Positions (new Map))) @@ -21,7 +21,7 @@ (dictSet sprites e.id sprite)))) (set onRemoveEntry - ->[archive e] + ->[archive e &opt ui] { (.kill (dictGet sprites e.id)) (sprites.remove e.id) diff --git a/projects/nat-flixel-desktop-playground/source/PlayState.kiss b/projects/nat-flixel-desktop-playground/source/PlayState.kiss index 9b24def3..b45e804a 100644 --- a/projects/nat-flixel-desktop-playground/source/PlayState.kiss +++ b/projects/nat-flixel-desktop-playground/source/PlayState.kiss @@ -94,7 +94,7 @@ (prop &mut :EntrySpriteSystem spriteSystem) (set spriteSystem (new EntrySpriteSystem "!done" "Playground-MAIN" this controller)) (archive.addSystem spriteSystem) - (archive.processSystems)) + (archive.processSystems this)) (method &override :Void update [:Float elapsed] (super.update elapsed) diff --git a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss b/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss index 427464ae..912aaa8b 100644 --- a/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss +++ b/projects/nat-flixel-desktop-playground/source/TextSpriteSystem.kiss @@ -6,7 +6,7 @@ (super ->[archive e] ?(and !(hasComponent e Images) (hasComponent e Name)) - ->[archive e] + ->[archive e &opt ui] { (let [name (readComponent e Name) sprite (new FlxText 0 0 0 name 16)