summaryrefslogtreecommitdiff
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
commit57b70dae6ec54a904699a1387d9b90f65b5f5e41 (patch)
tree183e2ba56080ff8c1f8e342b8da63f2390f46d34
parentf0b034684a20ae2d5b8ebb4efd2996532452af00 (diff)
downloadtools-57b70dae6ec54a904699a1387d9b90f65b5f5e41.tar.gz
tools-57b70dae6ec54a904699a1387d9b90f65b5f5e41.tar.bz2
tools-57b70dae6ec54a904699a1387d9b90f65b5f5e41.tar.xz
tools-57b70dae6ec54a904699a1387d9b90f65b5f5e41.zip
Added plain base64 encoding and xml encoding
-rwxr-xr-xtmx_converter.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/tmx_converter.py b/tmx_converter.py
index bb88ecc..4d4f36e 100755
--- a/tmx_converter.py
+++ b/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))