Ejemplo n.º 1
0
 def _dict_helper(cls, dct, layer, **kwargs):
     helpers.assert_item(dct, 'visible', True)
     self = cls(layer=layer,
                pixel_pos=(dct.pop('x'), dct.pop('y')),
                name=dct.pop('name', None),
                type=dct.pop('type', None),
                **kwargs)
     self.properties.update(dct.pop('properties', {}))
     return self
Ejemplo n.º 2
0
 def _dict_helper(cls, dct, layer, **kwargs):
     helpers.assert_item(dct, 'visible', True)
     self = cls(
             layer=layer,
             pixel_pos=(dct.pop('x'), dct.pop('y')),
             name=dct.pop('name', None),
             type=dct.pop('type', None),
             **kwargs
         )
     self.properties.update(dct.pop('properties', {}))
     return self
Ejemplo n.º 3
0
 def from_dict(cls, dct, map):
     """Import from a dict compatible with Tiled's JSON plugin"""
     helpers.assert_item(dct, 'type', 'tilelayer')
     helpers.assert_item(dct, 'width', map.width)
     helpers.assert_item(dct, 'height', map.height)
     helpers.assert_item(dct, 'x', 0)
     helpers.assert_item(dct, 'y', 0)
     self = cls(
             map=map,
             name=dct.pop('name'),
             visible=dct.pop('visible', True),
             opacity=dct.pop('opacity', 1),
             data=dct.pop('data'),
         )
     self.properties.update(dct.pop('properties', {}))
     return self
Ejemplo n.º 4
0
 def from_dict(cls, dct, map):
     """Import from a dict compatible with Tiled's JSON plugin"""
     helpers.assert_item(dct, 'type', 'imagelayer')
     helpers.assert_item(dct, 'width', map.width)
     helpers.assert_item(dct, 'height', map.height)
     helpers.assert_item(dct, 'x', 0)
     helpers.assert_item(dct, 'y', 0)
     self = cls(
             map=map,
             name=dct.pop('name'),
             visible=dct.pop('visible', True),
             opacity=dct.pop('opacity', 1),
             image=image.open(dct.pop('image')),
         )
     self.properties.update(dct.pop('properties', {}))
     return self
Ejemplo n.º 5
0
 def from_dict(cls, dct, map):
     """Import from a dict compatible with Tiled's JSON plugin"""
     helpers.assert_item(dct, 'type', 'imagelayer')
     helpers.assert_item(dct, 'width', map.width)
     helpers.assert_item(dct, 'height', map.height)
     helpers.assert_item(dct, 'x', 0)
     helpers.assert_item(dct, 'y', 0)
     self = cls(
             map=map,
             name=dct.pop('name'),
             visible=dct.pop('visible', True),
             opacity=dct.pop('opacity', 1),
             image=image.open(dct.pop('image')),
         )
     if getattr(map, 'base_path', None):
         self.image.base_path = map.base_path
         self.base_path = map.base_path
     self.properties.update(dct.pop('properties', {}))
     return self
Ejemplo n.º 6
0
 def from_dict(cls, dct, map):
     """Import from a dict compatible with Tiled's JSON plugin"""
     helpers.assert_item(dct, 'type', 'objectgroup')
     helpers.assert_item(dct, 'width', map.width)
     helpers.assert_item(dct, 'height', map.height)
     helpers.assert_item(dct, 'x', 0)
     helpers.assert_item(dct, 'y', 0)
     color = dct.pop('color', None)
     if color:
         color = fileio.from_hexcolor(color)
     self = cls(
             map=map,
             name=dct.pop('name'),
             visible=dct.pop('visible', True),
             opacity=dct.pop('opacity', 1),
             color=color,
         )
     self.properties.update(dct.pop('properties', {}))
     for obj in dct.pop('objects', {}):
         self.append(mapobject.MapObject.from_dict(obj, self))
     return self
Ejemplo n.º 7
0
 def from_dict(cls, dct, map):
     """Import from a dict compatible with Tiled's JSON plugin"""
     helpers.assert_item(dct, 'type', 'objectgroup')
     helpers.assert_item(dct, 'width', map.width)
     helpers.assert_item(dct, 'height', map.height)
     helpers.assert_item(dct, 'x', 0)
     helpers.assert_item(dct, 'y', 0)
     color = dct.pop('color', None)
     if color:
         color = fileio.from_hexcolor(color)
     self = cls(
             map=map,
             name=dct.pop('name'),
             visible=dct.pop('visible', True),
             opacity=dct.pop('opacity', 1),
             color=color,
         )
     self.properties.update(dct.pop('properties', {}))
     for obj in dct.pop('objects', {}):
         self.append(mapobject.MapObject.from_dict(obj, self))
     return self
Ejemplo n.º 8
0
def test_assert_item():
    dct = {'key': 'value', 'key2': 'bad value'}
    helpers.assert_item(dct, 'key', 'value')
    assert list(dct.keys()) == ['key2']
    with pytest.raises(KeyError):
        helpers.assert_item(dct, 'key', 'value')
    with pytest.raises(ValueError):
        helpers.assert_item(dct, 'key2', 'good value')