no more templates in the archive tool
This commit is contained in:
@@ -7,23 +7,31 @@
|
||||
(defmacro _componentPath [archive e componentType]
|
||||
`(haxe.io.Path.join [.archiveDir (the nat.Archive ,archive) "components" (+ (dictGet (the Map<String,String> .components ,e) ,(symbolName componentType)) ".json")]))
|
||||
|
||||
(defmacro getComponent [archive e componentType]
|
||||
// Changes to the object returned by (readComponent) will not be saved! Use (withWritableComponents) for making changes
|
||||
(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
|
||||
`(the nat.components ,componentType
|
||||
(tink.Json.parse
|
||||
(sys.io.File.getContent (_componentPath ,archive ,e ,componentType)))))
|
||||
|
||||
// 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 (withComponents...)
|
||||
(defmacro saveComponent [archive e componentType c]
|
||||
// not the data they contain. This is more ergonomically done by using (withWritableComponents...)
|
||||
(defmacro writeComponent [archive e componentType c]
|
||||
`(sys.io.File.saveContent
|
||||
(_componentPath ,archive ,e ,componentType)
|
||||
(tink.Json.stringify
|
||||
(the nat.components ,componentType ,c))))
|
||||
|
||||
// TODO check not overwriting a component
|
||||
(defmacro addComponent [archive e componentType c]
|
||||
`(let [componentId (Uuid.v4)]
|
||||
(dictSet .components ,e ,(symbolName componentType) componentId)
|
||||
(writeComponent ,archive ,e ,componentType ,c)
|
||||
,e))
|
||||
|
||||
// Retrieve multiple components from an Entity with mutable access.
|
||||
// All components will be serialized after the block is done.
|
||||
(defmacro withComponents [archive e bindings &rest body]
|
||||
(defmacro withWritableComponents [archive e bindings &rest body]
|
||||
(let [bindingPairs
|
||||
(groups (expList bindings) 2 Throw)
|
||||
bindingList
|
||||
@@ -34,16 +42,31 @@
|
||||
(symbol)]
|
||||
(doFor [name type] bindingPairs
|
||||
(bindingList.push `&mut ,name)
|
||||
(bindingList.push `(getComponent ,archive ,e ,type))
|
||||
(saveList.push `(saveComponent ,archive ,e ,type ,name)))
|
||||
(bindingList.push `(readComponent ,archive ,e ,type))
|
||||
(saveList.push `(writeComponent ,archive ,e ,type ,name)))
|
||||
`(let [,@bindingList
|
||||
,retValSymbol {,@body}]
|
||||
,@saveList
|
||||
,retValSymbol)))
|
||||
|
||||
(defmacro withWritableEntry [archive e &rest body]
|
||||
(let [retValSymbol
|
||||
(symbol)]
|
||||
`(let [,retValSymbol {,@body}]
|
||||
(archive.refreshEntry ,e)
|
||||
,retValSymbol)))
|
||||
|
||||
// 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]
|
||||
`(new System
|
||||
(lambda [archive :Entry e]
|
||||
?(and (hasComponent e ,componentType)
|
||||
(= ,value (readComponent ,archive e ,componentType))))
|
||||
,process))
|
||||
|
||||
(defun tagList [archive e]
|
||||
(let [t
|
||||
(getComponent archive e Tags)]
|
||||
(readComponent archive e Tags)]
|
||||
(collect (t.keys))))
|
||||
|
||||
(defun tagsMatch [archive e tagsBoolExp]
|
||||
|
||||
Reference in New Issue
Block a user