diff --git a/projects/nap/build.hxml b/projects/nap/build.hxml index d9040f8b..dcfc5b21 100644 --- a/projects/nap/build.hxml +++ b/projects/nap/build.hxml @@ -1,6 +1,7 @@ -lib uuid -lib kiss -lib hscript +-lib tink_json -cp src --main nap.Main --interp \ No newline at end of file diff --git a/projects/nap/example-archive/song1.json b/projects/nap/example-archive/song1.json index 668541b7..b193e724 100644 --- a/projects/nap/example-archive/song1.json +++ b/projects/nap/example-archive/song1.json @@ -1 +1 @@ -{"name":"Villain Alcohol","id":"song1","components":{"Tag":["song"]}} \ No newline at end of file +{"name":"Villain Alcohol","id":"song1","components":[["Tag", ["song"]]]} \ No newline at end of file diff --git a/projects/nap/haxelib.json b/projects/nap/haxelib.json index 9732332c..84d7c7c5 100644 --- a/projects/nap/haxelib.json +++ b/projects/nap/haxelib.json @@ -10,6 +10,7 @@ "classPath": "src/", "main": "nap.Main", "dependencies": { - "kiss": "" + "kiss": "", + "tink_json": "" } } \ No newline at end of file diff --git a/projects/nap/src/nap/Archive.hx b/projects/nap/src/nap/Archive.hx index 80a2bf8a..280b825d 100644 --- a/projects/nap/src/nap/Archive.hx +++ b/projects/nap/src/nap/Archive.hx @@ -3,7 +3,8 @@ package nap; import kiss.Prelude; import sys.FileSystem; import sys.io.File; -import haxe.Json; +import tink.Json; +import nap.systems.TagSystem; using haxe.io.Path; diff --git a/projects/nap/src/nap/Archive.kiss b/projects/nap/src/nap/Archive.kiss index 5dcf7df9..54328a2e 100644 --- a/projects/nap/src/nap/Archive.kiss +++ b/projects/nap/src/nap/Archive.kiss @@ -1,10 +1,13 @@ (defnew [archiveDir] [:Map entries (let [entryFiles (FileSystem.readDirectory archiveDir)] - (for file entryFiles =>(file.withoutExtension) ~(Json.parse (File.getContent (Path.join [archiveDir file]))))) - :Array systems []] // TODO also create systems - // TODO register entities to systems that want them - ) + (for file entryFiles =>(file.withoutExtension) ~(the Entry (Json.parse (File.getContent (Path.join [archiveDir file])))))) + :Array systems [ + (the System (new TagSystem "song"))]] + (doFor system systems + (doFor =>id entry entries + (when (system.canProcessEntry entry) + (system.entries.push entry))))) (defmethod :Void handleEvent [:Event e] (throw "can't handle $e")) diff --git a/projects/nap/src/nap/Entry.hx b/projects/nap/src/nap/Entry.hx index 5eaa9782..0b07e28f 100644 --- a/projects/nap/src/nap/Entry.hx +++ b/projects/nap/src/nap/Entry.hx @@ -1,8 +1,7 @@ package nap; -import kiss.Kiss; -import kiss.Prelude; -import uuid.Uuid; - -@:build(kiss.Kiss.build()) -class Entry {} +typedef Entry = { + id:String, + name:String, + components:Map> +}; diff --git a/projects/nap/src/nap/Entry.kiss b/projects/nap/src/nap/Entry.kiss deleted file mode 100644 index 9c496501..00000000 --- a/projects/nap/src/nap/Entry.kiss +++ /dev/null @@ -1,3 +0,0 @@ -(defnew [&prop :String name] - [:String id (Uuid.v4) - :Map> components (new Map)]) \ No newline at end of file diff --git a/projects/nap/src/nap/Lib.hx b/projects/nap/src/nap/Lib.hx index 6207ac58..b9b31adf 100644 --- a/projects/nap/src/nap/Lib.hx +++ b/projects/nap/src/nap/Lib.hx @@ -1,5 +1,6 @@ package nap; +import uuid.Uuid; import kiss.Prelude; import kiss.Stream; import hscript.Parser; diff --git a/projects/nap/src/nap/Lib.kiss b/projects/nap/src/nap/Lib.kiss index 9bbb8263..cdd15e64 100644 --- a/projects/nap/src/nap/Lib.kiss +++ b/projects/nap/src/nap/Lib.kiss @@ -6,4 +6,10 @@ (new BoolExpInterp)] (doFor condition activeConditions (interp.variables.set condition true)) - ?(interp.execute hscriptExp))) \ No newline at end of file + ?(interp.execute hscriptExp))) + +(defun :Entry newEntry [:String name] + (object + id (Uuid.v4) + name name + components (new Map))) \ No newline at end of file diff --git a/projects/nap/src/nap/components/Tag.kiss b/projects/nap/src/nap/components/Tag.kiss index e69de29b..493cdc44 100644 --- a/projects/nap/src/nap/components/Tag.kiss +++ b/projects/nap/src/nap/components/Tag.kiss @@ -0,0 +1,2 @@ +(defun :Array getTags [:Entry e] + (or (dictGet e.components "Tag") [])) \ No newline at end of file diff --git a/projects/nap/src/nap/systems/TagSystem.kiss b/projects/nap/src/nap/systems/TagSystem.kiss index 74bf77ee..227760a7 100644 --- a/projects/nap/src/nap/systems/TagSystem.kiss +++ b/projects/nap/src/nap/systems/TagSystem.kiss @@ -1,4 +1,6 @@ -(defnew [&prop :String tagFilterString]) +(load "../components/Tag.kiss") + +(defnew [&prop :String tagFilterString] []) (defmethod &override :Bool canProcessEntry [:Entry e] - ) \ No newline at end of file + (Lib.evalBoolExp tagFilterString (getTags e))) \ No newline at end of file