summaryrefslogtreecommitdiff
path: root/tools/tmx_converter.py
diff options
context:
space:
mode:
authorsebbu <zsbe17fr@yahoo.fr>2012-08-13 19:58:32 +0200
committerJessica Tölke <jtoelke@mail.upb.de>2012-08-13 22:02:21 +0200
commit8354fcfa4fc66738aedd4189a195e6ebf7414c9e (patch)
tree40fc3f0d805395c0106a2f187fffea40eb0b52d8 /tools/tmx_converter.py
parente485f7a5566b5e699dc96ea612004793a706ba96 (diff)
downloadserverdata-8354fcfa4fc66738aedd4189a195e6ebf7414c9e.tar.gz
serverdata-8354fcfa4fc66738aedd4189a195e6ebf7414c9e.tar.bz2
serverdata-8354fcfa4fc66738aedd4189a195e6ebf7414c9e.tar.xz
serverdata-8354fcfa4fc66738aedd4189a195e6ebf7414c9e.zip
Added plain base64 encoding and xml encoding
Diffstat (limited to 'tools/tmx_converter.py')
-rwxr-xr-xtools/tmx_converter.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/tools/tmx_converter.py b/tools/tmx_converter.py
index bb88ecc1..4d4f36e7 100755
--- a/tools/tmx_converter.py
+++ b/tools/tmx_converter.py
@@ -170,15 +170,17 @@ class ContentHandler(xml.sax.ContentHandler):
self.state = State.LAYER
elif self.state is State.LAYER:
if name == u'data':
- if attr[u'encoding'] != u'csv' and attr[u'encoding'] != u'base64':
- print('Bad encoding:', attr[u'encoding'])
+ if attr.get(u'encoding','') not in (u'', u'csv', u'base64', u'xml'):
+ print('Bad encoding:', attr.get(u'encoding',''))
return
self.encoding = attr.get(u'encoding','')
- if attr.get(u'compression','') != '' and attr.get(u'compression','') != 'none' and attr.get(u'compression','') != u'zlib' and attr.get(u'compression','') != u'gzip':
- print('Bad compression:', attr[u'compression'])
+ if attr.get(u'compression','') not in (u'', u'none', u'zlib', u'gzip'):
+ print('Bad compression:', attr.get(u'compression',''))
return
self.compression = attr.get(u'compression','')
self.state = State.DATA
+ elif self.state is State.DATA:
+ self.out.write(chr(int(attr.get(u'gid',0)) not in self.tilesets))
elif self.state is State.FINAL:
if name == u'object':
obj_type = attr[u'type'].lower()
@@ -260,21 +262,20 @@ class ContentHandler(xml.sax.ContentHandler):
])
)
- if self.state is State.DATA:
- if self.encoding == u'csv':
- for x in self.buffer.split(','):
- self.out.write(chr(int(x) not in self.tilesets))
- elif self.encoding == u'base64':
- data=base64.b64decode(self.buffer)
- if self.compression == u'zlib':
- data2 = zlib.decompress(data)
- for i in range(self.width*self.height):
- self.out.write(chr(int(struct.unpack('<I',data2[i*4:i*4+4])[0]) not in self.tilesets))
- elif self.compression == u'gzip':
- data2 = zlib.decompressobj().decompress('x\x9c' + data[10:-8])
+ if name == u'data':
+ if self.state is State.DATA:
+ if self.encoding == u'csv':
+ for x in self.buffer.split(','):
+ self.out.write(chr(int(x) not in self.tilesets))
+ elif self.encoding == u'base64':
+ data=base64.b64decode(self.buffer)
+ if self.compression == u'zlib':
+ data = zlib.decompress(data)
+ elif self.compression == u'gzip':
+ data = zlib.decompressobj().decompress('x\x9c' + data[10:-8])
for i in range(self.width*self.height):
- self.out.write(chr(int(struct.unpack('<I',data2[i*4:i*4+4])[0]) not in self.tilesets))
- self.state = State.FINAL
+ self.out.write(chr(int(struct.unpack('<I',data[i*4:i*4+4])[0]) not in self.tilesets))
+ self.state = State.FINAL
def endDocument(self):
self.mobs.write('\n\n%s.gat,0,0,0|script|Mob%s|-1,{\n' % (self.base, self.base))