Fix using deprecated forms in nat-archive-tool

This commit is contained in:
2021-07-25 21:10:34 -06:00
parent 872b4861f8
commit ed50d939fa
3 changed files with 24 additions and 22 deletions

View File

@@ -238,7 +238,7 @@
random Std.random random Std.random
int Std.int))) int Std.int)))
(defmacro withValueOrInputBox [v &body body] (defMacro withValueOrInputBox [v &body body]
`(if ,v `(if ,v
{,@body} {,@body}
(awaitLet [,v (inputBox)] (awaitLet [,v (inputBox)]

View File

@@ -107,7 +107,7 @@
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector))) (set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
(lastCollector))) (lastCollector)))
(defmacro defcommand [name args &body body] (defMacro defCommand [name args &body body]
(let [argPairs (let [argPairs
(groups (expList args) 2) (groups (expList args) 2)
methodArgs methodArgs
@@ -134,34 +134,34 @@
&mut :ChangeSet lastChangeSet [] &mut :ChangeSet lastChangeSet []
:Map<String,Command> commands (new Map)] :Map<String,Command> commands (new Map)]
(defcommand selectEntry [e OneEntry] (defCommand selectEntry [e OneEntry]
(set selectedEntries [e]) []) (set selectedEntries [e]) [])
(defcommand selectEntries [entries (Entries null null)] (defCommand selectEntries [entries (Entries null null)]
(set selectedEntries entries) []) (set selectedEntries entries) [])
(defcommand selectAllEntries [] (defCommand selectAllEntries []
(set selectedEntries (for =>id e archive.entries e)) []) (set selectedEntries (for =>id e archive.entries e)) [])
(defcommand selectLastChangeSet [] (defCommand selectLastChangeSet []
(set selectedEntries lastChangeSet) []) (set selectedEntries lastChangeSet) [])
(defcommand printSelectedEntries [entries (SelectedEntries null null)] (defCommand printSelectedEntries [entries (SelectedEntries null null)]
(doFor e entries (ui.displayMessage (archive.fullString e))) []) (doFor e entries (ui.displayMessage (archive.fullString e))) [])
(defcommand printComponent [entries (SelectedEntries null null) (defCommand printComponent [entries (SelectedEntries null null)
componentType (Text null)] componentType (Text null)]
(doFor e entries (ui.displayMessage (archive.componentData e componentType))) []) (doFor e entries (ui.displayMessage (archive.componentData e componentType))) [])
(defcommand createEntry [name (Text null)] (defCommand createEntry [name (Text null)]
[(archive.createEntry ->e [(archive.createEntry ->e
(addComponent archive e Name name))]) (addComponent archive e Name name))])
(defcommand createEntries [names (VarText null)] (defCommand createEntries [names (VarText null)]
(flatten (for name names (flatten (for name names
(createEntry name)))) (createEntry name))))
(defcommand addTags [entries (SelectedEntries 1 null) (defCommand addTags [entries (SelectedEntries 1 null)
tagsToAdd (VarText null)] tagsToAdd (VarText null)]
(doFor e entries (doFor e entries
(withWritableEntry archive e (withWritableEntry archive e
@@ -171,7 +171,7 @@
(addComponent archive e Tags (for tag tagsToAdd =>tag 1))))) (addComponent archive e Tags (for tag tagsToAdd =>tag 1)))))
entries) // TODO this includes entries that already had the tag in the changeset entries) // TODO this includes entries that already had the tag in the changeset
(defcommand removeTags [entries (SelectedEntries 1 null) (defCommand removeTags [entries (SelectedEntries 1 null)
tagsToRemove (VarText null)] tagsToRemove (VarText null)]
(doFor e entries (doFor e entries
(withWritableEntry archive e (withWritableEntry archive e
@@ -180,8 +180,8 @@
(doFor tag tagsToRemove (tags.remove tag)))))) (doFor tag tagsToRemove (tags.remove tag))))))
entries) // TODO this includes entries that didn't have the tag in the changeset entries) // TODO this includes entries that didn't have the tag in the changeset
(defcommand selectByTags [tagsBoolExp (Text null)] (defCommand selectByTags [tagsBoolExp (Text null)]
(selectEntries (filter archive.entries ->e (tagsMatch archive e tagsBoolExp)))) (selectEntries (filter archive.entries ->e (tagsMatch archive e tagsBoolExp))))
(defcommand selectByComponents [componentsBoolExp (Text null)] (defCommand selectByComponents [componentsBoolExp (Text null)]
(selectEntries (filter archive.entries ->e (componentsMatch e componentsBoolExp))))) (selectEntries (filter archive.entries ->e (componentsMatch e componentsBoolExp)))))

