diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-12-28 23:26:40 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-12-28 23:26:40 +0300 |
commit | fd60b7426c0191d7275272aec604d272fbc3c420 (patch) | |
tree | 12880a48b56a851870ceefe1979d69547852c4c1 /hercules/code | |
parent | 5e41522f8e2b9b26d2ee4db34f1a7a4cbfe2b194 (diff) | |
download | evol-tools-fd60b7426c0191d7275272aec604d272fbc3c420.tar.gz evol-tools-fd60b7426c0191d7275272aec604d272fbc3c420.tar.bz2 evol-tools-fd60b7426c0191d7275272aec604d272fbc3c420.tar.xz evol-tools-fd60b7426c0191d7275272aec604d272fbc3c420.zip |
hercules: add support for csv maps format
Diffstat (limited to 'hercules/code')
-rw-r--r-- | hercules/code/clienttoserver/maps.py | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/hercules/code/clienttoserver/maps.py b/hercules/code/clienttoserver/maps.py index 1aa9752..995aca1 100644 --- a/hercules/code/clienttoserver/maps.py +++ b/hercules/code/clienttoserver/maps.py @@ -4,9 +4,11 @@ # Author: Andrei Karas (4144) import array +import csv import os import zlib import struct +import StringIO from xml.dom import minidom from code.fileutils import * @@ -53,7 +55,12 @@ def recreateMapCache(): width = int(layer.attributes["width"].value) height = int(layer.attributes["height"].value) encoding = data.attributes["encoding"].value - compression = data.attributes["compression"].value + try: + compression = data.attributes["compression"].value + except: + compression = "" + + tiles = [] if encoding == "base64": binData = data.childNodes[0].data.strip() binData = binData.decode('base64') @@ -64,19 +71,39 @@ def recreateMapCache(): layerData = dc.decompress(binData) arr = array.array("I") arr.fromstring(layerData) + for tile in arr: + if tile == 0: + tileType = 0 + else: + tileType = tile - firstgid; + if tileType == 0 or tileType == 4: + tiles.append(0) + else: + tiles.append(1) + elif encoding == "csv": + binData = data.childNodes[0].data.strip() + f = StringIO.StringIO(binData) + arr = list(csv.reader(f, delimiter=',', quotechar='|')) + for row in arr: + try: + for item in row: + if item != "": + tile = int(item) + if tile == 0: + tileType = 0 + else: + tileType = tile - firstgid; + if tileType == 0 or tileType == 4: + tiles.append(0) + else: + tiles.append(1) + except: + None + f.close() else: print "map format not supported: " + fileName continue - tiles = [] - for tile in arr: - if tile == 0: - tileType = 0 - else: - tileType = tile - firstgid; - if tileType == 0 or tileType == 4: - tiles.append(0) - else: - tiles.append(1) + comp = zlib.compressobj() binData = struct.pack(str(len(tiles))+"B", *tiles) binData = zlib.compress(binData) |