Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/tools/tmx_converter.py b/tools/tmx_converter.py
- index a9dc929..bcfabd3 100755
- --- a/tools/tmx_converter.py
- +++ b/tools/tmx_converter.py
- @@ -49,7 +49,7 @@ other_warp_fields = (
- )
- TILESIZE = 32
- -SEPARATOR = '|'
- +SEPARATOR = '\t'
- MESSAGE = 'This file is generated automatically. All manually changes will be removed when running the Converter.'
- CLIENT_MAPS = 'maps'
- SERVER_WLK = 'data'
- @@ -111,6 +111,8 @@ class ContentHandler(xml.sax.ContentHandler):
- 'name', # name property of the current map
- 'object', # stores properties of the latest <object> tag
- 'mob_ids', # set of all mob types that spawn here
- + 'collision_fgid', # first gid in collision tileset
- + 'collision_lgid', # last gid in collision tileset
- )
- def __init__(self, out, npc_dir, mobs, warps, imports):
- xml.sax.ContentHandler.__init__(self)
- @@ -130,6 +132,8 @@ class ContentHandler(xml.sax.ContentHandler):
- self.imports = imports
- self.object = None
- self.mob_ids = set()
- + self.collision_fgid = 0
- + self.collision_lgid = 0
- def setDocumentLocator(self, loc):
- self.locator = loc
- @@ -162,6 +166,8 @@ class ContentHandler(xml.sax.ContentHandler):
- if name == u'tileset':
- self.tilesets.add(int(attr[u'firstgid']))
- + if attr.get(u'name','').lower().startswith(u'collision'):
- + self.collision_fgid = int(attr[u'firstgid'])
- if name == u'layer' and attr[u'name'].lower().startswith(u'collision'):
- self.width = int(attr[u'width'])
- @@ -169,6 +175,8 @@ class ContentHandler(xml.sax.ContentHandler):
- self.out.write(struct.pack('<HH', self.width, self.height))
- self.state = State.LAYER
- elif self.state is State.LAYER:
- + if name == u'layer' and self.collision_lgid == 0:
- + self.collision_lgid = int(attr[u'firstgid'])-1
- if name == u'data':
- if attr.get(u'encoding','') not in (u'', u'csv', u'base64', u'xml'):
- print('Bad encoding:', attr.get(u'encoding',''))
- @@ -180,9 +188,19 @@ class ContentHandler(xml.sax.ContentHandler):
- 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))
- + if name == u'tile':
- + gid = int(attr.get(u'gid'))
- + if (self.collision_lgid <> 0 and gid >= self.collision_lgid) or ( gid <> 0 and gid < self.collision_fgid):
- + print('bad gid in layer (xml)', self.collision_fgid, gid, self.collision_lgid)
- + return
- + if gid <> 0:
- + self.out.write(chr(int(attr.get(u'gid',0)) - self.collision_fgid))
- + else:
- + self.out.write(chr(0))
- elif self.state is State.FINAL:
- if name == u'object':
- + if attr.get(u'type') == None:
- + return
- obj_type = attr[u'type'].lower()
- x = int(attr[u'x']) / TILESIZE;
- y = int(attr[u'y']) / TILESIZE;
- @@ -240,6 +258,8 @@ class ContentHandler(xml.sax.ContentHandler):
- if name == u'object':
- obj = self.object
- if isinstance(obj, Mob):
- + if not hasattr(obj, u'max_beings') or not hasattr(obj, u'ea_spawn') or not hasattr(obj, u'ea_death'):
- + return
- mob_id = obj.monster_id
- if mob_id < 1000:
- mob_id += 1002
- @@ -249,10 +269,13 @@ class ContentHandler(xml.sax.ContentHandler):
- '%s.gat,%d,%d,%d,%d' % (self.base, obj.x, obj.y, obj.w, obj.h),
- 'monster',
- obj.name,
- - '%d,%d,%d,%d,Mob%s::On%d\n' % (mob_id, obj.max_beings, obj.ea_spawn, obj.ea_death, self.base, mob_id),
- + #'%d,%d,%d,%d,Mob%s::On%d\n' % (mob_id, obj.max_beings, obj.ea_spawn, obj.ea_death, self.base, mob_id),
- + '%d,%d,%d,%d\n' % (mob_id, obj.max_beings, obj.ea_spawn, obj.ea_death),
- ])
- )
- elif isinstance(obj, Warp):
- + if not hasattr(obj, u'dest_map') or not hasattr(obj, u'dest_x') or not hasattr(obj, u'dest_y'):
- + return
- self.warps.write(
- SEPARATOR.join([
- '%s.gat,%d,%d' % (self.base, obj.x, obj.y),
- @@ -266,7 +289,13 @@ 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))
- + if (self.collision_lgid <> 0 and x >= self.collision_lgid) or ( x <> 0 and x < self.collision_fgid):
- + print('bad gid in layer (csv)', self.collision_fgid, x, self.collision_lgid)
- + return
- + if x <> 0:
- + self.out.write(chr(int(x) - self.collision_fgid))
- + else:
- + self.out.write(chr(0))
- elif self.encoding == u'base64':
- data = base64.b64decode(str(self.buffer))
- if self.compression == u'zlib':
- @@ -274,14 +303,28 @@ class ContentHandler(xml.sax.ContentHandler):
- 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',data[i*4:i*4+4])[0]) not in self.tilesets))
- + gid = int(struct.unpack('<I',data[i*4:i*4+4])[0])
- + if (self.collision_lgid <> 0 and gid >= self.collision_lgid) or ( gid <> 0 and gid < self.collision_fgid):
- + print('bad gid in layer (base64)', self.collision_fgid, gid, self.collision_lgid)
- + return
- + if gid <> 0:
- + self.out.write(chr(gid - self.collision_fgid))
- + else:
- + self.out.write(chr(0))
- 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))
- - for mob_id in sorted(self.mob_ids):
- - self.mobs.write('On%d:\n set @mobID, %d;\n callfunc "MobPoints";\n end;\n\n' % (mob_id, mob_id))
- - self.mobs.write(' end;\n}\n')
- + #self.mobs.write(
- + # SEPARATOR.join([
- + # '\n\n%s.gat,0,0,0' % (self.base),
- + # 'script',
- + # 'Mob%s' % (self.base),
- + # '-1,{\n',
- + # ])
- + #)
- + #for mob_id in sorted(self.mob_ids):
- + # self.mobs.write('On%d:\n set @mobID, %d;\n callfunc "MobPoints";\n end;\n\n' % (mob_id, mob_id))
- + #self.mobs.write(' end;\n}\n')
- self.imports.write('// Map %s: %s\n' % (self.base, self.name))
- self.imports.write('// %s\n' % MESSAGE)
- self.imports.write('map: %s.gat\n' % self.base)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement