Skip to content

Commit 22d7631

Browse files
committed
All object tests passing for TMX
1 parent 5b78fd6 commit 22d7631

File tree

3 files changed

+529
-31
lines changed

3 files changed

+529
-31
lines changed

pytiled_parser/parsers/tmx/tiled_object.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ def _parse_polyline(raw_object: etree.Element) -> Polyline:
123123
Polyline: The Polyline object created from the raw object
124124
"""
125125
polyline = []
126-
for raw_point in raw_object.attrib["polyline"].split(" "):
127-
point = raw_point.split(",")
128-
polyline.append(OrderedPair(float(point[0]), float(point[1])))
126+
polyline_element = raw_object.find("./polyline")
127+
if polyline_element is not None:
128+
for raw_point in polyline_element.attrib["points"].split(" "):
129+
point = raw_point.split(",")
130+
polyline.append(OrderedPair(float(point[0]), float(point[1])))
129131

130132
return Polyline(points=polyline, **_parse_common(raw_object).__dict__)
131133

@@ -161,46 +163,50 @@ def _parse_text(raw_object: etree.Element) -> Text:
161163
Text: The Text object created from the raw object
162164
"""
163165
# required attributes
164-
text = raw_object.text
166+
text_element = raw_object.find("./text")
167+
168+
if text_element is not None:
169+
text = text_element.text
170+
171+
if not text:
172+
text = ""
173+
# create base Text object
174+
text_object = Text(text=text, **_parse_common(raw_object).__dict__)
165175

166-
if not text:
167-
text = ""
168-
# create base Text object
169-
text_object = Text(text=text, **_parse_common(raw_object).__dict__)
176+
# optional attributes
170177

171-
# optional attributes
172-
if raw_object.attrib.get("color") is not None:
173-
text_object.color = parse_color(raw_object.attrib["color"])
178+
if text_element.attrib.get("color") is not None:
179+
text_object.color = parse_color(text_element.attrib["color"])
174180

175-
if raw_object.attrib.get("fontfamily") is not None:
176-
text_object.font_family = raw_object.attrib["fontfamily"]
181+
if text_element.attrib.get("fontfamily") is not None:
182+
text_object.font_family = text_element.attrib["fontfamily"]
177183

178-
if raw_object.attrib.get("pixelsize") is not None:
179-
text_object.font_size = float(raw_object.attrib["pixelsize"])
184+
if text_element.attrib.get("pixelsize") is not None:
185+
text_object.font_size = float(text_element.attrib["pixelsize"])
180186

181-
if raw_object.attrib.get("bold") is not None:
182-
text_object.bold = bool(int(raw_object.attrib["bold"]))
187+
if text_element.attrib.get("bold") is not None:
188+
text_object.bold = bool(int(text_element.attrib["bold"]))
183189

184-
if raw_object.attrib.get("italic") is not None:
185-
text_object.italic = bool(int(raw_object.attrib["italic"]))
190+
if text_element.attrib.get("italic") is not None:
191+
text_object.italic = bool(int(text_element.attrib["italic"]))
186192

187-
if raw_object.attrib.get("kerning") is not None:
188-
text_object.kerning = bool(int(raw_object.attrib["kerning"]))
193+
if text_element.attrib.get("kerning") is not None:
194+
text_object.kerning = bool(int(text_element.attrib["kerning"]))
189195

190-
if raw_object.attrib.get("strikeout") is not None:
191-
text_object.strike_out = bool(int(raw_object.attrib["strikeout"]))
196+
if text_element.attrib.get("strikeout") is not None:
197+
text_object.strike_out = bool(int(text_element.attrib["strikeout"]))
192198

193-
if raw_object.attrib.get("underline") is not None:
194-
text_object.underline = bool(int(raw_object.attrib["underline"]))
199+
if text_element.attrib.get("underline") is not None:
200+
text_object.underline = bool(int(text_element.attrib["underline"]))
195201

196-
if raw_object.attrib.get("halign") is not None:
197-
text_object.horizontal_align = raw_object.attrib["halign"]
202+
if text_element.attrib.get("halign") is not None:
203+
text_object.horizontal_align = text_element.attrib["halign"]
198204

199-
if raw_object.attrib.get("valign") is not None:
200-
text_object.vertical_align = raw_object.attrib["valign"]
205+
if text_element.attrib.get("valign") is not None:
206+
text_object.vertical_align = text_element.attrib["valign"]
201207

202-
if raw_object.attrib.get("wrap") is not None:
203-
text_object.wrap = bool(int(raw_object.attrib["wrap"]))
208+
if text_element.attrib.get("wrap") is not None:
209+
text_object.wrap = bool(int(text_element.attrib["wrap"]))
204210

205211
return text_object
206212

0 commit comments

Comments
 (0)