Mercurial > LightClone
diff LightTools/build.py @ 52:2444937929ae
Update map building script
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Tue, 27 Sep 2011 13:30:10 -0700 |
parents | efd2b1ca5b77 |
children | 6d4437a24aeb |
line wrap: on
line diff
--- a/LightTools/build.py Tue Sep 27 09:42:01 2011 -0700 +++ b/LightTools/build.py Tue Sep 27 13:30:10 2011 -0700 @@ -33,22 +33,7 @@ return map(int, self.Parse(line)) def _ParseList(self, lines): - #return [self._ParseVector(line) for line in lines] - tuples = [] - - #print ''.join(lines) - #print _pattern.split(''.join(lines)) - - for item in _pattern.finditer(''.join(lines)): - #print item.groups() - #tuples.append((int(item.group(1)), int(item.group(2)))) - tuples.append(map(int, item.groups())) - - #print tuples - return tuples - #print tuples - - #return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))] + return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))] def ReadDefinition(filename): def FilterLines(lines): @@ -68,25 +53,46 @@ return MapDefinition(size, position, direction, grid) +def Compile(input_map, output_map): + if os.path.isfile(input_map): + definition = ReadDefinition(input_map) + if not definition: + print 'Failed to read definition "%s"' % input_map + + else: + folder = os.path.dirname(output_map) + + if not os.path.isdir(folder): + os.makedirs(folder) + + print 'Building %s from %s' % (os.path.basename(output_map), os.path.basename(input_map)) + definition.Write(output_map) + if __name__ == '__main__': path_root = os.path.dirname(sys.argv[0]) path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps')) path_build = os.path.abspath(os.path.join(path_root, '..', 'Data', 'Maps')) - if os.path.isdir(path_assets): - for filename in os.listdir(path_assets): - if not filename.endswith('.def'): - continue + if len(sys.argv) > 1: + Compile(os.path.join(path_assets, sys.argv[1]), os.path.join(path_build, os.path.splitext(sys.argv[1])[0] + '.map')) + + else: - definition = ReadDefinition(os.path.join(path_assets, filename)) - if not definition: - continue + if os.path.isdir(path_assets): + for filename in os.listdir(path_assets): + if not filename.endswith('.def'): + continue - output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map') - folder = os.path.dirname(output) + Compile(os.path.join(path_assets, filename), os.path.join(path_build, os.path.splitext(filename)[0] + '.map')) + #definition = ReadDefinition(os.path.join(path_assets, filename)) + #if not definition: + # continue - if not os.path.isdir(folder): - os.makedirs(folder) + #output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map') + #folder = os.path.dirname(output) - print 'Building %s from %s' % (os.path.basename(output), os.path.basename(filename)) - definition.Write(output) + #if not os.path.isdir(folder): + # os.makedirs(folder) + + #print 'Building %s from %s' % (os.path.basename(output), os.path.basename(filename)) + #definition.Write(output)