Created
November 4, 2017 06:30
-
-
Save wuuff/69d5ba1173cc5d678720f0fcf6939457 to your computer and use it in GitHub Desktop.
simple python script to convert map data from json to a binary format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys,struct,json | |
if len(sys.argv) != 2: | |
print "No! One argument, the json map, come on" | |
exit() | |
with open(sys.argv[1]) as f: | |
map = json.load(f) | |
mapdata = map['layers'][0]['data'] | |
for item in mapdata: | |
sys.stdout.write( struct.pack('B',int(item)-1) ) | |
#Append column-ordered version | |
width = map['layers'][0]['width'] | |
height = map['layers'][0]['height'] | |
for col in range(width): | |
for row in range(height): | |
item = mapdata[col + row*width] | |
sys.stdout.write( struct.pack('B',int(item)-1) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment