summaryrefslogtreecommitdiff
path: root/tools/genlayout.js
diff options
context:
space:
mode:
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("}")