diff options
author | iainp5 <iain.pearce.ip@gmail.com> | 2024-11-23 08:51:45 +0000 |
---|---|---|
committer | iainp5 <iain.pearce.ip@gmail.com> | 2024-11-23 08:51:45 +0000 |
commit | a35b49e654f2ad82c14855b3c36195c2c2e26d10 (patch) | |
tree | 0f56a45c62741907a2ac9dbbe315e025af2dcd7c /tools/genlayout.js | |
parent | dd4ef001caac00050d00f8ae1dfa87da9e95eb7c (diff) | |
parent | db464d9b4adb87cd4316f59058b6b70f61fbeaa3 (diff) | |
download | 1989-dawn-of-freedom-a35b49e654f2ad82c14855b3c36195c2c2e26d10.tar.gz |
Merge branch 'work-in-progress'
Diffstat (limited to 'tools/genlayout.js')
-rw-r--r-- | tools/genlayout.js | 37 |
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("}") |