Skip to content

Instantly share code, notes, and snippets.

@lachlandcp
Created August 21, 2015 07:55
Show Gist options
  • Save lachlandcp/bb009a52991fdc767548 to your computer and use it in GitHub Desktop.
Save lachlandcp/bb009a52991fdc767548 to your computer and use it in GitHub Desktop.
WIP script for creating new texture metas in MCPE
#!/usr/bin/env python
import sys, getopt
try:
import simplejson as json
except ImportError:
import json
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
inputfile = ''
outputfile = ''
type = ''
rows = ''
def main(argv):
help = 'code.py -i <inputfile> -o <outputfile> -t <type> -w <width>'
try:
opts, args = getopt.getopt(argv, "h:i:o:t:w:", ["ifile=", "ofile=", "type=", "width="])
except getopt.GetoptError:
print help
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print help
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
elif opt in ("-t", "--type"):
type = arg
elif opt in ("-r", "--rows"):
rows = arg
if inputfile and outputfile and type and rows:
print bcolors.OKGREEN + 'Input file is', inputfile
print 'Output file is', outputfile
print 'Type is', type
print 'Rows are', rows + bcolors.ENDC
run()
else:
print help
sys.exit(2)
def run():
with open(inputfile, "r") as f:
meta = json.loads(f.read())
for texture in meta:
for unique_texture in texture:
w = unique_texture[4]
h = unique_texture[5]
x = unique_texture[0] * w
y = unique_texture[1] * h
x2 = unique_texture[2] * w
y2 = unique_texture[3] * h
f.close()
def coord(num):
width = 512
height = rows * 16
return str(int(num * width))
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment