summaryrefslogtreecommitdiff
path: root/tools/genlayout.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-10-26 09:47:03 +0100
committeriainp5 <iain.pearce.ip@gmail.com>2024-10-26 09:47:03 +0100
commit1bfe93eea7faffbe59af0b5c2c0f6aa6889527e4 (patch)
tree398f95e119baae26d2f6fd4acc10af96daa6625d /tools/genlayout.js
parenta651d28999accf0c18476b322a47ea5ebf031aef (diff)
parent99a6ff8112bbc47d6c2825c36328aa40c5c99384 (diff)
download1989-dawn-of-freedom-1bfe93eea7faffbe59af0b5c2c0f6aa6889527e4.tar.gz
Merge branch 'work-in-progress' of https://github.com/iainp5/1989-Dawn-of-Freedom into work-in-progress
Diffstat (limited to 'tools/genlayout.js')
-rw-r--r--tools/genlayout.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/genlayout.js b/tools/genlayout.js
new file mode 100644
index 0000000..37f419d
--- /dev/null
+++ b/tools/genlayout.js
@@ -0,0 +1,37 @@
+const fs = require("fs")
+
+let boxes = []
+let mode, name, x, y, w, h
+
+function flush() {
+ if (mode === 'rect') {
+ boxes[name] = [ x |0, y |0, w |0, h |0 ]
+ }
+ x = y = w = h = 0
+ name = null
+}
+
+for (let line of fs.readFileSync("tools/layout.svg", "utf-8").split("\n")) {
+ line = line.trim()
+ if (line.startsWith("<rect")) {
+ flush()
+ mode = "rect"
+ x = y = w = h = 0
+ } else if (line.startsWith('x="'))
+ x = Math.round(Number(line.split('"')[1]))
+ else if (line.startsWith('y="'))
+ y = Math.round(Number(line.split('"')[1]))
+ else if (line.startsWith('width="'))
+ w = Math.round(Number(line.split('"')[1]))
+ else if (line.startsWith('height="'))
+ h = Math.round(Number(line.split('"')[1]))
+ else if (line.startsWith('inkscape:label="'))
+ name = line.split('"')[1]
+}
+
+flush()
+
+console.log("var LAYOUT = {")
+for (let key of Object.keys(boxes).sort())
+ console.log("\t\"" + key + "\": " + JSON.stringify(boxes[key]) + ",")
+console.log("}")