mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-02-14 07:11:14 +01:00
Fixed broken tests. Removed Class properties
Class Properties were not implemented very properly, need to revisit it with a more thought-out implementation.
This commit is contained in:
@@ -72,6 +72,7 @@ class RawTileSet(TypedDict):
|
||||
margin: int
|
||||
name: str
|
||||
properties: List[RawProperty]
|
||||
objectalignment: str
|
||||
source: str
|
||||
spacing: int
|
||||
tilecount: int
|
||||
@@ -239,6 +240,9 @@ def parse(
|
||||
if raw_tileset.get("imageheight") is not None:
|
||||
tileset.image_height = raw_tileset["imageheight"]
|
||||
|
||||
if raw_tileset.get("objectalignment") is not None:
|
||||
tileset.alignment = raw_tileset["objectalignment"]
|
||||
|
||||
if raw_tileset.get("backgroundcolor") is not None:
|
||||
tileset.background_color = parse_color(raw_tileset["backgroundcolor"])
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import xml.etree.ElementTree as etree
|
||||
from pathlib import Path
|
||||
from typing import List, Union, cast
|
||||
|
||||
from pytiled_parser.properties import Properties, Property, ClassProperty
|
||||
from pytiled_parser.properties import Properties, Property
|
||||
from pytiled_parser.util import parse_color
|
||||
|
||||
|
||||
@@ -14,13 +14,6 @@ def parse(raw_properties: etree.Element) -> Properties:
|
||||
for raw_property in raw_properties.findall("property"):
|
||||
|
||||
type_ = raw_property.attrib.get("type")
|
||||
if type_ == "class":
|
||||
children_nodes = raw_property.find("./properties")
|
||||
x = ClassProperty(
|
||||
raw_property.attrib["propertytype"], parse(children_nodes) if children_nodes is not None else {})
|
||||
final[raw_property.attrib["name"]] = x
|
||||
continue
|
||||
|
||||
value_ = raw_property.attrib["value"]
|
||||
if type_ == "file":
|
||||
value = Path(value_)
|
||||
|
||||
@@ -22,8 +22,7 @@ def parse(file: Path) -> TiledMap:
|
||||
TiledMap: A parsed TiledMap.
|
||||
"""
|
||||
with open(file) as map_file:
|
||||
tree = etree.parse(map_file)
|
||||
raw_map = tree.getroot()
|
||||
raw_map = etree.parse(map_file).getroot()
|
||||
|
||||
parent_dir = file.parent
|
||||
|
||||
@@ -61,7 +60,7 @@ def parse(file: Path) -> TiledMap:
|
||||
)
|
||||
|
||||
layers = []
|
||||
for element in raw_map.getchildren():
|
||||
for element in raw_map.iter():
|
||||
if element.tag in ["layer", "objectgroup", "imagelayer", "group"]:
|
||||
layers.append(parse_layer(element, parent_dir))
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ def parse(
|
||||
tile_height=int(raw_tileset.attrib["tileheight"]),
|
||||
columns=int(raw_tileset.attrib["columns"]),
|
||||
firstgid=firstgid,
|
||||
alignment=raw_tileset.attrib.get("objectalignment", "bottomleft"),
|
||||
)
|
||||
|
||||
if raw_tileset.attrib.get("version") is not None:
|
||||
@@ -139,6 +138,9 @@ def parse(
|
||||
if raw_tileset.attrib.get("margin") is not None:
|
||||
tileset.margin = int(raw_tileset.attrib["margin"])
|
||||
|
||||
if raw_tileset.attrib.get("objectalignment") is not None:
|
||||
tileset.alignment = raw_tileset.attrib["objectalignment"]
|
||||
|
||||
image_element = raw_tileset.find("image")
|
||||
if image_element is not None:
|
||||
if external_path:
|
||||
|
||||
@@ -13,11 +13,6 @@ from typing import Dict, Union
|
||||
|
||||
from .common_types import Color
|
||||
|
||||
class ClassProperty(dict):
|
||||
def __init__(self, propertytype:str, *args, **kwargs):
|
||||
self.propertytype = propertytype or ''
|
||||
dict.__init__(self, *args, **kwargs)
|
||||
|
||||
Property = Union[float, Path, str, bool, Color, ClassProperty]
|
||||
Property = Union[float, Path, str, bool, Color]
|
||||
|
||||
Properties = Dict[str, Property]
|
||||
|
||||
@@ -125,7 +125,7 @@ RECTANGLES = [
|
||||
<properties>
|
||||
<property name="bool property" type="bool" value="false"/>
|
||||
<property name="color property" type="color" value="#ffaa0000"/>
|
||||
<property name="file property" type="file" value="..\/..\/..\/..\/..\/..\/dev\/null"/>
|
||||
<property name="file property" type="file" value="../../../../../../dev/null"/>
|
||||
<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!!"/>
|
||||
|
||||
Reference in New Issue
Block a user