diff --git a/pytiled_parser/layer.py b/pytiled_parser/layer.py index 76c3632..ef0be1f 100644 --- a/pytiled_parser/layer.py +++ b/pytiled_parser/layer.py @@ -6,6 +6,7 @@ import attr from .common_types import OrderedPair, Size from .properties import Properties +from .tiled_object import TiledObject @attr.s(auto_attribs=True, kw_only=True) @@ -83,3 +84,41 @@ class TileLayer(Layer): size: Size layer_data: LayerData + + +@attr.s(auto_attribs=True, kw_only=True) +class ObjectLayer(Layer): + """ + TiledObject Group Object. + The object group is in fact a map layer, and is hence called "object layer" in + Tiled. + See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#objectgroup + Args: + tiled_objects: List of tiled_objects in the layer. + offset: Rendering offset of the layer object in pixels. + color: The color used to display the objects in this group. FIXME: editor only? + draworder: Whether the objects are drawn according to the order of the object + elements in the object group element ('manual'), or sorted by their + y-coordinate ('topdown'). Defaults to 'topdown'. See: + https://doc.mapeditor.org/en/stable/manual/objects/#changing-stacking-order + for more info. + """ + + tiled_objects: List[TiledObject] + + color: Optional[str] = None + draw_order: Optional[str] = "topdown" + + +@attr.s(auto_attribs=True, kw_only=True) +class LayerGroup(Layer): + """Layer Group. + A LayerGroup can be thought of as a layer that contains layers + (potentially including other LayerGroups). + Offset and opacity recursively affect child layers. + See: https://doc.mapeditor.org/en/stable/reference/tmx-map-format/#group + Attributes: + Layers: Layers in group. + """ + + layers: Optional[List[Union["LayerGroup", Layer, ObjectLayer]]] diff --git a/tests/test_data/all_objects/all_objects.json b/tests/test_data/maps/all_objects/all_objects.json similarity index 100% rename from tests/test_data/all_objects/all_objects.json rename to tests/test_data/maps/all_objects/all_objects.json diff --git a/tests/test_data/all_objects/tileset_image.json b/tests/test_data/maps/all_objects/tileset_image.json similarity index 100% rename from tests/test_data/all_objects/tileset_image.json rename to tests/test_data/maps/all_objects/tileset_image.json diff --git a/tests/test_data/all_objects/tileset_image_objects.json b/tests/test_data/maps/all_objects/tileset_image_objects.json similarity index 100% rename from tests/test_data/all_objects/tileset_image_objects.json rename to tests/test_data/maps/all_objects/tileset_image_objects.json diff --git a/tests/test_data/images/tmw_desert_spacing.png b/tests/test_data/maps/images/tmw_desert_spacing.png similarity index 100% rename from tests/test_data/images/tmw_desert_spacing.png rename to tests/test_data/maps/images/tmw_desert_spacing.png diff --git a/tests/test_data/simple_external_tileset/map_simple_external_tileset.json b/tests/test_data/maps/simple_external_tileset/map_simple_external_tileset.json similarity index 100% rename from tests/test_data/simple_external_tileset/map_simple_external_tileset.json rename to tests/test_data/maps/simple_external_tileset/map_simple_external_tileset.json diff --git a/tests/test_data/simple_external_tileset/tileset_image.json b/tests/test_data/maps/simple_external_tileset/tileset_image.json similarity index 100% rename from tests/test_data/simple_external_tileset/tileset_image.json rename to tests/test_data/maps/simple_external_tileset/tileset_image.json diff --git a/tests/test_data/simple_infinite/map_infinite.json b/tests/test_data/maps/simple_infinite/map_infinite.json similarity index 100% rename from tests/test_data/simple_infinite/map_infinite.json rename to tests/test_data/maps/simple_infinite/map_infinite.json diff --git a/tests/test_data/simple_infinite/tileset_image.json b/tests/test_data/maps/simple_infinite/tileset_image.json similarity index 100% rename from tests/test_data/simple_infinite/tileset_image.json rename to tests/test_data/maps/simple_infinite/tileset_image.json diff --git a/tests/test_data/simple_offset/map_simple_offset.json b/tests/test_data/maps/simple_offset/map_simple_offset.json similarity index 100% rename from tests/test_data/simple_offset/map_simple_offset.json rename to tests/test_data/maps/simple_offset/map_simple_offset.json diff --git a/tests/test_data/simple_offset/tileset_image.json b/tests/test_data/maps/simple_offset/tileset_image.json similarity index 100% rename from tests/test_data/simple_offset/tileset_image.json rename to tests/test_data/maps/simple_offset/tileset_image.json