mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-02-23 15:49:52 +01:00
feature: implemented properties casting for TiledObjects
This commit is contained in:
@@ -3,10 +3,11 @@ from typing import Dict, List, NamedTuple, Optional, Union
|
|||||||
|
|
||||||
from .common_types import Color
|
from .common_types import Color
|
||||||
|
|
||||||
RawProperties = List[Dict[str, Union[str, bool, int, float]]]
|
|
||||||
|
|
||||||
|
|
||||||
Property = Union[int, float, Path, str, bool, Color]
|
Property = Union[int, float, Path, str, bool, Color]
|
||||||
|
|
||||||
|
|
||||||
|
RawProperties = List[Dict[str, Property]]
|
||||||
|
|
||||||
|
|
||||||
Properties = Dict[str, Property]
|
Properties = Dict[str, Property]
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ from typing import Callable, Dict, List, Mapping, Optional, Union
|
|||||||
import attr
|
import attr
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
from .properties import Properties, RawProperties
|
|
||||||
from .common_types import Color, OrderedPair, Size
|
from .common_types import Color, OrderedPair, Size
|
||||||
|
from .properties import Properties, RawProperties
|
||||||
from .template import Template
|
from .template import Template
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ class TiledObject:
|
|||||||
name: Optional[str] = None
|
name: Optional[str] = None
|
||||||
type: Optional[str] = None
|
type: Optional[str] = None
|
||||||
|
|
||||||
properties: Optional[Properties] = None
|
properties: Properties = {}
|
||||||
template: Optional[Template] = None
|
template: Optional[Template] = None
|
||||||
|
|
||||||
|
|
||||||
@@ -190,7 +190,9 @@ def _get_common_attributes(raw_tiled_object: RawTiledObject) -> TiledObject:
|
|||||||
coordinates = OrderedPair(x=raw_tiled_object["x"], y=raw_tiled_object["y"])
|
coordinates = OrderedPair(x=raw_tiled_object["x"], y=raw_tiled_object["y"])
|
||||||
visible = raw_tiled_object["visible"]
|
visible = raw_tiled_object["visible"]
|
||||||
|
|
||||||
common_attributes = TiledObject(id=id_, coordinates=coordinates, visible=visible)
|
common_attributes = TiledObject(
|
||||||
|
id=id_, coordinates=coordinates, visible=visible, properties={}
|
||||||
|
)
|
||||||
|
|
||||||
# optional attributes
|
# optional attributes
|
||||||
if any([raw_tiled_object.get("width"), raw_tiled_object.get("height")]):
|
if any([raw_tiled_object.get("width"), raw_tiled_object.get("height")]):
|
||||||
@@ -222,7 +224,10 @@ def _get_common_attributes(raw_tiled_object: RawTiledObject) -> TiledObject:
|
|||||||
common_attributes.type = raw_tiled_object["type"]
|
common_attributes.type = raw_tiled_object["type"]
|
||||||
|
|
||||||
if raw_tiled_object.get("properties"):
|
if raw_tiled_object.get("properties"):
|
||||||
raise NotImplementedError
|
for prop in raw_tiled_object["properties"]:
|
||||||
|
name = str(prop["name"])
|
||||||
|
value = prop["value"]
|
||||||
|
common_attributes.properties[name] = prop["value"]
|
||||||
|
|
||||||
if raw_tiled_object.get("template"):
|
if raw_tiled_object.get("template"):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
Reference in New Issue
Block a user