# HG changeset patch # User koryspansel # Date 1316727335 25200 # Node ID a379bce1aeb1e69af75ac1495509af433a2c55a1 # Parent 50def8c971d980ad9688a519ede547e8fc85b369 Rename map.py to build.py; Add release script diff -r 50def8c971d9 -r a379bce1aeb1 .hgignore --- a/.hgignore Thu Sep 22 13:41:29 2011 -0700 +++ b/.hgignore Thu Sep 22 14:35:35 2011 -0700 @@ -9,4 +9,5 @@ Assets\UI\*.jpg Assets\UI\*.gif Bin\* -Intermediate\* \ No newline at end of file +Intermediate\* +LightTools\Build\* \ No newline at end of file diff -r 50def8c971d9 -r a379bce1aeb1 LightTools/Map.py --- a/LightTools/Map.py Thu Sep 22 13:41:29 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -# -# Map -# - -import sys -import string -import struct -import os -import functools - -class MapDefinition: - Parse = functools.partial(string.split, sep=',') - - def __init__(self, size, position, direction, fcount, functions, 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): - with open(filename, 'wb') as handle: - 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 - - def _ParseVector(self, line): - return map(int, self.Parse(line)) - - def _ParseList(self, lines): - return [self._ParseVector(line) for line in lines] - -def ReadDefinition(filename): - def FilterLines(lines): - for line in map(string.strip, lines): - if line and not line.startswith('#'): - yield line.split('#')[0] - - with open(filename, 'rt') as handle: - lines = handle.readlines() - - 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:] - - return MapDefinition(size, position, direction, fcount, functions, grid) - -#if __name__ == '__main__': -# if len(sys.argv) < 2: -# print 'Usage: Map [output]' -# sys.exit() -# -# path_input = os.path.abspath(sys.argv[1]) -# path_output = os.path.splitext(path_input)[0] + '.map' -# -# if len(sys.argv) > 2: -# path_output = os.path.abspath(sys.argv[2]) -# if os.path.isdir(path_output): -# path_output += os.path.splitext(os.path.basename(path_input))[0] + '.map' -# -# definition = ReadDefinition(path_input) -# if definition: -# print 'Building %s from %s' % (os.path.basename(path_output), os.path.basename(path_input)) -# definition.Write(path_output) - -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 - - definition = ReadDefinition(os.path.join(path_assets, filename)) - if not definition: - continue - - output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map') - folder = os.path.dirname(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) diff -r 50def8c971d9 -r a379bce1aeb1 LightTools/build.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightTools/build.py Thu Sep 22 14:35:35 2011 -0700 @@ -0,0 +1,89 @@ +# +# build +# + +import sys +import string +import struct +import os +import functools + +class MapDefinition: + Parse = functools.partial(string.split, sep=',') + + def __init__(self, size, position, direction, fcount, functions, 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): + with open(filename, 'wb') as handle: + 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 + + def _ParseVector(self, line): + return map(int, self.Parse(line)) + + def _ParseList(self, lines): + return [self._ParseVector(line) for line in lines] + +def ReadDefinition(filename): + def FilterLines(lines): + for line in map(string.strip, lines): + if line and not line.startswith('#'): + yield line.split('#')[0] + + with open(filename, 'rt') as handle: + lines = handle.readlines() + + 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:] + + return MapDefinition(size, position, direction, fcount, functions, grid) + +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 + + definition = ReadDefinition(os.path.join(path_assets, filename)) + if not definition: + continue + + output = os.path.join(path_build, os.path.splitext(filename)[0] + '.map') + folder = os.path.dirname(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) diff -r 50def8c971d9 -r a379bce1aeb1 LightTools/release.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LightTools/release.py Thu Sep 22 14:35:35 2011 -0700 @@ -0,0 +1,65 @@ +# +# release +# + +from os.path import join, isdir, isfile, dirname, basename, normpath + +import tempfile +import os +import sys +import shutil +import zipfile +import datetime + +def relative_walk(path): + for root, folders, files in os.walk(path): + for filename in files: + yield join(root, filename)[len(path)+1:] + +def release_project(root, location, project, target=None, build='Build'): + if target: + executable = join(root, project, 'bin', target, project + '.exe') + + else: + executable = join(root, project, 'bin', 'release', project + '.exe') + if not isfile(executable): + executable = join(root, project, 'bin', 'debug', project + '.exe') + + if not isfile(executable): + raise Exception('Error: Could not locate executable') + + data = join(root, 'data') + + if not isdir(data): + raise Exception('Error: Could not locate data folder') + + if isdir(build): + shutil.rmtree(build, True) + + os.makedirs(build) + + shutil.copyfile(executable, join(build, basename(executable))) + + for filename in relative_walk(data): + filepath = join(build, filename) + + if not isdir(dirname(filepath)): + os.makedirs(dirname(filepath)) + + shutil.copyfile(join(data, filename), filepath) + + if not isdir(location): + os.makedirs(location) + + current_date = datetime.datetime.now() + suffix = current_date.strftime('%Y%m%d%I%M%p') + print suffix + + with zipfile.ZipFile(join(location, project + '.zip'), 'w') as handle: + for filename in relative_walk(build): + handle.write(join(build, filename), filename) + +if __name__ == '__main__': + root = normpath(join(dirname(sys.argv[0]), '..')) + + release_project(root, '..\Release', 'LightClone') \ No newline at end of file