コード例 #1
0
 def setUp(self):
     self.layer = TileLayer()
     tile = Tile(1)
     self.layer.set_tile(20, 0, tile)
     self.layer.set_tile(20, 1, tile)
     for i in range(5):
         self.layer.tiles[40 + i] = tile
     for i in range(10):
         self.layer.tiles[240 + i] = tile
     for i in range(6):
         self.layer.tiles[295 + i * 50] = tile
     self.layer.tiles[2402] = tile
     self.layer.tiles[2403] = tile
     self.layer.tiles[2452] = tile
コード例 #2
0
 def test_init(self):
     layer = TileLayer()
     self.assertEqual(layer.width, 50)
     self.assertEqual(layer.height, 50)
     layer = TileLayer(100, 200, 'Tee')
     self.assertEqual(layer.width, 100)
     self.assertEqual(layer.height, 200)
     self.assertEqual(layer.name, 'Tee')
     self.assertEqual(len(layer.tiles), 20000)
     self.assertEqual(layer.game, 0)
     self.assertEqual(layer.color_env, -1)
     self.assertEqual(layer.color_env_offset, 0)
     self.assertEqual(layer.image_id, -1)
     self.assertEqual(layer.color, (255, 255, 255, 255))
コード例 #3
0
    def test_draw(self):
        layer = TileLayer(10, 5)
        tile = Tile(10)
        layer.set_tile(0, 0, tile)
        layer.set_tile(0, 4, tile)
        layer.set_tile(9, 0, tile)
        layer.set_tile(9, 4, tile)
        self.layer.set_tile(10, 5, Tile(5))

        self.layer.draw(0, 0, layer)
        self.assertEqual(self.layer.get_tile(0, 0).index, 10)
        self.assertEqual(self.layer.get_tile(0, 4).index, 10)
        self.assertEqual(self.layer.get_tile(9, 0).index, 10)
        self.assertEqual(self.layer.get_tile(9, 4).index, 10)
        self.assertEqual(self.layer.get_tile(10, 5).index, 5)

        # assert offset
        self.layer.draw(5, 3, layer)
        self.assertEqual(self.layer.get_tile(5, 3).index, 10)
        self.assertEqual(self.layer.get_tile(5, 7).index, 10)
        self.assertEqual(self.layer.get_tile(14, 3).index, 10)
        self.assertEqual(self.layer.get_tile(14, 7).index, 10)
        self.assertEqual(self.layer.get_tile(10, 5).index, 0)

        # assert clamping
        self.layer.draw(49, 48, layer)
        self.assertEqual(self.layer.get_tile(49, 48).index, 10)
        self.assertEqual(self.layer.get_tile(49, 49).index, 0)
コード例 #4
0
ファイル: test_items.py プロジェクト: heinrich5991/tml
 def setUp(self):
     self.layer = TileLayer()
     tile = Tile()
     tile.index = 1
     for i in range(5):
         self.layer.tiles[40 + i] = tile
     for i in range(10):
         self.layer.tiles[240 + i] = tile
     for i in range(6):
         self.layer.tiles[295 + i * 50] = tile
     self.layer.tiles[2402] = tile
     self.layer.tiles[2403] = tile
     self.layer.tiles[2452] = tile
