#!/usr/bin/python import argparse HEADER = "palette.register(\"{}\",{{" COLOR_STR = "{{{},{},{}}}" FOOTER = "})" parser = argparse.ArgumentParser(description="Converts TIC-80 style pal strings to palette definitions (for src/palette.lua)") parser.add_argument("palstr",help="File with the palette string.") parser.add_argument("paldef",help="File to put result in.") parser.add_argument("name",help="Name of palette. Defaults to 'New palette'.",default="New palette") args = parser.parse_args() def split(s,n): for i in range(0,len(s),n): yield s[i:i+n] t = [] with open(args.palstr) as f: t = [[int(x,16) for x in split(y,2)] for y in split(f.read().strip(),6)] #print(t) with open(args.paldef,"w") as f: f.write(HEADER.format(args.name)) for i in range(len(t)): c = t[i] f.write(COLOR_STR.format(*c)) if (i+1)