azuray/converters.py

37 lines
792 B
Python

import fxconv
def convert(input, output, params, target):
recognized = True
if params["custom-type"] == "map":
o = convert_map(input, params)
if recognized:
fxconv.elf(o, output, "_" + params["name"], **target)
return 0
return 1
def convert_map(input, params):
with open(input, "r") as fp:
lines = fp.read().strip().splitlines()
w = max(len(line) for line in lines)
h = len(lines)
def at(line, x):
if x >= len(line):
return 0
return 1 if line[x] == "#" else 0
cells = bytes()
for y in range(h):
for x in range(w):
cells += bytes([ at(lines[y], x) ])
s = fxconv.Structure()
s += fxconv.u16(w)
s += fxconv.u16(h)
s += fxconv.ptr(cells)
return s