コード例 #5
0
class TestTileLayer(unittest.TestCase):

    def setUp(self):
        self.layer = TileLayer()
        tile = Tile(1)
        self.layer.set_tile(20, 0, tile)
        self.layer.set_tile(20, 1, tile)
        for i in range(5):
            self.layer.tiles[40 + i] = tile
        for i in range(10):
            self.layer.tiles[240 + i] = tile
        for i in range(6):
            self.layer.tiles[295 + i * 50] = tile
        self.layer.tiles[2402] = tile
        self.layer.tiles[2403] = tile
        self.layer.tiles[2452] = tile

    def test_init(self):
        layer = TileLayer()
        self.assertEqual(layer.width, 50)
        self.assertEqual(layer.height, 50)
        layer = TileLayer(100, 200, 'Tee')
        self.assertEqual(layer.width, 100)
        self.assertEqual(layer.height, 200)
        self.assertEqual(layer.name, 'Tee')
        self.assertEqual(len(layer.tiles), 20000)
        self.assertEqual(layer.game, 0)
        self.assertEqual(layer.color_env, -1)
        self.assertEqual(layer.color_env_offset, 0)
        self.assertEqual(layer.image_id, -1)
        self.assertEqual(layer.color, (255, 255, 255, 255))

    def test_get_tile(self):
        for i in range(5):
            self.assertEqual(self.layer.get_tile(40 + i, 0),
                             self.layer.tiles[40 + i])
        for i in range(10):
            self.assertEqual(self.layer.get_tile(40 + i, 4),
                             self.layer.tiles[240 + i])
        self.assertRaises(ValueError, self.layer.get_tile, 50, 49)
        self.assertRaises(ValueError, self.layer.get_tile, -1, 49)
        self.assertRaises(ValueError, self.layer.get_tile, 49, 50)
        self.assertRaises(ValueError, self.layer.get_tile, 49, -1)

    def test_set_tile(self):
        tile = Tile(20)
        for i in range(5):
            self.layer.set_tile(40 + i, 0, tile)
            self.assertEqual(self.layer.tiles[40 + i], tile)
        for i in range(10):
            self.layer.set_tile(40 + i, 10, tile)
            self.assertEqual(self.layer.tiles[540 + i], tile)
        self.assertRaises(ValueError, self.layer.set_tile, 50, 49, tile)
        self.assertRaises(ValueError, self.layer.set_tile, -1, 49, tile)
        self.assertRaises(ValueError, self.layer.set_tile, 49, 50, tile)
        self.assertRaises(ValueError, self.layer.set_tile, 49, -1, tile)

    def test_select(self):
        layer = self.layer.select(40, 4)
        self.assertEqual(len(layer.tiles), 1)
        self.assertEqual(layer.tiles[0].index, 1)

        layer = self.layer.select(39, 4)
        self.assertEqual(len(layer.tiles), 1)
        self.assertEqual(layer.tiles[0].index, 0)

        layer = self.layer.select(43, 0, 5, 6)
        self.assertEqual(len(layer.tiles), 30)
        for tile in layer.tiles[:2]:
            self.assertEqual(tile.index, 1)
        for tile in layer.tiles[2:20]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[20:25]:
            self.assertEqual(tile.index, 1)
        for tile in layer.tiles[25:27]:
            self.assertEqual(tile.index, 0)
        self.assertEqual(layer.tiles[27].index, 1)
        for tile in layer.tiles[28:30]:
            self.assertEqual(tile.index, 0)

        # clamping test to the right
        layer = self.layer.select(45, 3, 7, 4)
        self.assertEqual(len(layer.tiles), 20)
        for tile in layer.tiles[:5]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[5:10]:
            self.assertEqual(tile.index, 1)
        self.assertEqual(layer.tiles[10].index, 1)
        for tile in layer.tiles[11:15]:
            self.assertEqual(tile.index, 0)
        self.assertEqual(layer.tiles[15].index, 1)
        for tile in layer.tiles[16:20]:
            self.assertEqual(tile.index, 0)

        # clamping test to the bottom
        layer = self.layer.select(2, 47, 2, 4)
        self.assertEqual(len(layer.tiles), 6)
        for tile in layer.tiles[:2]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[2:5]:
            self.assertEqual(tile.index, 1)
        self.assertEqual(layer.tiles[5].index, 0)

    def test_resizing(self):
        self.assertEqual(self.layer.width, 50)
        self.assertEqual(self.layer.height, 50)

        self.layer.width = 25
        self.assertEqual(self.layer.width, 25)
        self.assertEqual(len(self.layer.tiles), 25 * 50)
        self.layer.height = 25
        self.assertEqual(self.layer.height, 25)
        self.assertEqual(len(self.layer.tiles), 25 * 25)
        self.assertEqual(self.layer.tiles[20].index, 1)
        self.assertEqual(self.layer.tiles[45].index, 1)

        self.layer.width = 100
        self.assertEqual(self.layer.width, 100)
        self.assertEqual(len(self.layer.tiles), 100 * 25)
        self.layer.height = 100
        self.assertEqual(self.layer.height, 100)
        self.assertEqual(len(self.layer.tiles), 100 * 100)
        self.assertEqual(self.layer.get_tile(20, 0).index, 1)
        self.assertEqual(self.layer.get_tile(20, 1).index, 1)

        with self.assertRaises(ValueError):
            self.layer.width = -1
        with self.assertRaises(ValueError):
            self.layer.height = -1

    def test_draw(self):
        layer = TileLayer(10, 5)
        tile = Tile(10)
        layer.set_tile(0, 0, tile)
        layer.set_tile(0, 4, tile)
        layer.set_tile(9, 0, tile)
        layer.set_tile(9, 4, tile)
        self.layer.set_tile(10, 5, Tile(5))

        self.layer.draw(0, 0, layer)
        self.assertEqual(self.layer.get_tile(0, 0).index, 10)
        self.assertEqual(self.layer.get_tile(0, 4).index, 10)
        self.assertEqual(self.layer.get_tile(9, 0).index, 10)
        self.assertEqual(self.layer.get_tile(9, 4).index, 10)
        self.assertEqual(self.layer.get_tile(10, 5).index, 5)

        # assert offset
        self.layer.draw(5, 3, layer)
        self.assertEqual(self.layer.get_tile(5, 3).index, 10)
        self.assertEqual(self.layer.get_tile(5, 7).index, 10)
        self.assertEqual(self.layer.get_tile(14, 3).index, 10)
        self.assertEqual(self.layer.get_tile(14, 7).index, 10)
        self.assertEqual(self.layer.get_tile(10, 5).index, 0)

        # assert clamping
        self.layer.draw(49, 48, layer)
        self.assertEqual(self.layer.get_tile(49, 48).index, 10)
        self.assertEqual(self.layer.get_tile(49, 49).index, 0)
