summaryrefslogtreecommitdiff
path: root/utils/update-map-names.py
blob: 82743900e0315468e5297eae7b859479e39149df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python2

"""
Author: Joseph Botosh <rumly111@gmail.com>
Licence: GPLv2.
"""

import os
import sys
import pytmx


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('Usage: {} <maps-dir>'.format(sys.argv[0]))
        sys.exit(0)

    dirname = sys.argv[1]

    for tmx in (filter(lambda f: f.endswith('.tmx'),
                       os.listdir(dirname))):
        path = os.path.join(dirname, tmx)
        maptag = tmx[:-4]
        m = pytmx.TiledMap(filename=path)
        try:
            if 'name' in m.properties:
                mapname = m.properties['name']
            else:
                mapname = m.properties['Name']
            print maptag, mapname
        except KeyError:
            print '[error]', maptag