diff options
author | gumi <git@gumi.ca> | 2018-03-25 12:48:37 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2018-03-25 12:48:37 -0400 |
commit | ecf8231758afdd5e44defdd3424bf543f3a95e02 (patch) | |
tree | eab335ff3cad8ec67605105a532d500d1e66cdf2 | |
parent | 1b5bc0c799492d5461ecbffa3406409abce0615c (diff) | |
download | evol-tools-ecf8231758afdd5e44defdd3424bf543f3a95e02.tar.gz evol-tools-ecf8231758afdd5e44defdd3424bf543f3a95e02.tar.bz2 evol-tools-ecf8231758afdd5e44defdd3424bf543f3a95e02.tar.xz evol-tools-ecf8231758afdd5e44defdd3424bf543f3a95e02.zip |
add support for map anchors in tmx_converter
-rwxr-xr-x | hercules/tmx_converter.py | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/hercules/tmx_converter.py b/hercules/tmx_converter.py index 82cdc98..3e8a938 100755 --- a/hercules/tmx_converter.py +++ b/hercules/tmx_converter.py @@ -62,6 +62,7 @@ NPC_SAVES = '_savepoints.txt' NPC_WARPS = '_warps.txt' NPC_IMPORTS = '_import.txt' NPC_MASTER_IMPORTS = NPC_IMPORTS +NPC_MASTER_ANCHORS = '_anchors.txt' class State(object): pass @@ -96,6 +97,10 @@ class Save(Object): 'inn', ) +class Anchor(Object): + __slots__ = ( + ) + class Warp(Object): __slots__ = ( 'dest_map', @@ -110,26 +115,27 @@ class Warp(Object): class ContentHandler(xml.sax.ContentHandler): __slots__ = ( - 'locator', # keeps track of location in document - 'state', # state of height info - 'tilesets', # first gid of each tileset - 'buffer', # characters within a section - 'encoding', # encoding of layer data - 'compression', # compression of layer data - 'width', # width of the height layer - 'height', # height of the height layer - 'firstgid', # first gid of height layer - 'heightmap',# height map - 'base', # base name of current map - 'npc_dir', # world/map/npc/<base> - 'mobs', # open file to _mobs.txt - 'warps', # open file to _warps.txt - 'imports', # open file to _import.txt - '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 + 'locator', # keeps track of location in document + 'state', # state of height info + 'tilesets', # first gid of each tileset + 'buffer', # characters within a section + 'encoding', # encoding of layer data + 'compression', # compression of layer data + 'width', # width of the height layer + 'height', # height of the height layer + 'firstgid', # first gid of height layer + 'heightmap', # height map + 'base', # base name of current map + 'npc_dir', # world/map/npc/<base> + 'mobs', # open file to _mobs.txt + 'warps', # open file to _warps.txt + 'imports', # open file to _import.txt + '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 + 'anchor_master', # list of all anchors ) - def __init__(self, npc_dir, mobs, saves, warps, imports): + def __init__(self, npc_dir, mobs, saves, warps, imports, anchor_master): xml.sax.ContentHandler.__init__(self) self.locator = None self.state = State.INITIAL @@ -147,6 +153,7 @@ class ContentHandler(xml.sax.ContentHandler): self.saves = saves self.warps = warps self.imports = imports + self.anchor_master = anchor_master self.object = None self.mob_ids = set() self.mob_cnt = False @@ -233,6 +240,12 @@ class ContentHandler(xml.sax.ContentHandler): y += h/2 w -= 2 h -= 2 + elif obj_type == 'anchor': + self.object = Anchor() + x += w/2 + y += h/2 + w -= 2 + h -= 2 elif obj_type == 'warp': self.object = Warp() x += w/2 @@ -309,6 +322,8 @@ class ContentHandler(xml.sax.ContentHandler): ]) ) self.save_cnt = True + elif isinstance(obj, Anchor): + self.anchor_master.append(' htput(.ht, "%s", "%s %d %d");\n' % (obj.name.upper(), self.base, obj.x, obj.y)) elif isinstance(obj, Warp): if (obj.npc_id == u'WARP'): obj_name = "#%s_%s_%s" % (self.base, obj.x, obj.y) @@ -383,6 +398,7 @@ def main(argv): continue npc_master = [] + anchor_master = [] map_basenames = [] map_conf = open(posixpath.join(server_data,MAP_CONF), 'w') @@ -402,7 +418,7 @@ def main(argv): with open(posixpath.join(main.this_map_npc_dir, NPC_SAVES), 'w') as saves: with open(posixpath.join(main.this_map_npc_dir, NPC_WARPS), 'w') as warps: with open(posixpath.join(main.this_map_npc_dir, NPC_IMPORTS), 'w') as imports: - xml.sax.parse(tmx, ContentHandler(main.this_map_npc_dir, mobs, saves, warps, imports)) + xml.sax.parse(tmx, ContentHandler(main.this_map_npc_dir, mobs, saves, warps, imports, anchor_master)) if os.path.isfile(posixpath.join(main.this_map_npc_dir, NPC_IMPORTS)): npc_master.append('@include "%s"\n' % posixpath.join(SERVER_NPCS, base, NPC_IMPORTS)) @@ -411,11 +427,21 @@ def main(argv): map_conf.write(' "%s",\n' % (arg.split('.')[0])) map_count += 1 map_conf.write(")\n") + with open(posixpath.join(npc_dir, NPC_MASTER_ANCHORS), 'w') as out: + out.write('// %s\n\n' % MESSAGE) + out.write('-\tscript\t__anchors__\t32767,{\n') + out.write('OnInit:\n') + out.write(' .ht = htnew();\n'); + anchor_master.sort() + for line in anchor_master: + out.write(line) + out.write('}\n') with open(posixpath.join(npc_dir, NPC_MASTER_IMPORTS), 'w') as out: out.write('// %s\n\n' % MESSAGE) npc_master.sort() for line in npc_master: out.write(line) + out.write('"%s",\n' % posixpath.join(SERVER_NPCS, NPC_MASTER_ANCHORS)); if __name__ == '__main__': main(sys.argv) |