Skip to content

Instantly share code, notes, and snippets.

@wuuff
Created November 4, 2017 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wuuff/69d5ba1173cc5d678720f0fcf6939457 to your computer and use it in GitHub Desktop.
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
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