diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-11-12 03:04:36 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-11-18 00:46:17 +0100 |
commit | 8063f3b9ba28d439cad6c8317d3b58796d5a5ddb (patch) | |
tree | e7597d9119bf60c43a44e96268e7734a140be8e9 /tools/genroads.js | |
parent | e66e845ef1d691d2086afc7984ec5807706a6121 (diff) | |
download | crusader-rex-8063f3b9ba28d439cad6c8317d3b58796d5a5ddb.tar.gz |
Show road limits.
Use maps instead of objects for road_limit, last_used and main_road.
Diffstat (limited to 'tools/genroads.js')
-rw-r--r-- | tools/genroads.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tools/genroads.js b/tools/genroads.js new file mode 100644 index 0000000..71b1c45 --- /dev/null +++ b/tools/genroads.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/roads.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 ROADS_XY = {") +for (let key in output) + console.log("\t\"" + key + "\": " + JSON.stringify(output[key]) + ",") +console.log("}") |