Skip to content

Commit 00691fa

Browse files
authored
Re-add class properties (#83)
1 parent a8c90ad commit 00691fa

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pytiled_parser/parsers/tmx/properties.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import xml.etree.ElementTree as etree
22
from pathlib import Path
33

4-
from pytiled_parser.properties import Properties, Property
4+
from pytiled_parser.properties import Properties, Property, ClassProperty
55
from pytiled_parser.util import parse_color
66

77

@@ -11,6 +11,12 @@ def parse(raw_properties: etree.Element) -> Properties:
1111

1212
for raw_property in raw_properties.findall("property"):
1313
type_ = raw_property.attrib.get("type")
14+
if type_ == "class":
15+
children_nodes = raw_property.find("./properties")
16+
x = ClassProperty(
17+
raw_property.attrib["propertytype"], parse(children_nodes) if children_nodes is not None else {})
18+
final[raw_property.attrib["name"]] = x
19+
continue
1420

1521
value_ = raw_property.attrib.get("value", raw_property.text)
1622
if value_ is None:

pytiled_parser/properties.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
from .common_types import Color
1515

16-
Property = Union[int, float, Path, str, bool, Color]
16+
class ClassProperty(dict):
17+
def __init__(self, propertytype:str, *args, **kwargs):
18+
self.propertytype = propertytype or ''
19+
dict.__init__(self, *args, **kwargs)
20+
21+
Property = Union[int, float, Path, str, bool, Color, ClassProperty]
1722

1823
Properties = Dict[str, Property]

0 commit comments

Comments
 (0)