diff --git a/pytiled_parser/properties.py b/pytiled_parser/properties.py index bc20c30..9fda86d 100644 --- a/pytiled_parser/properties.py +++ b/pytiled_parser/properties.py @@ -1,11 +1,22 @@ +"""Properties Module + +This module casts raw properties from Tiled maps into a dictionary of +properly typed Properties. +""" + from pathlib import Path -from typing import Dict, List, NamedTuple, Optional, Union +from typing import Dict, List, Union from typing_extensions import TypedDict from .common_types import Color Property = Union[float, Path, str, bool, Color] + + +Properties = Dict[str, Property] + + RawProperty = Union[float, str, bool] @@ -17,20 +28,26 @@ class RawProperties(TypedDict): value: RawProperty -Properties = Dict[str, Property] +def cast(raw_properties: List[RawProperties]) -> Dict[str, Property]: + """ Cast raw properties into a dictionary of completed properly typed properties. + Args: + raw_properties: The list of raw properties to cast. + + Returns: + Dict[str, Property]: The completed dictionary of casted properties. + """ -def cast(raw: List[RawProperties]) -> Dict[str, Property]: final: Properties = {} value: Property - for prop in raw: - if prop["type"] == "file": - value = Path(str(prop["value"])) - elif prop["type"] == "color": - value = Color(str(prop["value"])) + for property_ in raw_properties: + if property_["type"] == "file": + value = Path(str(property_["value"])) + elif property_["type"] == "color": + value = Color(str(property_["value"])) else: - value = prop["value"] - final[str(prop["name"])] = value + value = property_["value"] + final[str(property_["name"])] = value return final