diff options
author | Joël Simoneau <simoneaujoel@gmail.com> | 2024-10-21 16:09:57 -0400 |
---|---|---|
committer | Joël Simoneau <simoneaujoel@gmail.com> | 2024-10-21 16:09:57 -0400 |
commit | 29affe09b459127422544474986a69d83b2fe5ac (patch) | |
tree | 8c4fab3dd23615f1c37e6f1d75a5c703ca19a70b /tools/genlayout.py | |
parent | 27a606cfe34b324f625b45944c999da245994072 (diff) | |
download | vijayanagara-29affe09b459127422544474986a69d83b2fe5ac.tar.gz |
Data package.
Diffstat (limited to 'tools/genlayout.py')
-rw-r--r-- | tools/genlayout.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/genlayout.py b/tools/genlayout.py new file mode 100644 index 0000000..54b1724 --- /dev/null +++ b/tools/genlayout.py @@ -0,0 +1,51 @@ +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] + flush() + +readsvg("tools/pieces_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() |