NAT flixel playground multiple playground views

This commit is contained in:
2022-07-02 23:10:47 +00:00
parent bcd1eca9a0
commit d17ebf9a1d
16 changed files with 104 additions and 92 deletions

View File

@@ -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;

View File

@@ -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<Dynamic> 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"))

View File

@@ -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<Int>, max:Null<Int>);
// 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 = {

View File

@@ -146,6 +146,8 @@
(method getSelectedEntries []
(_selectedEntries.copy))
(prop &mut :PlaygroundSystem playgroundSystem null)
(defNew [&prop :Archive archive
&prop :ArchiveUI ui]
[&mut :Array<Entry> _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<Dynamic> p]
(dictSet p name (object catsMatch catsMatchExp))))
(defCommand SwitchPlayground [name (Text null)]
(archive.changePlaygrounds ->:Void [:DynamicAccess<Dynamic> p] (dictSet p "default" name))
(when playgroundSystem (playgroundSystem.switchPlaygroundKey name))))

View File

@@ -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<String,String> .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))))

View File

@@ -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

View File

@@ -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)))