name system tracks a map of entry names
This commit is contained in:
@@ -139,13 +139,18 @@
|
||||
|
||||
(var :Array<String> commandNames [])
|
||||
|
||||
|
||||
(defNew [&prop :Archive archive
|
||||
&prop :ArchiveUI ui]
|
||||
[&mut :Array<Entry> selectedEntries []
|
||||
&mut :ChangeSet lastChangeSet []
|
||||
:Map<String,Command> commands (new Map)]
|
||||
:Map<String,Command> commands (new Map)
|
||||
:NameSystem nameSystem (new NameSystem)]
|
||||
|
||||
(ui.setController this)
|
||||
|
||||
// Add systems!
|
||||
(archive.addSystem nameSystem)
|
||||
(archive.addSystem (new WikipediaImageSystem))
|
||||
(archive.processSystems)
|
||||
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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<Entry> matchingEntries)
|
||||
([e] (resolve e))
|
||||
([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve))
|
||||
|
8
projects/nat-archive-tool/src/nat/systems/NameSystem.hx
Normal file
8
projects/nat-archive-tool/src/nat/systems/NameSystem.hx
Normal file
@@ -0,0 +1,8 @@
|
||||
package nat.systems;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import nat.System;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class NameSystem extends System {}
|
17
projects/nat-archive-tool/src/nat/systems/NameSystem.kiss
Normal file
17
projects/nat-archive-tool/src/nat/systems/NameSystem.kiss
Normal file
@@ -0,0 +1,17 @@
|
||||
(load "../Lib.kiss")
|
||||
|
||||
(prop :Map<String,Array<Entry>> 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<Entry> getEntries [name]
|
||||
(or (dictGet entriesByName name) []))
|
Reference in New Issue
Block a user