View File

@@ -1,14 +1,16 @@
// Lib is its own class because, while it would make sense to group its functions and macros in Archive.kiss, // Lib is its own class because, while it would make sense to group its functions and macros in Archive.kiss,
// other files would not be able to (load "Archive.kiss") for the macro definitions without taking on Archive's constructor. // other files would not be able to (load "Archive.kiss") for the macro definitions without taking on Archive's constructor.
(defmacro hasComponent [e componentType] // External programs can load Lib.kiss with (loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
(defMacro hasComponent [e componentType]
`(.exists .components ,e ,(symbolName componentType))) `(.exists .components ,e ,(symbolName componentType)))
(defmacro _componentPath [archive e componentType] (defMacro _componentPath [archive e componentType]
`(joinPath .archiveDir (the nat.Archive ,archive) "components" (+ (dictGet (the Map<String,String> .components ,e) ,(symbolName componentType)) ".json"))) `(joinPath .archiveDir (the nat.Archive ,archive) "components" (+ (dictGet (the Map<String,String> .components ,e) ,(symbolName componentType)) ".json")))
// Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes // Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes
(defmacro readComponent [archive e componentType] (defMacro readComponent [archive e 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 // 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
`(the nat.components ,componentType `(the nat.components ,componentType
(tink.Json.parse (tink.Json.parse
@@ -16,14 +18,14 @@
// Components have to be saved individually after writing because the Entity only knows their ids, // Components have to be saved individually after writing because the Entity only knows their ids,
// not the data they contain. This is more ergonomically done by using (withWritableComponents...) // not the data they contain. This is more ergonomically done by using (withWritableComponents...)
(defmacro writeComponent [archive e componentType c] (defMacro writeComponent [archive e componentType c]
`(sys.io.File.saveContent `(sys.io.File.saveContent
(_componentPath ,archive ,e ,componentType) (_componentPath ,archive ,e ,componentType)
(tink.Json.stringify (tink.Json.stringify
(the nat.components ,componentType ,c)))) (the nat.components ,componentType ,c))))
// TODO check not overwriting a component // TODO check not overwriting a component
(defmacro addComponent [archive e componentType c] (defMacro addComponent [archive e componentType c]
`(let [componentId (Uuid.v4)] `(let [componentId (Uuid.v4)]
(dictSet .components ,e ,(symbolName componentType) componentId) (dictSet .components ,e ,(symbolName componentType) componentId)
(writeComponent ,archive ,e ,componentType ,c) (writeComponent ,archive ,e ,componentType ,c)
@@ -31,7 +33,7 @@
// Retrieve multiple components from an Entity with mutable access. // Retrieve multiple components from an Entity with mutable access.
// All components will be serialized after the block is done. // All components will be serialized after the block is done.
(defmacro withWritableComponents [archive e bindings &body body] (defMacro withWritableComponents [archive e bindings &body body]
(let [bindingPairs (let [bindingPairs
(groups (expList bindings) 2 Throw) (groups (expList bindings) 2 Throw)
bindingList bindingList
@@ -49,7 +51,7 @@
,@saveList ,@saveList
,retValSymbol))) ,retValSymbol)))
(defmacro withWritableEntry [archive e &body body] (defMacro withWritableEntry [archive e &body body]
(let [retValSymbol (let [retValSymbol
(symbol)] (symbol)]
`(let [,retValSymbol {,@body}] `(let [,retValSymbol {,@body}]
@@ -57,7 +59,7 @@
,retValSymbol))) ,retValSymbol)))
// Create a system that selects Entries according to a single string component (i.e. Name or Author) matching the given value // Create a system that selects Entries according to a single string component (i.e. Name or Author) matching the given value
(defmacro stringComponentSystem [archive componentType value process] (defMacro stringComponentSystem [archive componentType value process]
`(new System `(new System
(lambda [archive :Entry e] (lambda [archive :Entry e]
?(and (hasComponent e ,componentType) ?(and (hasComponent e ,componentType)