comparison 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
comparison
equal deleted inserted replaced
51:efd2b1ca5b77 52:2444937929ae
31 31
32 def _ParseVector(self, line): 32 def _ParseVector(self, line):
33 return map(int, self.Parse(line)) 33 return map(int, self.Parse(line))
34 34
35 def _ParseList(self, lines): 35 def _ParseList(self, lines):
36 #return [self._ParseVector(line) for line in lines] 36 return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))]
37 tuples = []
38
39 #print ''.join(lines)
40 #print _pattern.split(''.join(lines))
41
42 for item in _pattern.finditer(''.join(lines)):
43 #print item.groups()
44 #tuples.append((int(item.group(1)), int(item.group(2))))
45 tuples.append(map(int, item.groups()))
46
47 #print tuples
48 return tuples
49 #print tuples
50
51 #return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))]
52 37
53 def ReadDefinition(filename): 38 def ReadDefinition(filename):
54 def FilterLines(lines): 39 def FilterLines(lines):
55 for line in map(string.strip, lines): 40 for line in map(string.strip, lines):
56 if line and not line.startswith('#'): 41 if line and not line.startswith('#'):
66 direction = definition[2] 51 direction = definition[2]
67 grid = definition[3:] 52 grid = definition[3:]
68 53
69 return MapDefinition(size, position, direction, grid) 54 return MapDefinition(size, position, direction, grid)
70 55
56 def Compile(input_map, output_map):
57 if os.path.isfile(input_map):
58 definition = ReadDefinition(input_map)
59 if not definition:
60 print 'Failed to read definition "%s"' % input_map
61
62 else:
63 folder = os.path.dirname(output_map)
64
65 if not os.path.isdir(folder):
66 os.makedirs(folder)
67
68 print 'Building %s from %s' % (os.path.basename(output_map), os.path.basename(input_map))
69 definition.Write(output_map)
70
71 if __name__ == '__main__': 71 if __name__ == '__main__':
72 path_root = os.path.dirname(sys.argv[0]) 72 path_root = os.path.dirname(sys.argv[0])
73 path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps')) 73 path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps'))
74 path_build = os.path.abspath(os.path.join(path_root, '..', 'Data', 'Maps')) 74 path_build = os.path.abspath(os.path.join(path_root, '..', 'Data', 'Maps'))
75 75
76 if os.path.isdir(path_assets): 76 if len(sys.argv) > 1:
77 for filename in os.listdir(path_assets): 77 Compile(os.path.join(path_assets, sys.argv[1]), os.path.join(path_build, os.path.splitext(sys.argv[1])[0] + '.map'))
78 if not filename.endswith('.def'):
79 continue
80 78
81 definition = ReadDefinition(os.path.join(path_assets, filename)) 79 else:
82 if not definition:
83 continue
84 80
85 output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map') 81 if os.path.isdir(path_assets):
86 folder = os.path.dirname(output) 82 for filename in os.listdir(path_assets):
83 if not filename.endswith('.def'):
84 continue
87 85
88 if not os.path.isdir(folder): 86 Compile(os.path.join(path_assets, filename), os.path.join(path_build, os.path.splitext(filename)[0] + '.map'))
89 os.makedirs(folder) 87 #definition = ReadDefinition(os.path.join(path_assets, filename))
88 #if not definition:
89 # continue
90 90
91 print 'Building %s from %s' % (os.path.basename(output), os.path.basename(filename)) 91 #output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map')
92 definition.Write(output) 92 #folder = os.path.dirname(output)
93
94 #if not os.path.isdir(folder):
95 # os.makedirs(folder)
96
97 #print 'Building %s from %s' % (os.path.basename(output), os.path.basename(filename))
98 #definition.Write(output)