#!/usr/bin/env python3

from xml.dom import minidom
import sys

if len(sys.argv) != 3:
	sys.exit("Usage: tmx2bin <tmx map file> <binary output file>")

bindata = bytearray()

doc = minidom.parse(sys.argv[1])
csvdata = doc.getElementsByTagName("data")[0].firstChild.data
for line in csvdata.strip().split("\n"):
	for tilenum in line.strip(",").split(","):
		bindata.append(int(tilenum) - 1)

open(sys.argv[2], "wb").write(bindata)

