From abc73fdf0649bb0ba1bdfa0d0941416891b91002 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Sun, 7 Jun 2020 21:48:34 -0400 Subject: [PATCH] feat(layer): build out _get_common_attributes --- pytiled_parser/layer.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pytiled_parser/layer.py b/pytiled_parser/layer.py index 43781d2..3e7cb9c 100644 --- a/pytiled_parser/layer.py +++ b/pytiled_parser/layer.py @@ -214,6 +214,29 @@ def _get_common_attributes(raw_layer: RawLayer) -> Layer: Returns: Layer: The attributes in common of all layers """ + common_attributes = Layer(name=raw_layer["name"]) + + if raw_layer.get("startx") is not None: + common_attributes.coordinates = OrderedPair( + raw_layer["startx"], raw_layer["starty"] + ) + + if raw_layer.get("id") is not None: + common_attributes.id = raw_layer["id"] + + # if either width or height is present, they both are + if raw_layer.get("width") is not None: + common_attributes.size = Size(raw_layer["width"], raw_layer["height"]) + + if raw_layer.get("offsetx") is not None: + common_attributes.offset = OrderedPair( + raw_layer["offsetx"], raw_layer["offsety"] + ) + + if raw_layer.get("properties") is not None: + common_attributes.properties = properties_.cast(raw_layer["properties"]) + + return common_attributes def _cast_tile_layer(raw_layer: RawLayer) -> TileLayer: