Completely change naming conventions of field forms and definition macros. Close #32

This commit is contained in:
2021-07-24 14:22:10 -06:00
parent e8811a8798
commit 3e4ff5902f
7 changed files with 36 additions and 36 deletions

View File

@@ -10,14 +10,14 @@
(let [entryFiles (FileSystem.readDirectory entryDir)] (let [entryFiles (FileSystem.readDirectory entryDir)]
(for file entryFiles =>(file.withoutExtension) (the Entry (Json.parse (File.getContent (joinPath archiveDir "entries" file)))))))]) (for file entryFiles =>(file.withoutExtension) (the Entry (Json.parse (File.getContent (joinPath archiveDir "entries" file)))))))])
(defmethod addSystem [:System system] (method addSystem [:System system]
// Assign entries to the Systems that care about them // Assign entries to the Systems that care about them
(doFor =>id entry entries (doFor =>id entry entries
(system.checkEntryInOrOut this entry)) (system.checkEntryInOrOut this entry))
(systems.push system) (systems.push system)
system) system)
(defmethod :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required (method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
(let [e (_newEntry)] (let [e (_newEntry)]
(initializer e) (initializer e)
(dictSet entries e.id e) (dictSet entries e.id e)
@@ -26,20 +26,20 @@
// After modifying an entry, this must be called. If you are writing in a createEntry initializer or a system's processEntry function, this will happen automatically. // After modifying an entry, this must be called. If you are writing in a createEntry initializer or a system's processEntry function, this will happen automatically.
// Otherwise, you can guarantee it happens automatically by using the (withWritableEntry) macro in Lib.kiss // Otherwise, you can guarantee it happens automatically by using the (withWritableEntry) macro in Lib.kiss
(defmethod refreshEntry [:Entry e] (method refreshEntry [:Entry e]
(_saveEntry e) (_saveEntry e)
(doFor system systems (doFor system systems
(system.checkEntryInOrOut this e))) (system.checkEntryInOrOut this e)))
(defmethod _saveEntry [:Entry e] (method _saveEntry [:Entry e]
(File.saveContent (File.saveContent
(joinPath archiveDir "entries" (e.id.withExtension "json")) (joinPath archiveDir "entries" (e.id.withExtension "json"))
(Json.stringify e))) (Json.stringify e)))
(defmethod componentData [:Entry e :String componentType] (method componentData [:Entry e :String componentType]
(haxe.Json.parse (File.getContent (joinPath archiveDir "components" "$(dictGet e.components componentType).json")))) (haxe.Json.parse (File.getContent (joinPath archiveDir "components" "$(dictGet e.components componentType).json"))))
(defmethod fullData [:Entry e] (method fullData [:Entry e]
(object (object
id e.id id e.id
components components
@@ -48,10 +48,10 @@
files files
e.files)) e.files))
(defmethod fullString [:Entry e] (method fullString [:Entry e]
(haxe.Json.stringify (fullData e) null "\t")) (haxe.Json.stringify (fullData e) null "\t"))
(defun :Entry _newEntry [] (function :Entry _newEntry []
(object (object
id (Uuid.v4) id (Uuid.v4)
components (new Map) components (new Map)

View File

@@ -1,6 +1,6 @@
(load "Lib.kiss") (load "Lib.kiss")
(defmethod :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation] (method :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
(case arg.type (case arg.type
(SelectedEntry (SelectedEntry
(if (= 1 selectedEntries.length) (if (= 1 selectedEntries.length)
@@ -91,11 +91,11 @@
min min
max)))) max))))
(defmethod :Void->Void _composeArgCollector [:Array<Dynamic> collectedArgs :CommandArg arg :Void->Void lastCollector] (method :Void->Void _composeArgCollector [:Array<Dynamic> collectedArgs :CommandArg arg :Void->Void lastCollector]
(lambda :Void [] (lambda :Void []
(_collectAndValidateArg arg ->:Void [:Dynamic argValue] {(collectedArgs.push argValue) (lastCollector)}))) (_collectAndValidateArg arg ->:Void [:Dynamic argValue] {(collectedArgs.push argValue) (lastCollector)})))
(defmethod :Void runCommand [:Command command] (method :Void runCommand [:Command command]
(let [collectedArgs (let [collectedArgs
[] []
&mut lastCollector &mut lastCollector
@@ -125,7 +125,7 @@
(for [name type] argPairs (for [name type] argPairs
`(object name ,(symbolName name) type ,type))] `(object name ,(symbolName name) type ,type))]
`{ `{
(defmethod ,name [,@methodArgs] ,@body) (method ,name [,@methodArgs] ,@body)
(dictSet commands ,(symbolName name) (object args [,@commandArgs] handler (the Function ,name)))})) (dictSet commands ,(symbolName name) (object args [,@commandArgs] handler (the Function ,name)))}))
(defnew [&prop :Archive archive (defnew [&prop :Archive archive

View File

@@ -1,4 +1,4 @@
(defun eval [:String expStr :Array<String> activeConditions] (function eval [:String expStr :Array<String> activeConditions]
(let [hscriptExp (let [hscriptExp
(.parseString (new Parser) (.parseString (new Parser)
(Prelude.convertToHScript expStr)) (Prelude.convertToHScript expStr))

View File

@@ -1,6 +1,6 @@
(load "Lib.kiss") (load "Lib.kiss")
(defun :Void main [] (function :Void main []
(let [[archiveDir] (Sys.args) (let [[archiveDir] (Sys.args)
controller controller
(new ArchiveController (new ArchiveController
@@ -16,7 +16,7 @@
(defnew []) (defnew [])
(defmethod :Void enterText [prompt resolve maxLength] (method :Void enterText [prompt resolve maxLength]
(Sys.print "$prompt ") (Sys.print "$prompt ")
(loop (loop
(let [entered (.toString (.readLine (Sys.stdin)))] (let [entered (.toString (.readLine (Sys.stdin)))]
@@ -25,7 +25,7 @@
{(resolve entered) {(resolve entered)
(break)})))) (break)}))))
(defmethod :Void enterNumber [prompt resolve min max &opt inStepsOf] (method :Void enterNumber [prompt resolve min max &opt inStepsOf]
(Sys.print "$prompt ") (Sys.print "$prompt ")
(loop (loop
(let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))] (let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))]
@@ -37,10 +37,10 @@
{(resolve entered) {(resolve entered)
(break)})))) (break)}))))
(defmethod :Void chooseEntry [prompt :Archive archive resolve] (method :Void chooseEntry [prompt :Archive archive resolve]
(_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve))) (_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve)))
(defmethod :Void _chooseEntry [prompt :Archive archive resolve onEmptyString] (method :Void _chooseEntry [prompt :Archive archive resolve onEmptyString]
// TODO allow narrowing down with a tag string // TODO allow narrowing down with a tag string
(enterText "entry name for $prompt" (enterText "entry name for $prompt"
->name { ->name {
@@ -59,10 +59,10 @@
(multipleEntries (throw "ambiguous between multiple entries")))))} (multipleEntries (throw "ambiguous between multiple entries")))))}
Math.POSITIVE_INFINITY)) Math.POSITIVE_INFINITY))
(defmethod :Void chooseEntries [prompt archive resolve min max] (method :Void chooseEntries [prompt archive resolve min max]
(_chooseEntries prompt archive resolve min max [])) (_chooseEntries prompt archive resolve min max []))
(defmethod :Void _chooseEntries [prompt archive resolve min max :Array<Entry> collectedEntries] (method :Void _chooseEntries [prompt archive resolve min max :Array<Entry> collectedEntries]
(let [onEmptyString (let [onEmptyString
->(if (<= min collectedEntries.length) ->(if (<= min collectedEntries.length)
(resolve collectedEntries) (resolve collectedEntries)
@@ -84,12 +84,12 @@
(_chooseNextEntry))) (_chooseNextEntry)))
(defmethod handleChanges [:Archive archive :ChangeSet changeSet] (method handleChanges [:Archive archive :ChangeSet changeSet]
(doFor e changeSet (doFor e changeSet
(print (archive.fullString e)))) (print (archive.fullString e))))
(defmethod :Void displayMessage [message] (method :Void displayMessage [message]
(print message)) (print message))
(defmethod :Void reportError [error] (method :Void reportError [error]
(print error)) (print error))

View File

@@ -64,13 +64,13 @@
(= ,value (readComponent ,archive e ,componentType)))) (= ,value (readComponent ,archive e ,componentType))))
,process)) ,process))
(defun tagList [archive e] (function tagList [archive e]
(let [t (let [t
(readComponent archive e Tags)] (readComponent archive e Tags)]
(collect (t.keys)))) (collect (t.keys))))
(defun tagsMatch [archive e tagsBoolExp] (function tagsMatch [archive e tagsBoolExp]
(BoolExpInterp.eval tagsBoolExp (tagList archive e))) (BoolExpInterp.eval tagsBoolExp (tagList archive e)))
(defun componentsMatch [:nat.Entry e componentsBoolExp] (function componentsMatch [:nat.Entry e componentsBoolExp]
(BoolExpInterp.eval componentsBoolExp (for =>cType cId e.components cType))) (BoolExpInterp.eval componentsBoolExp (for =>cType cId e.components cType)))

View File

@@ -1,6 +1,6 @@
(defprop :Map<String,Entry> entries (new Map)) (prop :Map<String,Entry> entries (new Map))
(defmethod :Void process [:Archive archive] (method :Void process [:Archive archive]
(doFor e (entries.iterator) (doFor e (entries.iterator)
(processEntry archive e) (processEntry archive e)
(archive.refreshEntry e))) (archive.refreshEntry e)))
@@ -9,7 +9,7 @@
&prop :EntryProcessor processEntry] &prop :EntryProcessor processEntry]
[]) [])
(defmethod :Void checkEntryInOrOut [:Archive archive :Entry e] (method :Void checkEntryInOrOut [:Archive archive :Entry e]
(if (canProcessEntry archive e) (if (canProcessEntry archive e)
(dictSet entries e.id e) (dictSet entries e.id e)
(entries.remove e.id))) (entries.remove e.id)))

View File

@@ -4,7 +4,7 @@
(load "../nat/Lib.kiss") (load "../nat/Lib.kiss")
(defun :Void main [] (function :Void main []
(assert (BoolExpInterp.eval "true" [])) (assert (BoolExpInterp.eval "true" []))
(assert !(BoolExpInterp.eval "false" [])) (assert !(BoolExpInterp.eval "false" []))
(assert !(BoolExpInterp.eval "flag" [])) (assert !(BoolExpInterp.eval "flag" []))