From 57b70dae6ec54a904699a1387d9b90f65b5f5e41 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 --- tmx_converter.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'tmx_converter.py') 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('