comparison LightTools/Map.py @ 45:50def8c971d9

Move build functionality into map.py
author koryspansel
date Thu, 22 Sep 2011 13:41:29 -0700
parents 7e3a0ae9c016
children
comparison
equal deleted inserted replaced
44:6790cf9e8bd8 45:50def8c971d9
63 offset += length 63 offset += length
64 grid = definition[offset:] 64 grid = definition[offset:]
65 65
66 return MapDefinition(size, position, direction, fcount, functions, grid) 66 return MapDefinition(size, position, direction, fcount, functions, grid)
67 67
68 #if __name__ == '__main__':
69 # if len(sys.argv) < 2:
70 # print 'Usage: Map <map> [output]'
71 # sys.exit()
72 #
73 # path_input = os.path.abspath(sys.argv[1])
74 # path_output = os.path.splitext(path_input)[0] + '.map'
75 #
76 # if len(sys.argv) > 2:
77 # path_output = os.path.abspath(sys.argv[2])
78 # if os.path.isdir(path_output):
79 # path_output += os.path.splitext(os.path.basename(path_input))[0] + '.map'
80 #
81 # definition = ReadDefinition(path_input)
82 # if definition:
83 # print 'Building %s from %s' % (os.path.basename(path_output), os.path.basename(path_input))
84 # definition.Write(path_output)
85
68 if __name__ == '__main__': 86 if __name__ == '__main__':
69 if len(sys.argv) < 2: 87 path_root = os.path.dirname(sys.argv[0])
70 print 'Usage: Map <map> [output]' 88 path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps'))
71 sys.exit() 89 path_build = os.path.abspath(os.path.join(path_root, '..', 'Data', 'Maps'))
72 90
73 path_input = os.path.abspath(sys.argv[1]) 91 if os.path.isdir(path_assets):
74 path_output = os.path.splitext(path_input)[0] + '.map' 92 for filename in os.listdir(path_assets):
93 if not filename.endswith('.def'):
94 continue
75 95
76 if len(sys.argv) > 2: 96 definition = ReadDefinition(os.path.join(path_assets, filename))
77 path_output = os.path.abspath(sys.argv[2]) 97 if not definition:
78 if os.path.isdir(path_output): 98 continue
79 path_output += os.path.splitext(os.path.basename(path_input))[0] + '.map'
80 99
81 definition = ReadDefinition(path_input) 100 output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map')
82 if definition: 101 folder = os.path.dirname(output)
83 print 'Building %s from %s' % (os.path.basename(path_output), os.path.basename(path_input)) 102
84 definition.Write(path_output) 103 if not os.path.isdir(folder):
104 os.makedirs(folder)
105
106 print 'Building %s from %s' % (os.path.basename(output), os.path.basename(filename))
107 definition.Write(output)