Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_layer(self, layer):
""" Add a layer (TileTileLayer, TiledImageLayer, or TiledObjectGroup)
:param layer: TileTileLayer, TiledImageLayer, TiledObjectGroup object
"""
assert (
isinstance(layer,
(TiledTileLayer, TiledImageLayer, TiledObjectGroup)))
self.layers.append(layer)
self.layernames[layer.name] = layer
def parse_xml(self, node):
""" 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
:param x: x coordinate
:param y: y coordinate
:param layer: layer number
:rtype: surface if found, otherwise 0
"""
try:
assert (x >= 0 and y >= 0)
except AssertionError:
raise ValueError
try:
layer = self.layers[layer]
except IndexError:
raise ValueError
assert (isinstance(layer, TiledTileLayer))
try:
gid = layer.data[y][x]
except (IndexError, ValueError):
raise ValueError
except TypeError:
msg = "Tiles must be specified in integers."
logger.debug(msg)
raise TypeError
else:
return self.get_tile_image_by_gid(gid)