Beispiel #1
0
    def test_fromxml__rect_py__height_0(self):
        map_height = 128
        tilesets = None
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="64" y="0"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == map_height

        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="64" y="128"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == 0
Beispiel #2
0
 def test_fromxml__polygon_px(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="98" y="46">
        <polygon points="0,0 -64,0 -64,32 0,32"/>
       </object>
     """
     vertices_tiled_relative = [
         v2(0, 0), v2(-64, 0), v2(-64, 32),
         v2(0, 32)
     ]
     vertices_tiled_absolute = [
         v + v2(98, 46) for v in vertices_tiled_relative
     ]
     vertices_gl_abs = [
         v2(x, map_height - y) for x, y in vertices_tiled_absolute
     ]
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     # on the other way,
     vertices_gl_relative = [v2(*p) for p in tmx_obj.points]
     pos = v2(tmx_obj.px, tmx_obj.py)
     vertices_gl_absolute = [v + pos for v in vertices_gl_relative]
     # so it must hold
     assert vertices_gl_absolute == vertices_gl_abs
     # and, being (px, py) the bottomleft corner of bounding box must be
     assert 0 == min([y for x, y in tmx_obj.points])
Beispiel #3
0
    def test_fromxml__rect_py__height_0(self):
        map_height = 128
        tilesets = None
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="64" y="0"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == map_height

        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="64" y="128"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == 0
Beispiel #4
0
 def test_fromxml__name__explicit(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object name="custom name" x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.name == "custom name"
Beispiel #5
0
 def test_fromxml__usertype__implicit(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.usertype == None
Beispiel #6
0
 def test_fromxml__usertype__explicit__encoding(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object type="\xc3\xad i with acute acent" x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.usertype == "í i with acute acent"
Beispiel #7
0
 def test_fromxml__usertype__explicit__encoding(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object type="\xc3\xad i with acute acent" x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.usertype == "í i with acute acent"
Beispiel #8
0
 def test_fromxml__usertype__implicit(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.usertype == None
Beispiel #9
0
 def test_fromxml__name__explicit(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object name="custom name" x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.name == "custom name"
Beispiel #10
0
 def test_fromxml__rect_width_and_height__XY(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object name="bottom_left" x="0" y="96" width="12" height="57"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.width == 12
     assert tmx_obj.height == 57
Beispiel #11
0
 def test_fromxml__rect_width_and_height__00(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.width == 0
     assert tmx_obj.height == 0
Beispiel #12
0
 def test_fromxml__rect_width_and_height__XY(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object name="bottom_left" x="0" y="96" width="12" height="57"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.width == 12
     assert tmx_obj.height == 57
Beispiel #13
0
 def test_fromxml__rect_width_and_height__00(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="256" y="0"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.width == 0
     assert tmx_obj.height == 0
Beispiel #14
0
 def test_fromxml__polyline_tmxtype(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="76" y="18">
        <polyline points="0,0 12,34 55,31"/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "polyline"
Beispiel #15
0
 def test_fromxml__polygon_tmxtype(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="98" y="46">
        <polygon points="0,0 24,-3 17,12"/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "polygon"
Beispiel #16
0
 def test_fromxml__ellipse_tmxtype(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="128" y="34">
        <ellipse/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "ellipse"
Beispiel #17
0
 def test_fromxml__polygon_px(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="98" y="46">
        <polygon points="0,0 24,-3 17,12"/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.px == min([x+98 for x,y in tmx_obj.points])
Beispiel #18
0
    def test_fromxml__rect_py__height_nonzero(self):
        map_height = 128
        tilesets = None
        # topleft pixel in the map, covers [0.0, 1.0] x [0.0, 1.0] in Tiled space,
        # in gl coords covers [0.0, 1.0] x [mh-1, mh]  (mh=map_height)
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="0" y="0" width="1" height="1"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == map_height - 1

        # bottomleft pixel in the map, covers [0.0, 1.0] x [mh-1, mh] in Tiled space,
        # in gl coords covers [0.0, 1.0] x [0.0, 1.0]
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="0" y="127" width="1" height="1"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == 0
Beispiel #19
0
 def test_fromxml__ellipse_tmxtype(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="128" y="34">
        <ellipse/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "ellipse"
Beispiel #20
0
 def test_fromxml__polyline_tmxtype(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="76" y="18">
        <polyline points="0,0 12,34 55,31"/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "polyline"
Beispiel #21
0
    def test_fromxml__rect_py__height_nonzero(self):
        map_height = 128
        tilesets = None
        # topleft pixel in the map, covers [0.0, 1.0] x [0.0, 1.0] in Tiled space,
        # in gl coords covers [0.0, 1.0] x [mh-1, mh]  (mh=map_height)
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="0" y="0" width="1" height="1"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == map_height - 1

        # bottomleft pixel in the map, covers [0.0, 1.0] x [mh-1, mh] in Tiled space,
        # in gl coords covers [0.0, 1.0] x [0.0, 1.0]
        obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
          <object x="0" y="127" width="1" height="1"/>
        """
        xml_obj = ET.fromstring(obj_string)
        tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
        assert tmx_obj.py == 0
Beispiel #22
0
 def test_fromxml__polygon_width_and_height(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="98" y="46">
        <polygon points="0,0 24,-3 17,12"/>
       </object>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.width == 25
     assert tmx_obj.height == 16
Beispiel #23
0
 def test_fromxml__tile_tmxtype(self):
     map_height = 128
     class TI(object):
         class IM(object):
             width = 64
             height = 32
         image = IM()
     tilesets = [{1: TI()}]
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object gid="1" x="154" y="43"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "tile"
Beispiel #24
0
 def test_fromxml__tile_tmxtype(self):
     map_height = 128
     class TI(object):
         class IM(object):
             width = 64
             height = 32
         image = IM()
     tilesets = [{1: TI()}]
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
         <object gid="1" x="154" y="43"/>
     """
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     assert tmx_obj.tmxtype == "tile"
Beispiel #25
0
 def test_fromxml__polygon_px(self):
     map_height = 128
     tilesets = None
     obj_string = b"""<?xml version="1.0" encoding="UTF-8"?>
       <object x="98" y="46">
        <polygon points="0,0 -64,0 -64,32 0,32"/>
       </object>
     """
     vertices_tiled_relative = [v2(0,0), v2(-64,0), v2(-64,32), v2(0,32)]
     vertices_tiled_absolute = [v+v2(98, 46) for v in vertices_tiled_relative]
     vertices_gl_abs = [v2(x, map_height-y) for x,y in vertices_tiled_absolute]
     xml_obj = ET.fromstring(obj_string)
     tmx_obj = TmxObject.fromxml(xml_obj, tilesets, map_height)
     # on the other way,
     vertices_gl_relative = [v2(*p) for p in tmx_obj.points]
     pos = v2(tmx_obj.px, tmx_obj.py)
     vertices_gl_absolute = [ v+pos for v in vertices_gl_relative]
     # so it must hold
     assert vertices_gl_absolute == vertices_gl_abs
     # and, being (px, py) the bottomleft corner of bounding box must be
     assert 0 == min([y for x,y in tmx_obj.points])