detective-game/board-parts.py

44 lines
922 B
Python
Raw Normal View History

2022-11-27 14:52:57 -07:00
#! /usr/bin/python3
import sys
import xml.dom.minidom
doc = xml.dom.minidom.parse(sys.argv[1])
# Ugh, XML
path = None
for e in doc.getElementsByTagName("clipPath"):
if e.getAttribute("id") == "boardClip":
path = e
rect = path.getElementsByTagName("rect")[0]
rect_x = float(rect.getAttribute("x"))
rect_y = float(rect.getAttribute("y"))
rect_w = float(rect.getAttribute("width"))
rect_h = float(rect.getAttribute("height"))
l3 = rect_w
l1 = l3 / 3
l2 = l1 * 2
parts = [
[ 0, 0, l1, l2],
[l1, 0, l1, l2],
[l2, 0, l1, l2],
[ 0, l2, l2, l1],
[l2, l2, l1, l1],
]
for n in range(len(parts)):
x,y,w,h = parts[n]
x += rect_x
y += rect_y
rect.setAttribute("x", str(x))
rect.setAttribute("y", str(y))
rect.setAttribute("width", str(w))
rect.setAttribute("height", str(h))
with open("clue-board-part-%d.svg" % n, "w") as f:
f.write(doc.toxml())