From 8354fcfa4fc66738aedd4189a195e6ebf7414c9e Mon Sep 17 00:00:00 2001 From: sebbu Date: Mon, 13 Aug 2012 19:58:32 +0200 Subject: Added plain base64 encoding and xml encoding --- tools/tmx_converter.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'tools') 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('