From dd4cd1d65347aedd7f95ab4204a421c7ae7d980b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Simi=C4=87?= Date: Thu, 3 Oct 2024 19:16:51 +0200 Subject: [PATCH] Fix multiline string properties (#75) * Test for multiline object properties. * Fix parsing of multiline string properties. --- pytiled_parser/parsers/tmx/properties.py | 5 ++--- tests/test_tiled_object_tmx.py | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pytiled_parser/parsers/tmx/properties.py b/pytiled_parser/parsers/tmx/properties.py index 1b20e3d4..2c6f7dc4 100644 --- a/pytiled_parser/parsers/tmx/properties.py +++ b/pytiled_parser/parsers/tmx/properties.py @@ -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": diff --git a/tests/test_tiled_object_tmx.py b/tests/test_tiled_object_tmx.py index 702ced32..9b6a3848 100644 --- a/tests/test_tiled_object_tmx.py +++ b/tests/test_tiled_object_tmx.py @@ -129,6 +129,9 @@ + Hi +I can write multiple lines in here +That's pretty great """, @@ -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", }, ), ),