Mercurial > LightClone
diff LightTools/build.py @ 51:efd2b1ca5b77
Clean up gui
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Tue, 27 Sep 2011 09:42:01 -0700 |
parents | a379bce1aeb1 |
children | 2444937929ae |
line wrap: on
line diff
--- a/LightTools/build.py Fri Sep 23 17:58:17 2011 -0700 +++ b/LightTools/build.py Tue Sep 27 09:42:01 2011 -0700 @@ -7,16 +7,17 @@ import struct import os import functools +import re + +_pattern = re.compile('\(\s*(\d+)\s*,\s*(\d+)\s*\)') class MapDefinition: Parse = functools.partial(string.split, sep=',') - def __init__(self, size, position, direction, fcount, functions, grid): + def __init__(self, size, position, direction, grid): self.Size = self._ParseVector(size) self.Position = self._ParseVector(position) self.Direction = self._ParseVector(direction) - self.Count = self._ParseVector(fcount) - self.Functions = self._ParseList(functions) self.Grid = self._ParseList(grid) def Write(self, filename): @@ -24,10 +25,6 @@ handle.write(struct.pack('i' * len(self.Size), *self.Size)) # 8 handle.write(struct.pack('i' * len(self.Position), *self.Position)) # 8 handle.write(struct.pack('i' * len(self.Direction), *self.Direction)) # 4 - handle.write(struct.pack('i' * len(self.Count), *self.Count)) # 4 - - for function in self.Functions: - handle.write(struct.pack('i' * len(function), *function)) # 4 * Count for tower in self.Grid: handle.write(struct.pack('i' * len(tower), *tower)) # 8 * Size.X * Size.Y @@ -36,7 +33,22 @@ return map(int, self.Parse(line)) def _ParseList(self, lines): - return [self._ParseVector(line) for line in 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))] def ReadDefinition(filename): def FilterLines(lines): @@ -49,22 +61,13 @@ definition = tuple(FilterLines(lines)) - offset = 0 - size = definition[offset] - offset += 1 - position = definition[offset] - offset += 1 - direction = definition[offset] - offset += 1 - fcount = definition[offset] - offset += 1 - length = int(fcount) - functions = definition[offset:offset+length] - offset += length - grid = definition[offset:] + size = definition[0] + position = definition[1] + direction = definition[2] + grid = definition[3:] - return MapDefinition(size, position, direction, fcount, functions, grid) - + return MapDefinition(size, position, direction, grid) + if __name__ == '__main__': path_root = os.path.dirname(sys.argv[0]) path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps'))