Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track groups, find layers inside groups #153

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions pytmx/pytmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,24 @@ def parse_xml(self, node):

# *** do not change this load order! *** #
# *** gid mapping errors will occur if changed *** #
for subnode in node.findall('layer'):
for subnode in node.findall('.//group'):
self.add_layer(TiledGroupLayer(self, subnode))

for subnode in node.findall('.//layer'):
self.add_layer(TiledTileLayer(self, subnode))

for subnode in node.findall('imagelayer'):
for subnode in node.findall('.//imagelayer'):
self.add_layer(TiledImageLayer(self, subnode))

# this will only find objectgroup layers, not including tile colliders
for subnode in node.findall('objectgroup'):
for subnode in node.findall('.//objectgroup'):
objectgroup = TiledObjectGroup(self, subnode)
self.add_layer(objectgroup)
for obj in objectgroup:
self.objects_by_id[obj.id] = obj
self.objects_by_name[obj.name] = obj

for subnode in node.findall('tileset'):
for subnode in node.findall('.//tileset'):
self.add_tileset(TiledTileset(self, subnode))

# "tile objects", objects with a GID, require their attributes to be
Expand Down Expand Up @@ -704,9 +707,8 @@ def add_layer(self, layer):

:param layer: TileTileLayer, TiledImageLayer, TiledObjectGroup object
"""
assert (
isinstance(layer,
(TiledTileLayer, TiledImageLayer, TiledObjectGroup)))
assert (isinstance(layer, (TiledGroupLayer, TiledTileLayer,
TiledImageLayer, TiledObjectGroup)))

self.layers.append(layer)
self.layernames[layer.name] = layer
Expand Down Expand Up @@ -1009,6 +1011,20 @@ def parse_xml(self, node):
return self


class TiledGroupLayer(TiledElement):
def __init__(self, parent, node):
TiledElement.__init__(self)
self.parent = parent
self.name = None
self.visible = 1
self.parse_xml(node)

def parse_xml(self, node):
self._set_properties(node)
self.name = node.get('name', None)
return self


class TiledTileLayer(TiledElement):
""" Represents a TileLayer

Expand Down