def test_table_pos_to_grid(self): b = Board(self.conf) b.add_to_board('2', (0, -1), tile.ROTATIONS.deg0) b.add_to_board('6', (1, 0), tile.ROTATIONS.deg90) b.add_to_board('7', (-1, 0), tile.ROTATIONS.deg270) b.add_to_board('4', (2, 0), tile.ROTATIONS.deg180) self.assertEquals(Renderer.table_pos_to_grid(0, 0, b), (-1, 0)) self.assertEquals(Renderer.table_pos_to_grid(3, 0, b), (2, 0))
def test_pos_to_tile_xy(self): pos = {'x' : 20, 'y': 30} x, y = Renderer.pos_to_tile_xy(pos, 0) self.assertTrue(x >= 0) self.assertTrue(y >= 0) self.assertTrue(x <= Renderer.tile_width) self.assertTrue(x <= Renderer.tile_height)
def main(): if len(sys.argv) < 2: sys.stderr.write("Usage: transform_tileset <tileset>\n") return 1 logging.getLogger().setLevel(logging.DEBUG) conf = load_config(sys.argv[1]) validate_tileset_config(conf, set(['city', 'field', 'road'])) new_conf = {} new_conf['tiles'] = {} new_conf['base_tiles'] = {} for name, tile in conf['tiles'].items(): new_conf['base_tiles'][tile['name']] = copy.deepcopy(tile) del new_conf['base_tiles'][tile['name']]['name'] new_conf['tiles'][name] = tile['name'] for name, tile in new_conf['base_tiles'].items(): positions = [] for pos, data in tile['positions'].items(): #print pos, data if 'connection' in data: #print pos x, y = Renderer.pos_to_tile_xy(pos, 0) #print x, y xp = int(float(x)/float(Renderer.tile_width) * 100.0) yp = int(float(y)/float(Renderer.tile_height) * 100.0) #print xp, yp this_pos = {} this_pos['connection'] = data['connection'] this_pos['x'] = xp this_pos['y'] = yp positions.append(this_pos) del tile['positions'] tile['positions'] = positions print json.dumps(new_conf, sort_keys=True, indent=4)
def test_rotate(self): self.assertEquals(Renderer.rotate(0, 0, 0), (0, 0)) self.assertEquals(Renderer.rotate(0, 0, 90), (87, 1)) self.assertEquals(Renderer.rotate(0, 0, 180), (88, 85)) self.assertEquals(Renderer.rotate(0, 0, 270), (2, 87)) self.assertEquals(Renderer.rotate(44, 44, 0), (44, 44)) self.assertEquals(Renderer.rotate(44, 44, 90), (43, 43)) self.assertEquals(Renderer.rotate(44, 44, 180), (44, 42)) self.assertEquals(Renderer.rotate(44, 44, 270), (45, 43)) self.assertEquals(Renderer.rotate(88, 88, 0), (88, 88)) self.assertEquals(Renderer.rotate(88, 88, 90), (1, 87)) self.assertEquals(Renderer.rotate(88, 88, 180), (0, 1)) self.assertEquals(Renderer.rotate(88, 88, 270), (88, 1))
def test_tile_to_id(self): b = Board(self.conf) self.assertEquals(Renderer.tile_to_id(b.grid[(0,0)]), 'starter000') b.add_to_board('2', (0, -1), tile.ROTATIONS.deg0) self.assertEquals(Renderer.tile_to_id(b.grid[(0,-1)]), 'cloister0-10')