0

gallery.py Python3 refactor

This commit is contained in:
Ben Steadman
2019-03-22 18:52:47 +00:00
parent 4e3a861c9c
commit 7516cd0c25

View File

@@ -2,39 +2,47 @@
Outputs a huge image with all currently-supported block textures. Outputs a huge image with all currently-supported block textures.
""" """
from overviewer_core import textures import argparse
from PIL import Image
import sys import sys
import Image import os
if len(sys.argv) != 2: # incantation to be able to import overviewer_core
print "usage: %s [output.png]" % (sys.argv[0],) if not hasattr(sys, "frozen"):
sys.exit(1) sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0], '..')))
t = textures.Textures()
t.generate()
blocks = {} def main(outfile):
from overviewer_core import textures
t = textures.Textures()
t.generate()
for blockid in xrange(textures.max_blockid): blocks = {}
for data in xrange(textures.max_data):
tex = t.blockmap[blockid * textures.max_data + data]
if tex:
if not blockid in blocks:
blocks[blockid] = {}
blocks[blockid][data] = tex
columns = max(map(len, blocks.values())) for blockid in range(textures.max_blockid):
rows = len(blocks) for data in range(textures.max_data):
texsize = t.texture_size tex = t.blockmap[blockid * textures.max_data + data]
if tex:
if blockid not in blocks:
blocks[blockid] = {}
blocks[blockid][data] = tex
gallery = Image.new("RGBA", (columns * texsize, rows * texsize), t.bgcolor) columns = max(len(v) for v in blocks.values())
rows = len(blocks)
texsize = t.texture_size
row = 0 gallery = Image.new("RGBA", (columns * texsize, rows * texsize), t.bgcolor)
for blockid, textures in blocks.iteritems():
column = 0
for data, tex in textures.iteritems():
gallery.paste(tex[0], (column * texsize, row * texsize))
column += 1
row += 1
gallery.save(sys.argv[1]) for row, (blockid, textures) in enumerate(blocks.items()):
for column, (data, tex) in enumerate(textures.items()):
gallery.paste(tex[0], (column * texsize, row * texsize))
gallery.save(outfile)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('file', metavar='output.png')
args = parser.parse_args()
main(args.file)