From 8d25142f482919440dbae46513f91d5bc7943f49 Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 4 Jun 2020 20:42:11 -0400 Subject: [PATCH 1/2] add(layer): the missing objects --- pytiled_parser/layer.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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]]] From 99b4befcb431079ba471a6f84be0caf36be2345e Mon Sep 17 00:00:00 2001 From: Benjamin Kirkbride Date: Thu, 4 Jun 2020 20:45:30 -0400 Subject: [PATCH 2/2] chore(test): move maps to a subdir --- .../{ => maps}/all_objects/all_objects.json | 0 .../{ => maps}/all_objects/tileset_image.json | 0 .../all_objects/tileset_image_objects.json | 0 .../{ => maps}/images/tmw_desert_spacing.png | Bin .../map_simple_external_tileset.json | 0 .../simple_external_tileset/tileset_image.json | 0 .../{ => maps}/simple_infinite/map_infinite.json | 0 .../{ => maps}/simple_infinite/tileset_image.json | 0 .../{ => maps}/simple_offset/map_simple_offset.json | 0 .../{ => maps}/simple_offset/tileset_image.json | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename tests/test_data/{ => maps}/all_objects/all_objects.json (100%) rename tests/test_data/{ => maps}/all_objects/tileset_image.json (100%) rename tests/test_data/{ => maps}/all_objects/tileset_image_objects.json (100%) rename tests/test_data/{ => maps}/images/tmw_desert_spacing.png (100%) rename tests/test_data/{ => maps}/simple_external_tileset/map_simple_external_tileset.json (100%) rename tests/test_data/{ => maps}/simple_external_tileset/tileset_image.json (100%) rename tests/test_data/{ => maps}/simple_infinite/map_infinite.json (100%) rename tests/test_data/{ => maps}/simple_infinite/tileset_image.json (100%) rename tests/test_data/{ => maps}/simple_offset/map_simple_offset.json (100%) rename tests/test_data/{ => maps}/simple_offset/tileset_image.json (100%) 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