summaryrefslogtreecommitdiff
path: root/tools/genlayout.py
blob: 033ef5eebfe8807cf8bdfb8c89a1ae462dab1601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
list = []

def flush():
	global mode, name, x, y, w, h
	if mode == 'rect':
		list.append((name, round(x+w/2), round(y+h/2)))
	if mode == 'circle':
		list.append((name, round(x), round(y)))
	mode = None

def readsvg(filename):
	global mode, name, x, y, w, h
	mode = None
	name = None
	x = y = w = h = 0
	for line in open(filename).readlines():
		line = line.strip()
		if line == "<rect":
			flush()
			mode = 'rect'
			x = y = w = h = 0
			name = None
		elif line == "<ellipse" or line == "<circle":
			flush()
			mode = 'circle'
			x = y = w = h = 0
			name = None
		elif line == "<text":
			flush()
			mode = None
		if line.startswith('x="'): x = round(float(line.split('"')[1]))
		if line.startswith('y="'): y = round(float(line.split('"')[1]))
		if line.startswith('width="'): w = round(float(line.split('"')[1]))
		if line.startswith('height="'): h = round(float(line.split('"')[1]))
		if line.startswith('cx="'): x = round(float(line.split('"')[1]))
		if line.startswith('cy="'): y = round(float(line.split('"')[1]))
		if line.startswith('inkscape:label="'):
			name = line.split('"')[1]
			if " / " in name:
				if " COIN" in name:
					name = name.replace(" COIN", "")
					name = "-".join(sorted(name.split(" / "))) + " LoC COIN"
				elif " INSURGENTS" in name:
					name = name.replace(" INSURGENTS", "")
					name = "-".join(sorted(name.split(" / "))) + " LoC INSURGENTS"
				else:
					name = "-".join(sorted(name.split(" / "))) + " LoC"
	flush()

readsvg("tools/boxes.svg")
readsvg("tools/layout.svg")

def print_list():
	print("const LAYOUT = {")
	for (name,x,y) in list:
		xc = round((x+w/2.0))
		yc = round((y+h/2.0))
		print(f'\t"{name}": [{x}, {y}],')
	print("}")

print_list()