summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-04 20:01:28 +0100
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-04 20:01:28 +0100
commite88ed8866fab097c589f76fba4254357f8825e6f (patch)
treeeda8d8d3c395ebad9530d4ddfa96742386a3efd2 /tools
parented5ec82f487a5a12b018f747840efd0c573fedea (diff)
downloadvotes-for-women-e88ed8866fab097c589f76fba4254357f8825e6f.tar.gz
card and code tools
Diffstat (limited to 'tools')
-rw-r--r--tools/gencards.py1
-rw-r--r--tools/gencode.js63
2 files changed, 64 insertions, 0 deletions
diff --git a/tools/gencards.py b/tools/gencards.py
index 1d22e87..d4461ff 100644
--- a/tools/gencards.py
+++ b/tools/gencards.py
@@ -70,3 +70,4 @@ if __name__ == "__main__":
read_cards("states")
print("const CARDS = " + json.dumps(cards))
+ print("if (typeof module !== 'undefined') module.exports = {CARDS}")
diff --git a/tools/gencode.js b/tools/gencode.js
new file mode 100644
index 0000000..e2522e7
--- /dev/null
+++ b/tools/gencode.js
@@ -0,0 +1,63 @@
+"use strict"
+
+let fs = require("fs")
+
+let pc = 0
+
+function emit(line) {
+ ++pc
+ line[0] = "vm_" + line[0]
+ for (let i = 1; i < line.length; ++i) {
+ if (typeof line[i] === "string") {
+ if (line[i] === "all")
+ line[i] = 999
+ if (line[i][0] === "(" && !line[i].match(/\)=>/))
+ line[i] = "()=>" + line[i]
+ if (line[i][0] === "`")
+ line[i] = "()=>" + line[i]
+ }
+ }
+ console.log("\t[ " + line.join(", ") + " ],")
+}
+
+console.log("// #region GENERATED EVENT CODE")
+console.log("const CODE = []")
+let first = false
+
+for (let line of fs.readFileSync("events.txt", "utf-8").split("\n")) {
+ line = line.trim()
+ if (line.length === 0 || line[0] === "#")
+ continue
+ if (line === "EOF")
+ break
+ line = line.split(" ")
+ switch (line[0]) {
+ case "CARD":
+ if (first++) {
+ emit(["return"])
+ console.log("]")
+ }
+ console.log("")
+ console.log("CODE[" + line[1] + "] = [ // " + line.slice(3).join(" "))
+ break
+
+ case "log":
+ case "prompt":
+ emit([ line[0], line.slice(1).join(" ") ])
+ break
+
+ case "asm":
+ case "if":
+ case "while":
+ emit([ line[0], "()=>" + line.slice(1).join(" ") ])
+ break
+
+ default:
+ emit(line)
+ break
+ }
+}
+
+emit(["return"])
+console.log("]")
+console.log("// #endregion")