Skip to content
Open
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: 26 additions & 4 deletions pytmx/pytmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,39 @@ def parse_xml(self, node: ElementTree.Element):

# *** do not change this load order! *** #
# *** gid mapping errors will occur if changed *** #
for subnode in node.findall(".//group"):
def find_all_visible_nodes(node, node_type):
""" Recursively find all visible nodes of the specified type

Recurses though the ElementTree of a TMX file to find visible nodes
by node type. The layers can be organized in a tree structure of
group layers. This method recurses through any groups to find all
such layers in the TMX file.

:param node: ElementTree xml node
:param node_type: Tag name of elements to find
:return: Python list of ElementTree xml nodes
"""
subnodes = []
for subnode in node:
if 'visible' in subnode.attrib and not convert_to_bool(subnode.attrib['visible']):
continue
if subnode.tag == node_type:
subnodes.append(subnode)
elif subnode.tag == 'group':
subnodes += find_all_visible_nodes(subnode, node_type)
return subnodes

for subnode in find_all_visible_nodes(node, 'group'):
self.add_layer(TiledGroupLayer(self, subnode))

for subnode in node.findall(".//layer"):
for subnode in find_all_visible_nodes(node, 'layer'):
self.add_layer(TiledTileLayer(self, subnode))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only adds visible layers while previously non-visible layers were also added. If there is utility in also adding the non-visible layers, it has been lost. It could be restored with additional changes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be ignoring invisible layers. For instance, a map may have a shape layer for boundaries that might be invisible on tiled, but we still want it loaded to get the shapes.


for subnode in node.findall(".//imagelayer"):
for subnode in find_all_visible_nodes(node, '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 find_all_visible_nodes(node, 'objectgroup'):
objectgroup = TiledObjectGroup(self, subnode)
self.add_layer(objectgroup)
for obj in objectgroup:
Expand Down