summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-08-24 01:17:17 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-24 01:19:42 +0200
commit3820856482017e0f206b0481856a86a2b4fc589c (patch)
treeff57b98648670583d0796d6ee0cbe500f7502f75 /tools
parent1c90c9ab2b7a97078d6a853c9d37d19e8a437ec8 (diff)
downloadvijayanagara-3820856482017e0f206b0481856a86a2b4fc589c.tar.gz
Start client.
Diffstat (limited to 'tools')
-rw-r--r--tools/layout.svg378
-rw-r--r--tools/parse-layout.js187
2 files changed, 565 insertions, 0 deletions
diff --git a/tools/layout.svg b/tools/layout.svg
new file mode 100644
index 0000000..1ead306
--- /dev/null
+++ b/tools/layout.svg
@@ -0,0 +1,378 @@
+<?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="1275"
+ height="1650"
+ 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="false"
+ inkscape:zoom="1.3237657"
+ inkscape:cx="732.66925"
+ inkscape:cy="245.31771"
+ inkscape:current-layer="g74"
+ inkscape:document-rotation="0" />
+ <image
+ sodipodi:absref="/home/tor/src/rally/public/vijayanagara/map75.jpg"
+ xlink:href="../map75.jpg"
+ id="image2"
+ sodipodi:insensitive="true"
+ image-rendering="pixelated"
+ height="1650"
+ width="1275"
+ y="0"
+ x="0" />
+ <g
+ id="g58"
+ inkscape:label="provinces">
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="path12"
+ cx="65.337875"
+ cy="393.10236"
+ r="34"
+ inkscape:label="Sindh" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle837"
+ cx="328.72156"
+ cy="402.87799"
+ r="34"
+ inkscape:label="Rajput Kingdoms" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle839"
+ cx="605.31427"
+ cy="572.21539"
+ r="34"
+ inkscape:label="Malwa" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle841"
+ cx="894.45099"
+ cy="455.29669"
+ r="34"
+ inkscape:label="Jaunpur" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle843"
+ cx="1192.2776"
+ cy="535.87579"
+ r="34"
+ inkscape:label="Bengal" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle845"
+ cx="1034.0819"
+ cy="858.19214"
+ r="34"
+ inkscape:label="Orissa" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle847"
+ cx="913.01575"
+ cy="736.92853"
+ r="34"
+ inkscape:label="Gondwana" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle849"
+ cx="670.44879"
+ cy="817.22009"
+ r="34"
+ inkscape:label="Madhyadesh" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle851"
+ cx="743.06372"
+ cy="1089.9803"
+ r="34"
+ inkscape:label="Andhra" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle853"
+ cx="438.38513"
+ cy="968.98218"
+ r="34"
+ inkscape:label="Maharashtra" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle855"
+ cx="220.07103"
+ cy="678.30847"
+ r="34"
+ inkscape:label="Gujarat" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle857"
+ cx="550.05054"
+ cy="1278.4006"
+ r="34"
+ inkscape:label="Karnataka" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="circle859"
+ cx="703.82556"
+ cy="1399.2897"
+ r="34"
+ inkscape:label="Tamilakam" />
+ </g>
+ <g
+ id="g64"
+ inkscape:label="available_boxes">
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect863"
+ width="177.06958"
+ height="110.22359"
+ x="23.983149"
+ y="99.914024"
+ inkscape:label="Mongol Invaders" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect865"
+ width="387.69797"
+ height="223.10062"
+ x="796.19531"
+ y="90.733284"
+ inkscape:label="DS Available" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect867"
+ width="237.8972"
+ height="223.72247"
+ x="21.017628"
+ y="908.0174"
+ inkscape:label="BK Available" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect869"
+ width="238.52563"
+ height="224.56042"
+ x="20.668497"
+ y="1405.1785"
+ inkscape:label="VE Available" />
+ </g>
+ <g
+ id="g86"
+ inkscape:label="tracks">
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect915"
+ width="60.631813"
+ height="61.421806"
+ x="1197.824"
+ y="403.09293"
+ inkscape:label="Track 24" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect913"
+ width="61.619305"
+ height="62.804291"
+ x="1196.8364"
+ y="14.219839"
+ inkscape:label="Track 18" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect911"
+ width="61.619305"
+ height="62.804291"
+ x="15.404826"
+ y="14.219839"
+ inkscape:label="Track 0" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect871"
+ width="61.446884"
+ height="62.564102"
+ x="18.15476"
+ y="1186.2042"
+ inkscape:label="BK Influence 0" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect873"
+ width="61.446884"
+ height="62.564102"
+ x="88.81868"
+ y="1186.4835"
+ inkscape:label="BK Influence 1" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect877"
+ width="61.446884"
+ height="62.564102"
+ x="160.11537"
+ y="1186.286"
+ inkscape:label="BK Influence 2" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect879"
+ width="61.446884"
+ height="62.564102"
+ x="231.21457"
+ y="1185.891"
+ inkscape:label="BK Influence 3" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect881"
+ width="61.446884"
+ height="62.564102"
+ x="302.31375"
+ y="1186.0885"
+ inkscape:label="BK Influence 4" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect885"
+ width="61.446884"
+ height="62.564102"
+ x="18.15476"
+ y="1291.7811"
+ inkscape:label="VE Influence 0" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect887"
+ width="61.446884"
+ height="62.564102"
+ x="88.81868"
+ y="1292.0604"
+ inkscape:label="VE Influence 1" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect889"
+ width="61.446884"
+ height="62.564102"
+ x="160.11537"
+ y="1291.8629"
+ inkscape:label="VE Influence 2" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect891"
+ width="61.446884"
+ height="62.564102"
+ x="231.21457"
+ y="1291.4679"
+ inkscape:label="VE Influence 3" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect893"
+ width="61.446884"
+ height="62.564102"
+ x="302.31375"
+ y="1291.6654"
+ inkscape:label="VE Influence 4" />
+ </g>
+ <g
+ id="g97"
+ inkscape:label="sequence_of_play">
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect895"
+ width="90.453941"
+ height="53.719433"
+ x="853.98035"
+ y="1305.0652"
+ inkscape:label="Limited Command" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect897"
+ width="90.848976"
+ height="200.65773"
+ x="853.58533"
+ y="1367.4745"
+ inkscape:label="Eligible Factions" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect899"
+ width="90.453979"
+ height="56.48436"
+ x="853.58533"
+ y="1577.6122"
+ inkscape:label="Pass" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect901"
+ width="90.058937"
+ height="201.0527"
+ x="1166.4218"
+ y="1366.6846"
+ inkscape:label="Ineligible Factions" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect905"
+ width="77.024101"
+ height="77.024071"
+ x="1016.3234"
+ y="1371.0295"
+ inkscape:label="Command and Decree" />
+ <rect
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:4"
+ id="rect907"
+ width="77.024101"
+ height="77.024071"
+ x="1016.3234"
+ y="1487.5532"
+ inkscape:label="Event or Command" />
+ </g>
+ <g
+ id="g74"
+ inkscape:label="mongol_invasion_regions">
+ <ellipse
+ style="fill:#00fff2;fill-opacity:0.566802;stroke-width:4"
+ id="path66"
+ cx="301.7406"
+ cy="139.98946"
+ rx="82.824387"
+ ry="27.608128"
+ inkscape:label="Mountain Passes" />
+ <ellipse
+ style="fill:#00fff2;fill-opacity:0.566802;stroke-width:4.16953"
+ id="path68"
+ cx="478.43262"
+ cy="219.56583"
+ rx="58.139465"
+ ry="18.838488"
+ inkscape:transform-center-x="0.5963195"
+ inkscape:transform-center-y="-19.991867"
+ inkscape:label="Punjab" />
+ <circle
+ style="fill:#00fff2;fill-opacity:0.566802;stroke:none;stroke-width:5.05769"
+ id="path861"
+ cx="646.8681"
+ cy="374.82599"
+ r="148"
+ inkscape:label="Delhi" />
+ </g>
+</svg>
diff --git a/tools/parse-layout.js b/tools/parse-layout.js
new file mode 100644
index 0000000..2060e17
--- /dev/null
+++ b/tools/parse-layout.js
@@ -0,0 +1,187 @@
+"use strict"
+
+const fs = require("fs")
+
+let circles = {}
+let rects = {}
+let edges = {}
+let mode, name, subname, x, y, w, h, cx, cy, rx, ry, x2, y2
+let labels = []
+
+function add_circle(cx, cy, rx, ry) {
+ if (!(name in circles))
+ circles[name] = {}
+ circles[name][subname] = {cx,cy,rx,ry}
+}
+
+function add_rect(x, y, w, h) {
+ if (!(name in rects))
+ rects[name] = {}
+ rects[name][subname] = {x,y,w,h}
+}
+
+function add_edge(x1, y1, x2, y2) {
+ if (name in edges)
+ edges[name].push({x1,y1,x2,y2})
+ else
+ edges[name] = [ {x1,y1,x2,y2} ]
+}
+
+function flush() {
+ if (mode === 'path') {
+ add_edge(x, y, x2, y2)
+ }
+ if (mode === 'rect') {
+ add_rect(x, y, w, h)
+ }
+ if (mode === 'circle') {
+ add_circle( cx, cy, rx, ry )
+ }
+ x = y = x2 = y2 = w = h = cx = cy = rx = ry = 0
+ subname = null
+}
+
+function parse_path_data(path) {
+ let cx = 0
+ let cy = 0
+ let abs = 0
+ for (let i = 0; i < path.length;) {
+ switch (path[i]) {
+ case 'M':
+ x2 = x = cx = Number(path[i+1])
+ y2 = y = cy = Number(path[i+2])
+ i += 3
+ abs = true
+ break
+ case 'm':
+ x2 = x = cx = cx + Number(path[i+1])
+ y2 = y = cy = cy + Number(path[i+2])
+ i += 3
+ abs = false
+ break
+ case 'C':
+ x2 = cx = Number(path[i+5])
+ y2 = cy = Number(path[i+6])
+ i += 7
+ abs = true
+ break
+ case 'L':
+ i += 1
+ abs = true
+ break
+ case 'H':
+ x2 = cx = Number(path[i+1])
+ i += 2
+ abs = true
+ break
+ case 'V':
+ y2 = cy = Number(path[i+1])
+ i += 2
+ abs = true
+ break
+ case 'c':
+ x2 = cx = cx + Number(path[i+5])
+ y2 = cy = cy + Number(path[i+6])
+ i += 7
+ abs = false
+ break
+ case 'l':
+ i += 1
+ abs = false
+ break
+ case 'h':
+ x2 = cx = cx + Number(path[i+1])
+ i += 2
+ abs = false
+ break
+ case 'v':
+ y2 = cy = cy + Number(path[i+1])
+ i += 2
+ abs = false
+ break
+ default:
+ if (abs) {
+ x2 = cx = Number(path[i+0])
+ y2 = cy = Number(path[i+1])
+ } else {
+ x2 = cx = cx + Number(path[i+0])
+ y2 = cy = cy + Number(path[i+1])
+ }
+ i += 2
+ break
+ }
+ }
+}
+
+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") || line.startsWith("<circle")) {
+ flush()
+ mode = "circle"
+ cx = cy = rx = ry = 0
+ }
+ else if (line.startsWith("<path")) {
+ flush()
+ mode = "path"
+ }
+ else if (line.startsWith("<g")) {
+ flush()
+ mode = "g"
+ }
+ else if (line.startsWith('x="'))
+ x = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('y="'))
+ y = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('width="'))
+ w = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('height="'))
+ h = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('cx="'))
+ cx = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('cy="'))
+ cy = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('r="'))
+ rx = ry = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('rx="'))
+ rx = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('ry="'))
+ ry = (Math.round(line.split('"')[1]))
+ else if (line.startsWith('inkscape:label="') && mode === "g")
+ name = line.split('"')[1]
+ else if (line.startsWith('inkscape:label="') && mode !== "g")
+ subname = line.split('"')[1]
+ else if (line.startsWith('d="'))
+ parse_path_data(line.split('"')[1].split(/[ ,]/))
+ if (line.includes("</tspan>")) {
+ let name = line.replace(/^[^>]*>/, "").replace(/<\/tspan.*/, "")
+ labels.push({x, y, name})
+ }
+}
+
+flush()
+
+function find_closest_node(list, x, y) {
+ let nd = Infinity, nn = null
+
+ for (let n of list) {
+ let d = Math.hypot(n.x - x, n.y - y)
+ if (d < nd) {
+ nd = d
+ nn = n
+ }
+ }
+
+ if (!nn) {
+ console.log("NOT FOUND", x, y)
+ return [ null, 0 ]
+ }
+
+ return [ nn, nd ]
+}
+
+console.log("const layout = " + JSON.stringify({ circles, rects }, null, "\t"))