def main(): if len(sys.argv) < 4: print "USAGE: %s PALETTE DATA_DIR OUT_DIR [--no-map] [--only-map] [--update]" % sys.argv[0] print "PALETTE is likely data/color.pal, and DATA_DIR is likely data/" sys.exit(1) PALETTE = sys.argv[1] DATA_DIR = sys.argv[2] OUT_DIR = sys.argv[3] if not os.path.exists(OUT_DIR): os.mkdir(OUT_DIR) exportImage = '--only-map' not in sys.argv palette = pal.readPAL(open(PALETTE, "rb")) palette = flatten([r, g, b] for r, g, b in palette) subdirs = ("critters", "skilldex", "inven", "tiles", "critters", "items", "scenery", "walls", "misc", "intrface") # etc imageInfo = {} for subdir in subdirs: dir = '%s/%s' % (OUT_DIR, subdir) if not os.path.exists(dir): os.mkdir(dir) subdirFRMs = [glob.glob("%s/art/%s/*.frm" % (DATA_DIR, subdir)) for subdir in subdirs] totalNum = sum(len(x) for x in subdirFRMs) if '--update' in sys.argv: imageMap = json.load(open('%s/imageMap.json' % OUT_DIR, "r")) i = 1 for subdirIdx,FRMs in enumerate(subdirFRMs): subdir = subdirs[subdirIdx] for FRM in FRMs: name = '%s/%s' % (subdir, os.path.splitext(os.path.basename(FRM))[0].lower()) outpath = "%s/%s.png" % (OUT_DIR, name) if '--update' in sys.argv and os.path.exists(outpath) and ('art/'+name) in imageMap: # already exists, skip it i += 1 continue print "[%d/%d/%d] %s..." % (i, len(FRMs), totalNum, name) imageInfo['art/'+name] = frmpixels.exportFRM(FRM, outpath, palette, exportImage) i += 1 if '--no-map' not in sys.argv: if '--update' in sys.argv: # merge our changes into the existing imageMap imageMap.update(imageInfo) imageInfo = imageMap print "writing image map..." # write new imageMap json.dump(imageInfo, open('%s/imageMap.json' % OUT_DIR, "w"))
def main(): if len(sys.argv) < 3: print("USAGE: %s FRM OUTFILE [PALETTE]" % sys.argv[0]) sys.exit(1) if len(sys.argv) < 4: palFile = "data/color.pal" else: palFile = sys.argv[3] palette = pal.readPAL(open(palFile, "rb")) palette = flatten([r, g, b] for r, g, b in palette) print(json.dumps(exportFRM(sys.argv[1], sys.argv[2], palette)))
def main(): if len(sys.argv) < 3: print "USAGE: %s FRM OUTFILE [PALETTE]" % sys.argv[0] sys.exit(1) if len(sys.argv) < 4: palFile = "data/color.pal" else: palFile = sys.argv[3] palette = pal.readPAL(open(palFile, "rb")) palette = flatten([r, g, b] for r, g, b in palette) print json.dumps(exportFRM(sys.argv[1], sys.argv[2], palette))
def readPAL(path): palette = pal.readPAL(open(path, "rb")) palette = flatten([r, g, b] for r, g, b in palette) return palette