Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Attr('fontfamily', str, 'sans-serif', 'font family used'),
Attr('pixelsize', int, 16, 'size of font in pixels'),
Attr('wrap', bool, False, 'word wrap'),
Attr('color', str, '#000000', 'color of text'),
Attr('bold', bool, False, 'bold?'),
Attr('italic', bool, False, 'italic?'),
Attr('underline', bool, False, 'underline?'),
Attr('strikeout', bool, False, 'strikeout?'),
Attr('kerning', bool, False, 'render kerning, or not'),
Attr('halign', str, 'left', 'horizontal alignment in object'),
Attr('valign', str, 'top', 'vertical alignment in object'),
)
# ok
class TileToken(Token):
# from tileset
attributes = (
Attr('id', int, None, 'local id'),
Attr('gid', int, None, 'global id'),
Attr('type', str, None, 'defined in editor'),
Attr('terrain', str, None, 'optional'),
Attr('probability', float, None, 'optional'),
)
def __init__(self):
super(TileToken, self).__init__()
self.image = None
def add_image(self, item):
self.image = item
# if for some reason tile elements are used
elif self.tiles:
self.data = rowify([i.gid for i in self.tiles], w, h)
else:
raise Exception('no layer data?')
def add_tile(self, item):
self.tiles.append(item)
def add_chunk(self, item):
self.chunks.append(item)
# ok
class EllipseToken(Token):
""" No attributes defined """
pass
# ok
class FrameToken(Token):
attributes = (
Attr('tileid', int, None, 'local id within parent tileset'),
Attr('duration', int, None, 'duration in milliseconds'),
)
# ok
class GroupToken(Token):
attributes = (
Attr('name', str, None, 'name of group'),
def add_layer(self, item):
self.layers.append(item)
def add_objectgroup(self, item):
self.objectgroups.append(item)
def add_imagelayer(self, item):
self.layers.append(item)
def add_group(self, item):
raise UnsupportedFeature
# ok
class ObjectToken(Token):
attributes = (
Attr('name', str, None, 'name of object'),
Attr('id', int, None, 'unique id assigned to object'),
Attr('type', str, None, 'defined by editor'),
Attr('x', float, None, 'tile x coordinate'),
Attr('y', float, None, 'tile y coordinate'),
Attr('width', float, None, 'pixel widht'),
Attr('height', float, None, 'pixel height'),
Attr('rotation', float, 0, 'rotation'),
Attr('gid', int, None, 'reference a tile id'),
Attr('template', str, None, 'path, optional'),
Visible, Opacity
)
def __init__(self):
super(ObjectToken, self).__init__()
self.points = move_points(item.points, self.x, self.y)
self.attrib['closed'] = True
def add_polyline(self, item):
self.points = move_points(item.points, self.x, self.y)
self.attrib['closed'] = False
def add_text(self, item):
raise UnsupportedFeature
def add_image(self, item):
raise UnsupportedFeature
# ok
class ObjectgroupToken(Token):
attributes = (
Attr('name', str, None, 'name of group'),
Attr('x', float, 0, 'not used, per spec'),
Attr('y', float, 0, 'not used, per spec'),
Attr('width', int, None, 'not used, per spec'),
Attr('height', int, None, 'not used, per spec'),
Color, Visible, Opacity
)
def __init__(self):
super(ObjectgroupToken, self).__init__()
self.objects = list()
def add_object(self, item):
self.objects.append(item)
# ok
class TemplateToken(Token):
def __init__(self):
super(TemplateToken, self).__init__()
self.tilesets = list()
self.objects = list()
def add_terrain(self, item):
self.terrains.append(item)
def add_object(self, item):
self.objects.append(item)
# ok
class TerrainToken(Token):
Attributes = {
Attr('name', str, '', 'name of terrain'),
Attr('tile', int, 0, 'local tile-id that represents terrain visually')
}
# ok
class TerraintypesToken(Token):
def __init__(self):
super(TerraintypesToken, self).__init__()
self.terrains = list()
def add_terrain(self, item):
self.terrains.append(item)
def add_layer(self, item):
raise UnsupportedFeature
def add_objectgroup(self, item):
raise UnsupportedFeature
def add_imagelayer(self, item):
raise UnsupportedFeature
def add_group(self, item):
raise UnsupportedFeature
# ok
class ImageToken(Token):
attributes = (
Attr('format', str, None, 'png, jpg, etc'),
Attr('source', str, None, 'path, relative to the map'),
Attr('trans', str, None, 'transparent color'),
Attr('width', int, None, 'pixel width, optional'),
Attr('height', int, None, 'pixel height, optional'),
)
def end(self, content, context):
loader_class = context['image_loader']
loader = loader_class(self.source, None)
self.image = loader()
def add_data(self, item):
# data is used to load image into memory. uses ImageToken.format
raise UnsupportedFeature
Attr('y', float, 0, 'not used, per spec'),
Attr('width', int, None, 'not used, per spec'),
Attr('height', int, None, 'not used, per spec'),
Color, Visible, Opacity
)
def __init__(self):
super(ObjectgroupToken, self).__init__()
self.objects = list()
def add_object(self, item):
self.objects.append(item)
# ok
class PointToken(Token):
""" No attributes defined """
pass
# ok
class PolygonToken(Token):
attributes = (
Attr('points', read_points, None, 'coordinates of the polygon'),
)
# ok
class PolylineToken(Token):
attributes = (
Attr('points', read_points, None, 'coordinates of the polyline'),
)
# ok
class EllipseToken(Token):
""" No attributes defined """
pass
# ok
class FrameToken(Token):
attributes = (
Attr('tileid', int, None, 'local id within parent tileset'),
Attr('duration', int, None, 'duration in milliseconds'),
)
# ok
class GroupToken(Token):
attributes = (
Attr('name', str, None, 'name of group'),
Attr('offsetx', int, 0, 'pixel offset, applied to all descendants'),
Attr('offsety', int, 0, 'pixel offset, applied to all descendants'),
Visible, Opacity
)
def add_layer(self, item):
raise UnsupportedFeature
def add_objectgroup(self, item):
raise UnsupportedFeature
def add_imagelayer(self, item):
raise UnsupportedFeature
Attr('name', str, 'ImageLayer', 'name of layer'),
Attr('offsetx', int, 0, 'not used, per spec.'),
Attr('offsety', int, 0, 'not used, per spec.'),
Visible, Opacity
)
def __init__(self):
super(ImagelayerToken, self).__init__()
self.image = None
def add_image(self, item):
self.image = item
# ok
class LayerToken(Token):
""" TILE LAYER """
attributes = (
Attr('name', str, 'TileLayer', 'name of layer'),
Attr('width', int, None, 'tile width'),
Attr('height', int, None, 'tile height'),
Attr('offsetx', int, 0, 'Not used, per spec'),
Attr('offsety', int, 0, 'Not used, per spec'),
Visible, Opacity
)
def __init__(self):
super(LayerToken, self).__init__()
self.data = None
def add_data(self, data):
self.data = data
Attr('points', read_points, None, 'coordinates of the polyline'),
)
# ok
class PropertiesToken(Token):
def __init__(self):
super(PropertiesToken, self).__init__()
self.dictionary = dict()
def add_property(self, item):
self.dictionary[item.name] = item.value
# ok
class PropertyToken(Token):
attributes = (
Attr('type', noop, None, 'type of the property'),
Attr('name', noop, None, 'name of property'),
Attr('value', noop, None, 'value'),
)
def __init__(self):
super(PropertyToken, self).__init__()
def start(self, init, context):
super(PropertyToken, self).start(init, context)
try:
_type = tiled_property_type[init['type']]
self.attrib['value'] = _type(init['value'])
except KeyError:
self.attrib['value'] = init['value']