Пример #1
0
def export(filename, formMain, curActiveLayout):
    path, fname = os.path.split(filename)
    fnameWithoutExt, fnameExt = os.path.splitext(fname)
    
    layout = ConfigScript.getLayout(curActiveLayout)
    levelRec = ConfigScript.getLevelRec(curActiveLayout)
    curScale = 1#formMain.CurScale
    
    blockWidth = int(formMain.Layers[0].blockWidth * curScale);
    blockHeight = int(formMain.Layers[0].blockHeight * curScale);
    scrLevelNo = levelRec.levelNo;
    
    width = ConfigScript.getScreenWidth(scrLevelNo);
    height = ConfigScript.getScreenHeight(scrLevelNo);
    if ConfigScript.getScreenVertical():
        mapSize = (layout.width * height, layout.height * width)
    else:
        mapSize = (layout.width * width, layout.height * height)
    
    tileSize = (blockWidth, blockHeight)
    
    #generate tiles
    #TODO: rescale it to curScale
    bigBlocksImages = formMain.BigBlocks
    ImWidthInBlocks = 16
    ImHeightInBlocks = int(ceil(len(bigBlocksImages)*1.0/ImWidthInBlocks))
    bigBlockImage = UtilsGDI.GlueImages(bigBlocksImages, ImWidthInBlocks, ImHeightInBlocks)
    #bigBlockImage = UtilsGDI.GlueImages(bigBlocksImages, len(bigBlocksImages), 1)
    bigBlockImage.Save(os.path.join(path, fnameWithoutExt + ".png"))
    
    map = tmxlib.Map(mapSize, tileSize , base_path=".")
    im = tmxlib.image.open(fnameWithoutExt + ".png", base_path=path)
    tileset = tmxlib.ImageTileset("Tiles", tileSize, im, base_path = ".")
    map.tilesets.append(tileset)
    layer = map.add_layer("Layer1")
    for sy in xrange(layout.height):
        for sx in xrange(layout.width):
            scrIndex = sy * layout.width + sx
            scrNo = calcScrNo(layout, scrIndex)
            if scrNo >= 0 and scrNo < len(formMain.Layers[0].screens):
                curScreen = formMain.Layers[0].screens[scrNo]
                for y in xrange(height):
                    for x in xrange(width):
                        if ConfigScript.getScreenVertical():
                            cx, cy = y, x
                        else:
                            cx, cy = x, y
                        index = y * width + x
                        tileNo =  ConfigScript.getBigTileNoFromScreen(curScreen, index)
                        lx = sx * width + cx
                        ly = sy * height + cy
                        layer[lx,ly] = map.tilesets["Tiles"][tileNo]
    map.save(filename)
    return True
Пример #2
0
def test_multiple_tilesets():
    map = tmxlib.Map.open(get_test_filename('desert_and_walls.tmx'))

    def check_names(names_string):
        names = names_string.split()
        assert [l.name for l in map.tilesets] == names

    check_names('Desert Walls')

    walls = map.tilesets[1]
    walls2 = tmxlib.ImageTileset('Walls2',
                                 tile_size=(20, 20),
                                 image=map.tilesets[0].image)
    map.tilesets.append(walls2)
    check_names('Desert Walls Walls2')

    assert walls2.first_gid(map) == walls.first_gid(map) + len(walls) == 65
    assert any(t.tileset is walls for t in map.all_tiles())
    assert not any(t.tileset is walls2 for t in map.all_tiles())

    building = map.layers['Building']
    tile = building[1, 1]
    assert tile.tileset is walls
    assert tile.gid == walls.first_gid(map) + tile.number
    assert walls.first_gid(map) < building[1, 1].gid < walls2.first_gid(map)
    assert map.end_gid == 182

    map.tilesets.move('Walls2', -1)
    check_names('Desert Walls2 Walls')
    print(tile.gid, walls.first_gid(map))
    print(tile.tileset_tile)
    assert tile.tileset is walls
    assert tile.gid == walls.first_gid(map) + tile.number
    assert walls2.first_gid(map) < walls.first_gid(map) < building[1, 1].gid
    assert map.end_gid == 182

    assert any(t.tileset is walls for t in map.all_tiles())
    assert not any(t.tileset is walls2 for t in map.all_tiles())
    assert map.end_gid == 182

    map.tilesets.move('Walls2', 1)
    assert tile.tileset is walls
    assert tile.gid == walls.first_gid(map) + tile.number
    assert walls.first_gid(map) < building[1, 1].gid < walls2.first_gid(map)
    assert map.end_gid == 182

    del map.tilesets['Walls2']
    assert tile.tileset is walls
    assert tile.gid == walls.first_gid(map) + tile.number
    assert map.end_gid == 65

    del map.layers[:]
    del map.tilesets[:]
    assert map.end_gid == 0
Пример #3
0
 def tileset_class(self, *args, **kwargs):
     import tmxlib
     if 'image' in kwargs:
         return tmxlib.ImageTileset(*args, **kwargs)
     else:
         return tmxlib.IndividualTileTileset(*args, **kwargs)
Пример #4
0
def make_tileset(name, image_path, tile_size=(32,32)):
    image = tmxlib.image.open(image_path)
    tileset = tmxlib.ImageTileset(name=name, tile_size=tile_size, image=image)

    return tileset