# -*- coding: utf-8 -*- """ Ah, the mysteries of shitty Python code. Try to understand it, but can you? No! They're mysteries! WARNING: No support on this code, or assistance on how to use it. Don't run this if you don't know what it does, and don't run this on non-windows platforms. This code is potentially unsafe. Use it at your own risk. Public Domain """ import os import time as time try: os.remove("Z:\\run.bat") #output batch file except Exception, e: print "ignored: %s" % e global f f = open("Z:\\run.bat", "w") #output batch file def fixani(inputfilepath, inmask, outx, outy): """ Fixes a .ani file, so that every line that starts with 'inmask' has its x coordinate set to 'outx' and its y coordinate set to 'outy' """ try: fin = open(inputfilepath, "r") outwrite = [] for line in fin.readlines(): arr = line.split() if arr[0].startswith(inmask): arr[3] = str(outx) arr[4] = str(outy) out = " ".join(arr) print out outwrite.append(out) fin.close() os.remove(inputfilepath) fin = open(inputfilepath, "w") for o in outwrite: fin.write(o + "\n") fin.close() except Exception, e: print "exception occured (ignoring): %s" % e def wr(input): """ writes input to file also echoes input to console """ global f print input f.write(input) def process(i, namebase, coords, fpath): wr("del %s-big-%03d.png\n" % (fpath+namebase,i)) wr("convert in-%s.png -background \"rgba(0,0,0,0)\" -extent 256x256 -distort SRT \"%s 1,1 %s 128,128\" %s-big-%03d.png\n" % (namebase, coords, (i * 22.5),fpath + namebase,i)) ## wr("del %s-med-%03d.png\n" % (fpath+namebase,i)) wr("convert in-%s.png -background \"rgba(0,0,0,0)\" -extent 256x256 -distort SRT \"%s 0.5,0.5 %s 128,128\" %s-med-%03d.png\n" % (namebase, coords, (i * 22.5),fpath + namebase,i)) ## wr("del %s-sml-%03d.png\n" % (fpath+namebase,i)) wr("convert in-%s.png -background \"rgba(0,0,0,0)\" -extent 256x256 -distort SRT \"%s 0.25,0.25 %s 128,128\" %s-sml-%03d.png\n" % (namebase, coords, (i * 22.5),fpath + namebase,i)) def convert(namebase, coords, anifiledirectory): for i in xrange(0,16): process(i, namebase, coords, anifiledirectory) wr("del %s-meleeicons-000.png\n" % (anifiledirectory + namebase)) wr("del %s-meleeicons-001.png\n" % (anifiledirectory + namebase)) wr("convert in-%s.png %s-meleeicons-000.png\n" % (namebase,(anifiledirectory + namebase))) wr("convert in-%s.png -resize 33%% %s-meleeicons-001.png\n" % (namebase,(anifiledirectory + namebase))) fixani(anifiledirectory + namebase + "-big.ani", namebase + "-big-", 128, 128) fixani(anifiledirectory + namebase + "-med.ani", namebase + "-med-", 128, 128) fixani(anifiledirectory + namebase + "-sml.ani", namebase + "-sml-", 128, 128) fixani(anifiledirectory + namebase + "-meleeicons.ani", namebase + "-big-", 128, 128) fixani(anifiledirectory + namebase + "-meleeicons.ani", namebase + "-med-", 128, 128) fixani(anifiledirectory + namebase + "-meleeicons.ani", namebase + "-sml-", 128, 128) ### Uncomment as needed: #convert("avatar", "63,100", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\chmmr\\") #TODO determine hotspot properly #convert("scout", "35,45", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\shofixti\\") #TODO determine hotspot properly #convert("torch", "55,54", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\thraddash\\") #TODO determine hotspot properly #convert("marauder", "46,91", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\kohrah\\") #TODO determine hotspot properly #convert("trader", "69,69", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\melnorme\\") #TODO determine hotspot properly #convert("mauler", "23,64", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\druuge\\") #TODO determine hotspot properly #convert("skiff", "28,29", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\arilou\\") #TODO determine hotspot properly #convert("broodhome", "70,71", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\chenjesu\\") #TODO determine hotspot properly #convert("drone", "29,40", "C:\\games\\p6014_2\\content\\addons\\hires4x\\ships\\umgah\\") #TODO determine hotspot properly time.sleep(1) f.close() print "done, now run the .bat"