You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
2 years ago
|
from xml.etree import ElementTree
|
||
|
from itertools import chain
|
||
|
|
||
|
def read_level(file_path):
|
||
|
schema = '{http://www.w3.org/2000/svg}'
|
||
|
root = ElementTree.parse(file_path).getroot()
|
||
|
active = next(filter(
|
||
|
lambda g: g.get('id') == "ACTIVE",
|
||
|
root.iter(f"{schema}g")))
|
||
|
block_pos = [ (
|
||
|
float(rect.get('x')),
|
||
|
float(rect.get('y')),
|
||
|
float(rect.get('width')),
|
||
|
float(rect.get('height')),
|
||
|
)
|
||
|
for rect in active.iter(f"{schema}rect")
|
||
|
]
|
||
|
gem_pos = []
|
||
|
ellipses = chain(
|
||
|
active.iter(f"{schema}circle"),
|
||
|
active.iter(f"{schema}ellipse")
|
||
|
)
|
||
|
for ellipse in ellipses:
|
||
|
if ellipse.get('id') == "START":
|
||
|
start = (
|
||
|
float(ellipse.get(f'cx')),
|
||
|
float(ellipse.get(f'cy')),
|
||
|
)
|
||
|
else:
|
||
|
gem_pos.append((
|
||
|
float(ellipse.get('cx')),
|
||
|
float(ellipse.get('cy')),
|
||
|
))
|
||
|
|
||
|
return (start, gem_pos, block_pos)
|