comparison LightTools/build.py @ 62:6d4437a24aeb

Added camera position to level definition
author koryspansel
date Mon, 03 Oct 2011 15:14:41 -0700
parents 2444937929ae
children
comparison
equal deleted inserted replaced
61:1fe27776627e 62:6d4437a24aeb
12 _pattern = re.compile('\(\s*(\d+)\s*,\s*(\d+)\s*\)') 12 _pattern = re.compile('\(\s*(\d+)\s*,\s*(\d+)\s*\)')
13 13
14 class MapDefinition: 14 class MapDefinition:
15 Parse = functools.partial(string.split, sep=',') 15 Parse = functools.partial(string.split, sep=',')
16 16
17 def __init__(self, size, position, direction, grid): 17 def __init__(self, size, position, direction, distance, yaw, pitch, grid):
18 self.Size = self._ParseVector(size) 18 self.Size = self._ParseVector(size)
19 self.Position = self._ParseVector(position) 19 self.Position = self._ParseVector(position)
20 self.Direction = self._ParseVector(direction) 20 self.Direction = self._ParseVector(direction)
21 self.Distance = self._ParseVectorF(distance)
22 self.Yaw = self._ParseVectorF(yaw)
23 self.Pitch = self._ParseVectorF(pitch)
21 self.Grid = self._ParseList(grid) 24 self.Grid = self._ParseList(grid)
22 25
23 def Write(self, filename): 26 def Write(self, filename):
24 with open(filename, 'wb') as handle: 27 with open(filename, 'wb') as handle:
25 handle.write(struct.pack('i' * len(self.Size), *self.Size)) # 8 28 handle.write(struct.pack('i' * len(self.Size), *self.Size)) # 8
26 handle.write(struct.pack('i' * len(self.Position), *self.Position)) # 8 29 handle.write(struct.pack('i' * len(self.Position), *self.Position)) # 8
27 handle.write(struct.pack('i' * len(self.Direction), *self.Direction)) # 4 30 handle.write(struct.pack('i' * len(self.Direction), *self.Direction)) # 4
31 handle.write(struct.pack('f' * len(self.Distance), *self.Distance)) # 4
32 handle.write(struct.pack('f' * len(self.Yaw), *self.Yaw)) # 4
33 handle.write(struct.pack('f' * len(self.Pitch), *self.Pitch)) # 4
28 34
29 for tower in self.Grid: 35 for tower in self.Grid:
30 handle.write(struct.pack('i' * len(tower), *tower)) # 8 * Size.X * Size.Y 36 handle.write(struct.pack('i' * len(tower), *tower)) # 8 * Size.X * Size.Y
31 37
32 def _ParseVector(self, line): 38 def _ParseVector(self, line):
33 return map(int, self.Parse(line)) 39 return map(int, self.Parse(line))
40
41 def _ParseVectorF(self, line):
42 return map(float, self.Parse(line))
34 43
35 def _ParseList(self, lines): 44 def _ParseList(self, lines):
36 return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))] 45 return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))]
37 46
38 def ReadDefinition(filename): 47 def ReadDefinition(filename):
47 definition = tuple(FilterLines(lines)) 56 definition = tuple(FilterLines(lines))
48 57
49 size = definition[0] 58 size = definition[0]
50 position = definition[1] 59 position = definition[1]
51 direction = definition[2] 60 direction = definition[2]
52 grid = definition[3:] 61 distance = definition[3]
62 yaw = definition[4]
63 pitch = definition[5]
64 grid = definition[6:]
53 65
54 return MapDefinition(size, position, direction, grid) 66 return MapDefinition(size, position, direction, distance, yaw, pitch, grid)
55 67
56 def Compile(input_map, output_map): 68 def Compile(input_map, output_map):
57 if os.path.isfile(input_map): 69 if os.path.isfile(input_map):
58 definition = ReadDefinition(input_map) 70 definition = ReadDefinition(input_map)
59 if not definition: 71 if not definition:
82 for filename in os.listdir(path_assets): 94 for filename in os.listdir(path_assets):
83 if not filename.endswith('.def'): 95 if not filename.endswith('.def'):
84 continue 96 continue
85 97
86 Compile(os.path.join(path_assets, filename), os.path.join(path_build, os.path.splitext(filename)[0] + '.map')) 98 Compile(os.path.join(path_assets, filename), os.path.join(path_build, os.path.splitext(filename)[0] + '.map'))
87 #definition = ReadDefinition(os.path.join(path_assets, filename))
88 #if not definition:
89 # continue
90
91 #output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map')
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)