summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-06-01 15:04:23 +0200
committerTor Andersson <tor@ccxvii.net>2024-06-01 15:04:23 +0200
commit562e1822729e85834e54cc76d0bfbc8a584c572c (patch)
treee3cf66ad203b7bebcc0b0f31f64e5ab772cee746 /tools
parente1a0ee4619c330f9da81f00dc4f1e50c5ee61d02 (diff)
downloadmaria-562e1822729e85834e54cc76d0bfbc8a584c572c.tar.gz
setup
Diffstat (limited to 'tools')
-rw-r--r--tools/layout.svg29
-rw-r--r--tools/parse-layout.js137
2 files changed, 106 insertions, 60 deletions
diff --git a/tools/layout.svg b/tools/layout.svg
index 841fb90..aa73244 100644
--- a/tools/layout.svg
+++ b/tools/layout.svg
@@ -40,10 +40,10 @@
inkscape:window-height="480"
id="namedview6"
showgrid="false"
- inkscape:zoom="8.3661045"
- inkscape:cx="236.64652"
- inkscape:cy="1572.9559"
- inkscape:current-layer="g3013"
+ inkscape:zoom="6.1864511"
+ inkscape:cx="1511.6937"
+ inkscape:cy="597.4918"
+ inkscape:current-layer="g5174"
inkscape:document-rotation="0"
showguides="false">
<inkscape:grid
@@ -63,7 +63,8 @@
style="display:inline" />
<g
id="g3013"
- inkscape:label="box">
+ inkscape:label="box"
+ style="display:none">
<rect
style="fill:#ffffff;fill-opacity:0.54878;stroke-width:1.01529"
id="rect3008"
@@ -100,7 +101,7 @@
<g
id="g2467"
inkscape:label="major_fortress"
- style="fill:#ffffff"
+ style="display:none;fill:#ffffff"
sodipodi:insensitive="true">
<circle
style="fill:#ffffff;fill-opacity:0.809893;stroke:none"
@@ -196,7 +197,8 @@
<g
id="g2403"
inkscape:label="minor_fortress"
- sodipodi:insensitive="true">
+ sodipodi:insensitive="true"
+ style="display:none">
<rect
style="fill:#ffffff;fill-opacity:0.809893;stroke:none"
id="rect2211"
@@ -649,7 +651,8 @@
<g
id="g1382"
inkscape:label="city"
- sodipodi:insensitive="true">
+ sodipodi:insensitive="true"
+ style="display:none">
<circle
style="fill:#ff2f2f;fill-opacity:0.54878;stroke:none;stroke-opacity:1"
id="circle846"
@@ -4063,9 +4066,9 @@
</g>
<g
id="g3273"
- inkscape:label="major_road"
+ inkscape:label="main_road"
sodipodi:insensitive="true"
- style="stroke:#b3b3b3">
+ style="display:none;stroke:#b3b3b3">
<path
style="font-variation-settings:normal;opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#b3b3b3;stroke-width:6;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;stop-color:#000000;stop-opacity:1"
d="m 927.46646,172.09164 -51.03383,15.29644"
@@ -5082,7 +5085,7 @@
id="g5326"
inkscape:label="road"
sodipodi:insensitive="true"
- style="stroke:#cccccc">
+ style="display:none;stroke:#cccccc">
<path
style="font-variation-settings:normal;opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#cccccc;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;stop-color:#000000;stop-opacity:1"
d="m 153.3132,1503.4258 75.96726,11.8004"
@@ -9464,9 +9467,9 @@
y="570.19531"
id="text2119"><tspan
sodipodi:role="line"
- id="tspan2117"
x="1452.9949"
- y="570.19531">Meißsen</tspan></text>
+ y="570.19531"
+ id="tspan2983">Meißen</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8px;line-height:1.25;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;stop-color:#000000;stop-opacity:1"
diff --git a/tools/parse-layout.js b/tools/parse-layout.js
index 9006560..785bc8c 100644
--- a/tools/parse-layout.js
+++ b/tools/parse-layout.js
@@ -1,10 +1,35 @@
+"use strict"
+
const fs = require("fs")
let points = {}
let rects = {}
let edges = {}
-let mode, name, x, y, w, h, cx, cy, rx, ry, x2, y2
+let mode, name, subname, x, y, w, h, cx, cy, rx, ry, x2, y2
let labels = []
+let sectors = {}
+
+function array_insert(array, index, item) {
+ for (let i = array.length; i > index; --i)
+ array[i] = array[i - 1]
+ array[index] = item
+}
+
+function set_add(set, item) {
+ let a = 0
+ let b = set.length - 1
+ while (a <= b) {
+ let m = (a + b) >> 1
+ let x = set[m]
+ if (item < x)
+ b = m - 1
+ else if (item > x)
+ a = m + 1
+ else
+ return
+ }
+ array_insert(set, a, item)
+}
function add_point(x, y) {
if (name in points)
@@ -32,6 +57,8 @@ function flush() {
add_edge(x, y, x2, y2)
}
if (mode === 'rect') {
+ if (subname && subname.startsWith("#"))
+ sectors[subname.slice(1)] = [x, y, x+w, y+h]
if (name.startsWith("$"))
add_rect(x, y, w, h)
else
@@ -41,6 +68,7 @@ function flush() {
add_point( cx, cy )
}
x = y = x2 = y2 = w = h = cx = cy = rx = ry = 0
+ subname = null
}
function parse_path_data(path) {
@@ -85,6 +113,7 @@ function parse_path_data(path) {
x2 = cx = cx + Number(path[i+5])
y2 = cy = cy + Number(path[i+6])
i += 7
+ abs = false
break
case 'l':
i += 1
@@ -154,6 +183,8 @@ for (let line of fs.readFileSync("tools/layout.svg", "utf-8").split("\n")) {
ry = (Number(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>")) {
@@ -300,7 +331,7 @@ for (let key in points) {
}
if (country === "UNKNOWN")
- console.log("no country:", node)
+ console.warn("no country:", node)
cities.push({
name: node.name,
@@ -310,6 +341,7 @@ for (let key in points) {
type: key,
x: Math.round(x),
y: Math.round(y),
+ adjacent: [],
main_roads: [],
roads: [],
})
@@ -320,48 +352,65 @@ for (let key in points) {
}
}
+
cities.sort((a,b) => {
- if (a.country < b.country) return -1
- if (a.country > b.country) return 1
+ if (a.map < b.map) return -1
+ if (a.map > b.map) return 1
+
+ //let a_obj = a.type.includes("fortress")
+ //let b_obj = b.type.includes("fortress")
+ //if (a_obj && !b_obj) return -1
+ //if (!a_obj && b_obj) return 1
- if (a.map < b.map) return 1
- if (a.map > b.map) return -1
+ // if (a.type === "depot" && b.type !== "depot") return -1
+ // if (a.type !== "depot" && b.type === "depot") return 1
if (a.suit < b.suit) return -1
if (a.suit > b.suit) return 1
- //if (a.type === "major_fortress" && b.type !== "major_fortress") return -1
- //if (a.type !== "major_fortress" && b.type === "major_fortress") return 1
- //if (a.type === "minor_fortress" && b.type !== "minor_fortress") return -1
- //if (a.type !== "minor_fortress" && b.type === "minor_fortress") return 1
+ // if (a.country < b.country) return -1
+ // if (a.country > b.country) return 1
+
+ if (a.type === "major_fortress" && b.type !== "major_fortress") return -1
+ if (a.type !== "major_fortress" && b.type === "major_fortress") return 1
+ if (a.type === "minor_fortress" && b.type !== "minor_fortress") return -1
+ if (a.type !== "minor_fortress" && b.type === "minor_fortress") return 1
+
+ if (a.type === "box" && b.type !== "box") return 1
+ if (a.type !== "box" && b.type === "box") return -1
if (a.name < b.name) return -1
if (a.name > b.name) return 1
+
return b.y - a.y
})
-for (let e of edges.major_road) {
+for (let e of edges.main_road) {
let a = find_closest_city(e.x1, e.y1)
let b = find_closest_city(e.x2, e.y2)
- cities[a].main_roads.push(b)
- cities[b].main_roads.push(a)
+ set_add(cities[a].main_roads, b)
+ set_add(cities[b].main_roads, a)
+ set_add(cities[a].adjacent, b)
+ set_add(cities[b].adjacent, a)
}
for (let e of edges.road) {
let a = find_closest_city(e.x1, e.y1)
let b = find_closest_city(e.x2, e.y2)
- cities[a].roads.push(b)
- cities[b].roads.push(a)
+ set_add(cities[a].roads, b)
+ set_add(cities[b].roads, a)
+ set_add(cities[a].adjacent, b)
+ set_add(cities[b].adjacent, a)
}
let arrays = {
name: [],
- // map: [],
- country: [],
+ // country: [],
// suit: [],
// type: [],
x: [],
y: [],
+ adjacent: [],
main_roads: [],
roads: [],
}
@@ -379,21 +428,21 @@ let sets = {
hearts: [],
spades: [],
},
- map: {
- Flanders: [],
- Bohemia: [],
- UNKNOWN: [],
- },
country: {
Austria: [],
Bavaria: [],
+ Empire: [],
France: [],
Netherlands: [],
Poland: [],
Prussia: [],
Saxony: [],
Silesia: [],
- Empire: [],
+ UNKNOWN: [],
+ },
+ map: {
+ Bohemia: [],
+ Flanders: [],
UNKNOWN: [],
},
}
@@ -426,35 +475,29 @@ function remap_to_range(obj) {
obj[key] = map_to_range(obj[key])
}
-remap_to_range(sets.map)
remap_to_range(sets.suit)
-remap_to_range(sets.country)
-
-function object_group_by(items, callback) {
- let groups = {}
- if (typeof callback === "function") {
- for (let item of items) {
- let key = callback(item)
- if (key in groups)
- groups[key].push(item)
- else
- groups[key] = [ item ]
- }
- } else {
- for (let item of items) {
- let key = item[callback]
- if (key in groups)
- groups[key].push(item)
- else
- groups[key] = [ item ]
- }
- }
- return groups
-}
+remap_to_range(sets.map)
+//remap_to_range(sets.country)
delete sets.type.city
sets.cities = arrays
+function list_cities_in_rect(rect) {
+ let [ x1, y1, x2, y2 ] = rect
+ let list = []
+ for (let i = 0; i < sets.cities.name.length; ++i) {
+ let x = sets.cities.x[i]
+ let y = sets.cities.y[i]
+ if (x >= x1 && x <= x2 && y >= y1 && y <= y2)
+ list.push(i)
+ }
+ return list
+}
+
+sets.sectors = {}
+for (let key in sectors)
+ sets.sectors[key] = list_cities_in_rect(sectors[key])
+
console.log("const data = " + JSON.stringify(sets))
console.log("if (typeof module === 'object') module.exports = data")