diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-11-02 22:48:23 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2018-11-02 22:48:23 -0300 |
commit | 7c5e51f21c1cddcb6c8709d275b64f20a98776af (patch) | |
tree | 5e0366ef8a5bcf6e8cf66afb2426136c2ad98e23 /hercules | |
parent | 2fd4281a9cc0b5ee0e812d8eea31358d3e1273d8 (diff) | |
download | tools-7c5e51f21c1cddcb6c8709d275b64f20a98776af.tar.gz tools-7c5e51f21c1cddcb6c8709d275b64f20a98776af.tar.bz2 tools-7c5e51f21c1cddcb6c8709d275b64f20a98776af.tar.xz tools-7c5e51f21c1cddcb6c8709d275b64f20a98776af.zip |
Updates by Andrei Karas
+ Some stuff by Jesusalva which got in because -a flag
Diffstat (limited to 'hercules')
-rw-r--r-- | hercules/code/clienttoserver/maps.py | 23 | ||||
-rwxr-xr-x | hercules/tmx_converter.py | 3 |
2 files changed, 19 insertions, 7 deletions
diff --git a/hercules/code/clienttoserver/maps.py b/hercules/code/clienttoserver/maps.py index 06b7eb5..0f8e773 100644 --- a/hercules/code/clienttoserver/maps.py +++ b/hercules/code/clienttoserver/maps.py @@ -52,10 +52,13 @@ def findFirstGid(tilesets, tile): # 4 - sit, walkable ground # 5 - none # 6 - monster walk not allowed -def convertTileType(tile): +def convertTileType(tile, idx, width, height): if tile == 5: tile = 0; - if tile > 128 or tile < 0: + if tile > 6 or tile < 0: + y = int(idx / width) + x = idx - y * width + print "Error: wrong tile: ({0}, {1}) = {2}".format(x, y, tile) tile = 1 return tile @@ -74,6 +77,7 @@ def recreateMap(names): tmxName = names[0] mCaheName = destDir + names[1][:-3] + "mcache" with open(mCaheName, "wb") as w: + print tmxName dom = minidom.parse(tmxName) root = dom.documentElement tilesets = [] @@ -106,17 +110,20 @@ def recreateMap(names): layerData = dc.decompress(binData) arr = array.array("I") arr.fromstring(layerData) + idx = 0 for tile in arr: if tile == 0: tileType = 0 else: firstgid = findFirstGid(tilesets, tile) - tileType = convertTileType(tile - firstgid); + tileType = convertTileType(tile - firstgid, idx, width, height); tiles.append(tileType) + idx = idx + 1 elif encoding == "csv": binData = data.childNodes[0].data.strip() f = StringIO.StringIO(binData) arr = list(csv.reader(f, delimiter=',', quotechar='|')) + idx = 0 for row in arr: for item in row: if item != "": @@ -125,7 +132,7 @@ def recreateMap(names): tileType = 0 else: firstgid = findFirstGid(tilesets, tile) - tileType = convertTileType(tile - firstgid); + tileType = convertTileType(tile - firstgid, idx, width, height); # tmx collision format # 0 - walkable ground # 1 - non walkable wall @@ -146,6 +153,7 @@ def recreateMap(names): if tileType > 128 or tileType < 0: tileType = 1 tiles.append(tileType) + idx = idx + 1 f.close() else: print "map format not supported: " + tmxName @@ -165,7 +173,12 @@ def recreateMap(names): break if found == False: print "Error: missing collision layer in file: {0}".format(tmxName) - + return + return + with open(mCaheName + ".debug", "wb") as w: + writeInt16(w, width) + writeInt16(w, height) + writeData(w, struct.pack(str(len(tiles))+"B", *tiles)) def recreateMapCache(): diff --git a/hercules/tmx_converter.py b/hercules/tmx_converter.py index 3b56a7b..f2b40c0 100755 --- a/hercules/tmx_converter.py +++ b/hercules/tmx_converter.py @@ -333,10 +333,9 @@ class ContentHandler(xml.sax.ContentHandler): elif isinstance(obj, Warp): if (obj.npc_id == u'WARP'): obj_name = "#%s_%s_%s" % (self.base, obj.x, obj.y) - y_offset = int(self.heightmap[((obj.y * self.width) + obj.x)])/2 self.warps.write( SEPARATOR.join([ - '%s,%d,%d,0\t' % (self.base, obj.x, (obj.y + y_offset)), + '%s,%d,%d,0\t' % (self.base, obj.x, obj.y), 'warp\t', '%s\t%s,%s,%s,%d,%d\n' % (obj_name, obj.w, obj.h, obj.dest_map, obj.dest_x, obj.dest_y), ]) |