예제 #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
예제 #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])
예제 #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
예제 #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"
예제 #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
예제 #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"
예제 #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"
예제 #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
예제 #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"
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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"
예제 #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"
예제 #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"
예제 #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])
예제 #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
예제 #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"
예제 #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"
예제 #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
예제 #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
예제 #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"
예제 #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"
예제 #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])