Skip to content

Commit dd4cd1d

Browse files
Fix multiline string properties (#75)
* Test for multiline object properties. * Fix parsing of multiline string properties.
1 parent 31458e0 commit dd4cd1d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pytiled_parser/parsers/tmx/properties.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ def parse(raw_properties: etree.Element) -> Properties:
1212
for raw_property in raw_properties.findall("property"):
1313
type_ = raw_property.attrib.get("type")
1414

15-
if "value" not in raw_property.attrib:
15+
value_ = raw_property.attrib.get("value", raw_property.text)
16+
if value_ is None:
1617
continue
1718

18-
value_ = raw_property.attrib["value"]
19-
2019
if type_ == "file":
2120
value = Path(value_)
2221
elif type_ == "color":

tests/test_tiled_object_tmx.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<property name="float property" type="float" value="42.1"/>
130130
<property name="int property" type="int" value="8675309"/>
131131
<property name="string property" value="pytiled_parser rulez!1!!"/>
132+
<property name="multiline string property">Hi
133+
I can write multiple lines in here
134+
That's pretty great</property>
132135
</properties>
133136
</object>
134137
""",
@@ -144,6 +147,7 @@
144147
"float property": 42.1,
145148
"int property": 8675309,
146149
"string property": "pytiled_parser rulez!1!!",
150+
"multiline string property": "Hi\nI can write multiple lines in here\nThat's pretty great",
147151
},
148152
),
149153
),

0 commit comments

Comments
 (0)