diff --git a/src/nat/Archive.hx b/src/nat/Archive.hx index dcb2f96..f57946e 100644 --- a/src/nat/Archive.hx +++ b/src/nat/Archive.hx @@ -3,8 +3,8 @@ package nat; import sys.FileSystem; import kiss.Prelude; import sys.io.File; -import tink.Json; import uuid.Uuid; +import haxe.DynamicAccess; using haxe.io.Path; diff --git a/src/nat/Archive.kiss b/src/nat/Archive.kiss index 5c96b5d..f670576 100644 --- a/src/nat/Archive.kiss +++ b/src/nat/Archive.kiss @@ -12,10 +12,27 @@ (FileSystem.createDirectory entryDir) (FileSystem.createDirectory componentDir) (FileSystem.createDirectory filesDir) + (let [entryFiles (FileSystem.readDirectory entryDir)] (for file entryFiles =>(file.withoutExtension) - (the Entry (Json.parse (File.getContent (joinPath archiveDir "entries" file)))))))]) + (the Entry (tink.Json.parse (File.getContent (joinPath archiveDir "entries" file))))))) + :DynamicAccess playgrounds + (let [playgroundsFile (joinPath archiveDir "playgrounds.json")] + (unless (FileSystem.exists playgroundsFile) + (File.saveContent playgroundsFile +#"{ + "default": "Playground-MAIN", + "Playground-MAIN": { + "catsMatch": "true" + } +} +"#)) + (haxe.Json.parse (File.getContent playgroundsFile)))]) + +(method changePlaygrounds [:Dynamic->Void change] + (change playgrounds) + (File.saveContent (joinPath archiveDir "playgrounds.json") (haxe.Json.stringify playgrounds "\t"))) (method addSystem [:System system] // Assign entries to the Systems that care about them @@ -47,7 +64,7 @@ (method _saveEntry [:Entry e] (File.saveContent (joinPath archiveDir "entries" (e.id.withExtension "json")) - (Json.stringify e))) + (tink.Json.stringify e))) (method fullString [:Entry e] (haxe.Json.stringify e null "\t")) diff --git a/src/nat/ArchiveController.hx b/src/nat/ArchiveController.hx index a29be19..ab3d8cd 100644 --- a/src/nat/ArchiveController.hx +++ b/src/nat/ArchiveController.hx @@ -3,6 +3,7 @@ package nat; import kiss.Prelude; import kiss.List; import haxe.Constraints; +import haxe.DynamicAccess; import uuid.Uuid; import nat.systems.*; @@ -22,6 +23,8 @@ enum CommandArgType { Entries(min:Null, max:Null); // TODO Tag -- make sure a tag input is a valid haxe variable name for tagsMatch compatibility // TODO VarTag + + // TODO playground name -- choose from archive.playgrounds } typedef CommandArg = { diff --git a/src/nat/ArchiveController.kiss b/src/nat/ArchiveController.kiss index e7e945a..7b5782f 100644 --- a/src/nat/ArchiveController.kiss +++ b/src/nat/ArchiveController.kiss @@ -146,6 +146,8 @@ (method getSelectedEntries [] (_selectedEntries.copy)) +(prop &mut :PlaygroundSystem playgroundSystem null) + (defNew [&prop :Archive archive &prop :ArchiveUI ui] [&mut :Array _selectedEntries [] @@ -163,14 +165,14 @@ (archive.addSystem (new KeyShortcutSystem this)) (archive.addSystem (new DLSystem)) (whenLet [ps (ui.playgroundSystem)] + (set playgroundSystem ps) (archive.addSystem ps) - // TODO allow saving a different default playground - (ps.switchPlaygroundKey "Playground-MAIN")) + (ps.switchPlaygroundKey (dictGet archive.playgrounds "default"))) // Just for testing: // (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files)) - (archive.processSystems) + (archive.processSystems ui) (defCommand Help [] (ui.displayMessage @@ -261,4 +263,12 @@ (withWritableComponents archive e [scaleComponent Scale] (set scaleComponent scale)) (addComponent archive e Scale scale))) - entries)) + entries) + + (defCommand CreatePlayground [name (Text null) catsMatchExp (Text null)] + (archive.changePlaygrounds ->:Void [:DynamicAccess p] + (dictSet p name (object catsMatch catsMatchExp)))) + + (defCommand SwitchPlayground [name (Text null)] + (archive.changePlaygrounds ->:Void [:DynamicAccess p] (dictSet p "default" name)) + (when playgroundSystem (playgroundSystem.switchPlaygroundKey name)))) diff --git a/src/nat/Lib.kiss b/src/nat/Lib.kiss index 88ac372..e27f5ad 100644 --- a/src/nat/Lib.kiss +++ b/src/nat/Lib.kiss @@ -18,7 +18,7 @@ // Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes (defMacro readComponent [e componentType] `(let [componentData (dictGet (the Map .components ,e) ,(symbolName componentType))] - (log null (+ "reading " componentData " as " ,(symbolName componentType) " for " .id ,e)) + // (log null (+ "reading " componentData " as " ,(symbolName componentType) " for " .id ,e)) (the nat.components ,componentType // TODO add to the documentation a hint that macros should use fully qualified type paths so macro caller classes don't need to import everything (tink.Json.parse componentData)))) diff --git a/src/nat/System.kiss b/src/nat/System.kiss index 61c2d6c..d535b12 100644 --- a/src/nat/System.kiss +++ b/src/nat/System.kiss @@ -16,5 +16,3 @@ (when (entries.exists e.id) (entries.remove e.id) (when onRemoveEntry (onRemoveEntry archive e))))) - -// TODO systems may need access to an ArchiveController diff --git a/src/nat/systems/PlaygroundSystem.kiss b/src/nat/systems/PlaygroundSystem.kiss index ccf7f4f..34ef278 100644 --- a/src/nat/systems/PlaygroundSystem.kiss +++ b/src/nat/systems/PlaygroundSystem.kiss @@ -16,9 +16,10 @@ (addComponent archive e Positions (new Map))) (withWritableComponents archive e [positions Positions] (when !(positions.exists _playgroundKey) - // TODO do a playground check before giving a default position. - (dictSet positions _playgroundKey (defaultPosition e)))) - (let [pos (dictGet (readComponent e Positions) _playgroundKey)] + (if (catsMatch e .catsMatch (dictGet archive.playgrounds _playgroundKey)) + (dictSet positions _playgroundKey (defaultPosition e)) + (return null)))) + (whenLet [pos (dictGet (readComponent e Positions) _playgroundKey)] (processor archive e pos ui)) })) @@ -28,7 +29,7 @@ (set _playgroundKey key) (process ui.controller.archive ui)) -(method clear []) +(method :Void clear []) (method &override :Void process [:Archive archive &opt :ArchiveUI ui] (when _playgroundKey (super.process archive ui)))