diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-05-26 14:12:31 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-12-10 18:13:09 +0100 |
commit | b9474e7ef170fd5dac842cadf52072e0a89f1bcb (patch) | |
tree | 36c6c62711b293c32b34de44f8ef741c969e0624 /tools | |
parent | 70f4c2a76d68a1c7187f62b4cc2013be752f7005 (diff) | |
download | plantagenet-b9474e7ef170fd5dac842cadf52072e0a89f1bcb.tar.gz |
WIP map boxes and layout
Diffstat (limited to 'tools')
-rw-r--r-- | tools/genboxes.js | 58 | ||||
-rw-r--r-- | tools/layout.svg | 79 |
2 files changed, 137 insertions, 0 deletions
diff --git a/tools/genboxes.js b/tools/genboxes.js new file mode 100644 index 0000000..356955b --- /dev/null +++ b/tools/genboxes.js @@ -0,0 +1,58 @@ +const fs = require("fs") + +const { round, floor, ceil } = Math + +let boxes = {} +let mode, name, x, y, w, h, cx, cy, rx, ry + +function flush() { + if (mode === 'rect') { + boxes[name] = [ x, y, w, h ] + } + if (mode === 'circle') { + x = cx - rx + y = cy - ry + w = rx * 2 + h = ry * 2 + boxes[name] = [ x, y, w, h ] + } + x = y = w = h = cx = cy = rx = ry = 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("<ellipse")) { + 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('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 boxes = {") +for (let key in boxes) + console.log("\t" + key + ": " + JSON.stringify(boxes[key]) + ",") +console.log("}") diff --git a/tools/layout.svg b/tools/layout.svg new file mode 100644 index 0000000..3889183 --- /dev/null +++ b/tools/layout.svg @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="1350" + height="1725" + version="1.1" + id="svg4" + sodipodi:docname="layout.svg" + inkscape:version="1.0.2 (e86c870879, 2021-01-15)"> + <metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs8" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="640" + inkscape:window-height="480" + id="namedview6" + showgrid="true" + inkscape:zoom="4" + inkscape:cx="309.54531" + inkscape:cy="1500.0381" + inkscape:current-layer="svg4"> + <inkscape:grid + type="xygrid" + id="grid839" /> + </sodipodi:namedview> + <image + sodipodi:absref="/home/tor/src/rally/public/plantagenet/map75.png" + xlink:href="../map75.png" + id="image2" + sodipodi:insensitive="true" + image-rendering="pixelated" + height="1725" + width="1350" + y="0" + x="0" /> + <rect + style="fill:#00ffff;fill-opacity:0.4;stroke:none;stroke-width:1.00573;stroke-linecap:round;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect12" + width="103" + height="150" + x="240" + y="74" + ry="0.76437294" + inkscape:label="Calendar 1" /> + <rect + style="fill:#00ffff;fill-opacity:0.4;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect841" + width="55" + height="45" + x="180" + y="1490" + ry="0.764373" + inkscape:label="Truro" /> +</svg> |