From da13ee5c99cc285119914c20feedeab31bc038b7 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 5 Feb 2013 12:44:06 -0800 Subject: make tmx_converter compatible with python 2.6 --- tools/tmx_converter.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/tmx_converter.py b/tools/tmx_converter.py index 4d4f36e7..a9dc9294 100755 --- a/tools/tmx_converter.py +++ b/tools/tmx_converter.py @@ -34,12 +34,12 @@ import zlib dump_all = False # wall of text # lower case versions of everything except 'spawn' and 'warp' -other_object_types = { +other_object_types = set([ 'particle_effect', 'npc', # not interpreted by client 'script', # for ManaServ 'fixme', # flag for things that didn't have a type before -} +]) # Somebody has put ManaServ fields in our data! other_spawn_fields = ( @@ -117,7 +117,7 @@ class ContentHandler(xml.sax.ContentHandler): self.locator = None self.out = open(out, 'w') self.state = State.INITIAL - self.tilesets = {0} # consider the null tile as its own tileset + self.tilesets = set([0]) # consider the null tile as its own tileset self.buffer = bytearray() self.encoding = None self.compression = None @@ -268,7 +268,7 @@ class ContentHandler(xml.sax.ContentHandler): 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) + data = base64.b64decode(str(self.buffer)) if self.compression == u'zlib': data = zlib.decompress(data) elif self.compression == u'gzip': @@ -314,10 +314,10 @@ def main(argv): this_map_npc_dir = posixpath.join(npc_dir, base) os.path.isdir(this_map_npc_dir) or os.mkdir(this_map_npc_dir) print('Converting %s to %s' % (tmx, wlk)) - with open(posixpath.join(this_map_npc_dir, NPC_MOBS), 'w') as mobs, \ - open(posixpath.join(this_map_npc_dir, NPC_WARPS), 'w') as warps, \ - open(posixpath.join(this_map_npc_dir, NPC_IMPORTS), 'w') as imports: - xml.sax.parse(tmx, ContentHandler(wlk, this_map_npc_dir, mobs, warps, imports)) + with open(posixpath.join(this_map_npc_dir, NPC_MOBS), 'w') as mobs: + with open(posixpath.join(this_map_npc_dir, NPC_WARPS), 'w') as warps: + with open(posixpath.join(this_map_npc_dir, NPC_IMPORTS), 'w') as imports: + xml.sax.parse(tmx, ContentHandler(wlk, this_map_npc_dir, mobs, warps, imports)) npc_master.append('import: %s\n' % posixpath.join(SERVER_NPCS, base, NPC_IMPORTS)) with open(posixpath.join(npc_dir, NPC_MASTER_IMPORTS), 'w') as out: -- cgit v1.2.3-70-g09d2