gallery.py Python3 refactor
This commit is contained in:
@@ -2,39 +2,47 @@
|
||||
Outputs a huge image with all currently-supported block textures.
|
||||
"""
|
||||
|
||||
from overviewer_core import textures
|
||||
import argparse
|
||||
|
||||
from PIL import Image
|
||||
import sys
|
||||
import Image
|
||||
import os
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "usage: %s [output.png]" % (sys.argv[0],)
|
||||
sys.exit(1)
|
||||
# incantation to be able to import overviewer_core
|
||||
if not hasattr(sys, "frozen"):
|
||||
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):
|
||||
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
|
||||
blocks = {}
|
||||
|
||||
columns = max(map(len, blocks.values()))
|
||||
rows = len(blocks)
|
||||
texsize = t.texture_size
|
||||
for blockid in range(textures.max_blockid):
|
||||
for data in range(textures.max_data):
|
||||
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
|
||||
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 = Image.new("RGBA", (columns * texsize, rows * texsize), t.bgcolor)
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user