doodle/mp2json.py
Noah Petherbridge f76ba6fbb7 WIP: MsgPack stubs, Level Filesystem Module
* Add some encoding/decoding functions for binary msgpack format for
  levels and doodads. Currently it writes msgpack files that can be
  decoded and printed by Python (mp2json.py) but it can't re-read from
  the binary format. For now, levels will continue to write in JSON
  format.
* Add filesystem abstraction functions to the balance/ package to search
  multiple paths to find Levels and Doodads, to make way for
  system-level doodads.
2019-05-06 12:41:46 -07:00

23 lines
573 B
Python

#!/usr/bin/env python3
"""mp2json: convert a msgpack binary file into JSON for debugging."""
import msgpack
import json
import sys
if len(sys.argv) < 2:
print("Usage: mp2json <filename.level>")
with open(sys.argv[1], 'rb') as fh:
header = fh.read(8)
magic = header[:6].decode("utf-8")
if magic != "DOODLE":
print("input file doesn't appear to be a doodle drawing binary")
sys.exit(1)
reader = msgpack.Unpacker(fh, raw=False, max_buffer_size=10*1024*1024)
for o in reader:
print(o)
print(json.dumps(o, indent=2))