From 02a81dfcc5beb1fbe784a3e261fd6416590f4755 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 1 Nov 2023 14:04:15 +0100 Subject: Clean up map. Use JS to layout stacks. Change size to be an even multiple of the track boxes (1503x1103). Move boxes and text into play.html part. Render area outlines and borders to bitmap. Focus stacks by clicking as in wilderness war. Stacks expand different directions based on the sub-location so that they don't collide with stacks in the same area. NOTE: Layout values have been manually tweaked. Do not re-run the genlayout script. --- tools/genlayout.py | 52 +- tools/genshape.js | 30 + tools/layout.svg | 2045 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 1715 insertions(+), 412 deletions(-) create mode 100644 tools/genshape.js (limited to 'tools') diff --git a/tools/genlayout.py b/tools/genlayout.py index 2e7bafe..9a287db 100644 --- a/tools/genlayout.py +++ b/tools/genlayout.py @@ -1,33 +1,41 @@ from bs4 import BeautifulSoup -SCALE = 1.8033333333333332 +SCALE = 1.8 def readsvg(filename): - with open(filename) as fp: - soup = BeautifulSoup(fp, features="xml") + with open(filename) as fp: + soup = BeautifulSoup(fp, features="xml") - result = [] - boxes = soup.find('g', id='Mission-Boxes') - for box in boxes.find_all('g', recursive=False): - area_name = box.attrs.get('serif:id', box.attrs['id']) - for rect in box.find_all('rect'): - rect_id = rect.attrs.get('serif:id', rect.attrs['id']) - x = float(rect.attrs['x']) - y = float(rect.attrs['y']) - w = float(rect.attrs['width']) - h = float(rect.attrs['height']) - xc = round((x+w/2.0)/SCALE) - yc = round((y+h/2.0)/SCALE) - name = area_name + '-' + rect_id - result.append([name, xc, yc]) + result = [] + boxes = soup.find('g', id='Mission-Boxes') + for box in boxes.find_all('g', recursive=False): + area_name = box.attrs.get('serif:id', box.attrs['id']) + for g in box.find_all('g'): + xo = 0 + yo = 0 + transform = g.attrs.get('transform') + if transform and transform.startswith("translate("): + transform = transform.replace("translate(","").replace(")","").split(',') + xo = float(transform[0]) + yo = float(transform[1]) + for rect in g.find_all('rect'): + rect_id = rect.attrs.get('serif:id', rect.attrs['id']) + x = float(rect.attrs['x']) + xo + y = float(rect.attrs['y']) + yo + w = float(rect.attrs['width']) + h = float(rect.attrs['height']) + xc = round((x+w/2.0)/SCALE) + yc = round((y+h/2.0)/SCALE) + name = area_name + '-' + rect_id + result.append([name, xc, yc]) - return result + return result def print_list(data): - print("const LAYOUT = {") - for (name, x, y) in data: - print(f'\t"{name}": [{x}, {y}],') - print("}") + print("const LAYOUT = {") + for (name, x, y) in data: + print(f'\t"{name}": [{x}, {y}],') + print("}") result = readsvg("tools/layout.svg") print_list(result) diff --git a/tools/genshape.js b/tools/genshape.js new file mode 100644 index 0000000..c1b7ddf --- /dev/null +++ b/tools/genshape.js @@ -0,0 +1,30 @@ +var fs = require("fs") + +function polygon(radius, sides, angle) { + let w = radius * 2 + 6 + let b = 3 + radius + let out = [] + out.push(``) + let d = [ "M" ] + for (let i = 0; i < sides; ++i) { + let a = (angle + (360 / sides) * i) * (Math.PI / 180) + let x = b + Math.round(Math.sin(a) * radius) + let y = b + Math.round(Math.cos(a) * radius) + d.push(x) + d.push(y) + } + d.push("z") + out.push(``) + out.push(``) + return out.join("\n") +} + +// circle diameter: 54 => 27 +// square width: 54 => 27 +// hex diameter = 60 => 30 +// triangle base = 70, r = 70 / sqrt(3) => 40 + +fs.writeFileSync("ops.svg", polygon(30, 6, 30)) +//fs.writeFileSync("ptl.svg", polygon(27, 100, 0)) +//fs.writeFileSync("oc.svg", polygon(27, 4, 45)) +fs.writeFileSync("ug.svg", polygon(38, 3, 180)) diff --git a/tools/layout.svg b/tools/layout.svg index f5a7850..d5addb3 100644 --- a/tools/layout.svg +++ b/tools/layout.svg @@ -1,448 +1,1713 @@ - - - - - - - - - - - - - - - - - - +image/svg+xml + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - - - + + + + + + -- cgit v1.2.3