Skip to content

Commit

Permalink
Fix multiline string properties (#75)
Browse files Browse the repository at this point in the history
* Test for multiline object properties.

* Fix parsing of multiline string properties.
  • Loading branch information
KockaAdmiralac authored Oct 3, 2024
1 parent 31458e0 commit dd4cd1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pytiled_parser/parsers/tmx/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ def parse(raw_properties: etree.Element) -> Properties:
for raw_property in raw_properties.findall("property"):
type_ = raw_property.attrib.get("type")

if "value" not in raw_property.attrib:
value_ = raw_property.attrib.get("value", raw_property.text)
if value_ is None:
continue

value_ = raw_property.attrib["value"]

if type_ == "file":
value = Path(value_)
elif type_ == "color":
Expand Down
4 changes: 4 additions & 0 deletions tests/test_tiled_object_tmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<property name="float property" type="float" value="42.1"/>
<property name="int property" type="int" value="8675309"/>
<property name="string property" value="pytiled_parser rulez!1!!"/>
<property name="multiline string property">Hi
I can write multiple lines in here
That's pretty great</property>
</properties>
</object>
""",
Expand All @@ -144,6 +147,7 @@
"float property": 42.1,
"int property": 8675309,
"string property": "pytiled_parser rulez!1!!",
"multiline string property": "Hi\nI can write multiple lines in here\nThat's pretty great",
},
),
),
Expand Down

0 comments on commit dd4cd1d

Please sign in to comment.