""" Converts json level data files into binary level data """ import json from os import listdir from os.path import isfile, join LVL_DIR = "lvl/" BIN_DIR = "lvl_bin/" if __name__ == "__main__": files = [f for f in listdir(LVL_DIR) if isfile(join(LVL_DIR, f))] decoder = json.JSONDecoder() for v in files: file = open(join(LVL_DIR, v), "r", encoding="utf-8") content = decoder.decode(file.read()) newfile = open(join(BIN_DIR, v.replace(".json", ".dat")), "wb") bin_content = b'' for line in content: bin_content += bytes(line+[255]) newfile.write(bin_content)