1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# -*- coding: utf8 -*-
#
# Copyright (C) 2014 Evol Online
# Author: Andrei Karas (4144)
import zlib
from code.fileutils import readInt16, readInt32, makeDir, copyFile, readFile, readMapName, saveFile, readData
from code.tileutils import getTileData, getTile
def covertToTmx(f, mapsCount):
destDir = "clientdata/"
mapsDir = destDir + "maps/"
tilesetsDir = destDir + "graphics/tilesets/"
templatesDir = "templates/"
makeDir(mapsDir)
makeDir(tilesetsDir)
copyFile(templatesDir, tilesetsDir, "collision.png")
copyFile(templatesDir, tilesetsDir, "tileset.png")
tmx = readFile("templates/template.tmx")
for i in xrange(0, mapsCount):
name = readMapName(f)
print("converting map [{0:4}/{1:4}]: {2}".format(i, mapsCount + 1, name))
sx = readInt16(f)
sy = readInt16(f)
sz = readInt32(f)
mapData = readData(f, sz)
dc = zlib.decompressobj()
mapData = dc.decompress(mapData)
ground = ""
collision = ""
fringe = ""
for y in xrange(0, sy):
for x in xrange(0, sx):
tileData = getTileData(mapData, x, y, sx)
tile = getTile(tileData)
if x + 1 == sx and y + 1 == sy:
ground = ground + tile[0]
collision = collision + tile[1]
fringe = fringe + "0"
else:
ground = ground + tile[0] + ","
collision = collision + tile[1] + ","
fringe = fringe + "0,"
ground = ground + "\n"
collision = collision + "\n"
fringe = fringe + "\n"
saveFile(mapsDir + name + ".tmx", tmx.format(sx, sy, ground, collision, fringe))
|