Skip to content

Commit

Permalink
Merge pull request #153 from jamesalbert/master
Browse files Browse the repository at this point in the history
track groups, find layers inside groups
  • Loading branch information
bitcraft authored Oct 1, 2021
2 parents 29a5ed4 + 5a75641 commit 795905b
Showing 1 changed file with 23 additions and 7 deletions.
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

0 comments on commit 795905b

Please sign in to comment.