diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-11-12 14:34:56 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-11-12 17:39:46 +0100 |
commit | 0cee28075504d3354e5c327200d472c760452b94 (patch) | |
tree | d4c87746e5365e553ded624bd4c7500f0607372a /tools/genborders.js | |
parent | 9323f62100b1f74ac5361b86cc53655adaee9572 (diff) | |
download | richard-iii-0cee28075504d3354e5c327200d472c760452b94.tar.gz |
Show border limits.
Diffstat (limited to 'tools/genborders.js')
-rw-r--r-- | tools/genborders.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/genborders.js b/tools/genborders.js new file mode 100644 index 0000000..f639e8a --- /dev/null +++ b/tools/genborders.js @@ -0,0 +1,53 @@ +const fs = require("fs") + +const { round, floor, ceil } = Math + +let output = {} +let mode, name, x, y, w, h, cx, cy, rx, ry + +function flush() { + if (mode === 'circle') { + output[name] = [ cx, cy ] + } + x = y = w = h = cx = cy = rx = ry = 0 + name = null +} + +for (let line of fs.readFileSync("tools/borders.svg", "utf-8").split("\n")) { + line = line.trim() + if (line.startsWith("<rect")) { + flush() + mode = "rect" + x = y = w = h = 0 + } else if (line.startsWith("<ellipse") || line.startsWith("<circle")) { + flush() + mode = "circle" + cx = cy = rx = ry = 0 + } else if (line.startsWith('x="')) + x = round(Number(line.split('"')[1])) + else if (line.startsWith('y="')) + y = round(Number(line.split('"')[1])) + else if (line.startsWith('width="')) + w = round(Number(line.split('"')[1])) + else if (line.startsWith('height="')) + h = round(Number(line.split('"')[1])) + else if (line.startsWith('cx="')) + cx = round(Number(line.split('"')[1])) + else if (line.startsWith('cy="')) + cy = round(Number(line.split('"')[1])) + else if (line.startsWith('r="')) + rx = ry = round(Number(line.split('"')[1])) + else if (line.startsWith('rx="')) + rx = round(Number(line.split('"')[1])) + else if (line.startsWith('ry="')) + ry = round(Number(line.split('"')[1])) + else if (line.startsWith('inkscape:label="')) + name = line.split('"')[1] +} + +flush() + +console.log("const BORDERS_XY = {") +for (let key in output) + console.log("\t\"" + key + "\": " + JSON.stringify(output[key]) + ",") +console.log("}") |