Mercurial > mamba
view scripts/partition_helper @ 420:66df5a3c748a
TODO maintainance
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 17 Sep 2011 17:00:25 +0200 |
parents | 20b424c5c1ef |
children | fca61cd8fc33 |
line wrap: on
line source
#!/usr/bin/env python HEIGHT_PARTITIONS = ( (2,2), (2,3), (2,5), (2,6), ) WIDTH_PARTITIONS = ( (1,3), (2,2), (2,4), (2,5), ) SAVE_LOCATION = "data/levels/templates" def partition(total, parts, sepwidth=1): seps = parts - 1 space = total - 2 - sepwidth * seps return float(space) / parts def find_partitions(num, sepwidth): partitions = [] for i in range(2, num): size = partition(num, i, sepwidth) if size > 0 and int(size) == size: partitions.append((i, size)) return partitions def print_all(): height = ["FLOOR HEIGHT: PARTS x PART HEIGHT"] for sepwidth in range(1, 28): partitions = find_partitions(30, sepwidth) if partitions: height.append("%s: %s" % (sepwidth, " ".join([" %dx%d" % (i, size) for (i, size) in partitions]))) width = ["COLUMN WIDTH: PARTS x PART WIDTH"] for sepwidth in range(1, 38): partitions = find_partitions(40, sepwidth) if partitions: width.append("%s: %s" % (sepwidth, " ".join([" %dx%d" % (i, size) for (i, size) in partitions]))) height.extend([""] * 6) height = [l.ljust(50) for l in height] pairs = zip(height, width) print "\n".join(["%s %s" % p for p in pairs]) def make_partition(height, width): sepheight, hparts = height pheight = int(partition(30, hparts, sepheight)) sepwidth, wparts = width pwidth = int(partition(40, wparts, sepwidth)) wsep = 'X' * sepwidth partrow = 'X' + wsep.join(['.' * pwidth for i in range(wparts)]) + 'X' partblock = '\n'.join([partrow for i in range(pheight)]) + '\n' seprow = 'X' * 40 sepblock = '\n'.join([seprow for i in range(sepheight)]) + '\n' level = '%s\n%s%s' % (seprow, sepblock.join([partblock for i in range(hparts)]), seprow) level = level[:162] + 'E' + level[163:1190] + 'e' + level[1191:] dims = '%dx%d'% (wparts, hparts) f = open('%s/%s.txt' % (SAVE_LOCATION, dims), 'w') f.write('%s template\n' % dims) f.write('lab\n') f.write('test.ogg\n') f.write(level + '\n') f.write('end\n') f.close() def generate_partitions(): for height in HEIGHT_PARTITIONS: for width in WIDTH_PARTITIONS: make_partition(height, width) if __name__ == "__main__": generate_partitions()