コード例 #6
0
ファイル: test_items.py プロジェクト: heinrich5991/tml
class TestTileLayer(unittest.TestCase):

    def setUp(self):
        self.layer = TileLayer()
        tile = Tile()
        tile.index = 1
        for i in range(5):
            self.layer.tiles[40 + i] = tile
        for i in range(10):
            self.layer.tiles[240 + i] = tile
        for i in range(6):
            self.layer.tiles[295 + i * 50] = tile
        self.layer.tiles[2402] = tile
        self.layer.tiles[2403] = tile
        self.layer.tiles[2452] = tile

    def test_init(self):
        layer = TileLayer()
        self.assertEqual(layer.width, 50)
        self.assertEqual(layer.height, 50)
        layer = TileLayer(100, 200, 'Tee')
        self.assertEqual(layer.width, 100)
        self.assertEqual(layer.height, 200)
        self.assertEqual(layer.name, 'Tee')
        self.assertEqual(len(layer.tiles), 20000)
        self.assertEqual(layer.game, 0)
        self.assertEqual(layer.color_env, -1)
        self.assertEqual(layer.color_env_offset, 0)
        self.assertEqual(layer.image_id, -1)
        self.assertEqual(layer.color, {'r': 255, 'g': 255, 'b': 255, 'a': 255})

    def test_get_tile(self):
        for i in range(5):
            self.assertEqual(self.layer.get_tile(40 + i, 0),
                             self.layer.tiles[40 + i])
        for i in range(10):
            self.assertEqual(self.layer.get_tile(40 + i, 4),
                             self.layer.tiles[240 + i])

    def test_select(self):
        layer = self.layer.select(40, 4)
        self.assertEqual(len(layer.tiles), 1)
        self.assertEqual(layer.tiles[0].index, 1)

        layer = self.layer.select(39, 4)
        self.assertEqual(len(layer.tiles), 1)
        self.assertEqual(layer.tiles[0].index, 0)

        layer = self.layer.select(43, 0, 5, 6)
        self.assertEqual(len(layer.tiles), 30)
        for tile in layer.tiles[:2]:
            self.assertEqual(tile.index, 1)
        for tile in layer.tiles[2:20]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[20:25]:
            self.assertEqual(tile.index, 1)
        for tile in layer.tiles[25:27]:
            self.assertEqual(tile.index, 0)
        self.assertEqual(layer.tiles[27].index, 1)
        for tile in layer.tiles[28:30]:
            self.assertEqual(tile.index, 0)

        # clamping test to the right
        layer = self.layer.select(45, 3, 7, 4)
        self.assertEqual(len(layer.tiles), 20)
        for tile in layer.tiles[:5]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[5:10]:
            self.assertEqual(tile.index, 1)
        self.assertEqual(layer.tiles[10].index, 1)
        for tile in layer.tiles[11:15]:
            self.assertEqual(tile.index, 0)
        self.assertEqual(layer.tiles[15].index, 1)
        for tile in layer.tiles[16:20]:
            self.assertEqual(tile.index, 0)

        # clamping test to the bottom
        layer = self.layer.select(2, 47, 2, 4)
        self.assertEqual(len(layer.tiles), 6)
        for tile in layer.tiles[:2]:
            self.assertEqual(tile.index, 0)
        for tile in layer.tiles[2:5]:
            self.assertEqual(tile.index, 1)
        self.assertEqual(layer.tiles[5].index, 0)