diff --git a/projects/nat-archive-tool/src/nat/ArchiveController.kiss b/projects/nat-archive-tool/src/nat/ArchiveController.kiss index 7f0bcebb..f357a196 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveController.kiss +++ b/projects/nat-archive-tool/src/nat/ArchiveController.kiss @@ -139,13 +139,18 @@ (var :Array commandNames []) + (defNew [&prop :Archive archive &prop :ArchiveUI ui] [&mut :Array selectedEntries [] &mut :ChangeSet lastChangeSet [] - :Map commands (new Map)] + :Map commands (new Map) + :NameSystem nameSystem (new NameSystem)] + + (ui.setController this) // Add systems! + (archive.addSystem nameSystem) (archive.addSystem (new WikipediaImageSystem)) (archive.processSystems) diff --git a/projects/nat-archive-tool/src/nat/ArchiveUI.hx b/projects/nat-archive-tool/src/nat/ArchiveUI.hx index 3b15248e..0d1eb4cf 100644 --- a/projects/nat-archive-tool/src/nat/ArchiveUI.hx +++ b/projects/nat-archive-tool/src/nat/ArchiveUI.hx @@ -3,6 +3,11 @@ package nat; import nat.ArchiveController; interface ArchiveUI { + /** + * Accept and store a reference to the controller + */ + function setController(controller:ArchiveController):Void; + /** * Prompt the user to enter text */ diff --git a/projects/nat-archive-tool/src/nat/CLI.kiss b/projects/nat-archive-tool/src/nat/CLI.kiss index 51ceeb07..4d08aed5 100644 --- a/projects/nat-archive-tool/src/nat/CLI.kiss +++ b/projects/nat-archive-tool/src/nat/CLI.kiss @@ -12,6 +12,10 @@ (.trim (.toString (.readLine (Sys.stdin))))] (controller.tryRunCommand command)))) +(prop &mut :ArchiveController controller) + +(method :Void setController [controller] (set this.controller controller)) + (defNew []) (method :Void enterText [prompt resolve maxLength] @@ -44,12 +48,7 @@ ->name { (if !name (onEmptyString) - (let [matchingEntries []] - (.process (archive.addSystem - (stringComponentSystem archive Name name - (lambda [archive e] - (matchingEntries.push e)))) archive) - + (let [matchingEntries (controller.nameSystem.getEntries name)] (case (the Array matchingEntries) ([e] (resolve e)) ([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve)) diff --git a/projects/nat-archive-tool/src/nat/systems/NameSystem.hx b/projects/nat-archive-tool/src/nat/systems/NameSystem.hx new file mode 100644 index 00000000..73694e5b --- /dev/null +++ b/projects/nat-archive-tool/src/nat/systems/NameSystem.hx @@ -0,0 +1,8 @@ +package nat.systems; + +import kiss.Prelude; +import kiss.List; +import nat.System; + +@:build(kiss.Kiss.build()) +class NameSystem extends System {} diff --git a/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss b/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss new file mode 100644 index 00000000..05cde848 --- /dev/null +++ b/projects/nat-archive-tool/src/nat/systems/NameSystem.kiss @@ -0,0 +1,17 @@ +(load "../Lib.kiss") + +(prop :Map> entriesByName (new Map)) + +// Stores a map of named entries, for instant lookup by name +(defNew [] + (super + ->[archive e] (hasComponent e Name) + ->[archive e] (let [name (readComponent archive e Name)] + (if (entriesByName.exists name) + (.push (dictGet entriesByName name) e) + (dictSet entriesByName name [e])) + // Because the if statement doesn't unify by type :( + null))) + +(method :Array getEntries [name] + (or (dictGet entriesByName name) [])) \ No newline at end of file