Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
""" Parse a map from ElementTree xml node
:param node: ElementTree xml node
:return: self
"""
self._set_properties(node)
self.background_color = node.get('backgroundcolor',
self.background_color)
# *** do not change this load order! *** #
# *** gid mapping errors will occur if changed *** #
for subnode in node.findall('layer'):
self.add_layer(TiledTileLayer(self, subnode))
for subnode in node.findall('imagelayer'):
self.add_layer(TiledImageLayer(self, subnode))
for subnode in node.findall('objectgroup'):
self.add_layer(TiledObjectGroup(self, subnode))
for subnode in node.findall('tileset'):
self.add_tileset(TiledTileset(self, subnode))
# "tile objects", objects with a GID, have need to have their attributes
# set after the tileset is loaded, so this step must be performed last
# also, this step is performed for objects to load their tiles.
# tiled stores the origin of GID objects by the lower right corner
# this is different for all other types, so i just adjust it here
# so all types loaded with pytmx are uniform.
# iterate through tile objects and handle the image
# gids is None if the tile is never used
# but give another chance to load the gid anyway
if gids is None:
if self.load_all_tiles or real_gid in self.optional_gids:
# TODO: handle flags? - might never be an issue, though
gids = [self.register_gid(real_gid, flags=0)]
if gids:
# flags might rotate/flip the image, so let the loader
# handle that here
for gid, flags in gids:
self.images[gid] = loader(rect, flags)
# load image layer images
for layer in (i for i in self.layers if isinstance(i, TiledImageLayer)):
source = getattr(layer, 'source', None)
if source:
colorkey = getattr(layer, 'trans', None)
real_gid = len(self.images)
gid = self.register_gid(real_gid)
layer.gid = gid
path = os.path.join(os.path.dirname(self.filename), source)
loader = self.image_loader(path, colorkey)
image = loader()
self.images.append(image)
# load images in tiles.
# instead of making a new gid, replace the reference to the tile that
# was loaded from the tileset
for real_gid, props in self.tile_properties.items():
source = props.get('source', None)