mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-29 07:40:11 +01:00
Merge branch 'rf/caster' of github.com:Beefy-Swain/pytiled_parser into rf/caster
This commit is contained in:
@@ -3,11 +3,23 @@ from typing import Dict, List, NamedTuple, Optional, Union
|
||||
|
||||
from .common_types import Color
|
||||
|
||||
|
||||
Property = Union[int, float, Path, str, bool, Color]
|
||||
|
||||
class
|
||||
|
||||
RawProperties = List[Dict[str, Property]]
|
||||
|
||||
|
||||
Properties = Dict[str, Property]
|
||||
|
||||
|
||||
def cast(raw: RawProperties) -> Dict[str, Property]:
|
||||
final: Properties = {}
|
||||
for prop in raw:
|
||||
value = prop["value"]
|
||||
if prop["type"] == "file":
|
||||
value = Path(str(value))
|
||||
elif prop["type"] == "color":
|
||||
value = Color(str(value))
|
||||
final[str(prop["name"])] = value
|
||||
|
||||
return final
|
||||
|
||||
@@ -5,8 +5,8 @@ from typing import Callable, Dict, List, Optional, Union
|
||||
import attr
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from . import properties as properties_
|
||||
from .common_types import Color, OrderedPair, Size
|
||||
from .properties import Properties, RawProperties
|
||||
from .template import Template
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class TiledObject:
|
||||
name: Optional[str] = None
|
||||
type: Optional[str] = None
|
||||
|
||||
properties: Properties = {}
|
||||
properties: properties_.Properties = {}
|
||||
template: Optional[Template] = None
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ class RawTiledObject(TypedDict):
|
||||
visible: bool
|
||||
name: str
|
||||
type: str
|
||||
properties: RawProperties
|
||||
properties: properties_.RawProperties
|
||||
template: Template
|
||||
ellipse: bool
|
||||
point: bool
|
||||
@@ -227,10 +227,7 @@ def _get_common_attributes(raw_tiled_object: RawTiledObject) -> TiledObject:
|
||||
common_attributes.type = raw_tiled_object["type"]
|
||||
|
||||
if raw_tiled_object.get("properties"):
|
||||
for prop in raw_tiled_object["properties"]:
|
||||
name = str(prop["name"])
|
||||
value = prop["value"]
|
||||
common_attributes.properties[name] = prop["value"]
|
||||
common_attributes.properties = properties_.cast(raw_tiled_object["properties"])
|
||||
|
||||
if raw_tiled_object.get("template"):
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user