import os
import shutil
import xml.dom.minidom

def main():
    for sheet in ["boot", "hair", "pants", "shirt", "glove", ("item", "axe"), ("item", "bow"), ("item", "swing"), ("item", "hold"), ("item", "thrust"), ("item", "sword")]:
        folder = sheet if isinstance(sheet, str) else sheet[0]
        name = sheet if isinstance(sheet, str) else sheet[1]
        sheetPath = os.path.join(folder, "{}.xml".format(name))
        if not os.path.exists(sheetPath):
            continue

        print "{} = SpriteSheet()".format(name)
        sheetXml = xml.dom.minidom.parse(sheetPath)
        for node in sheetXml.childNodes:
            if not hasattr(node, "tagName") or node.tagName != "TextureAtlas":
                continue
            for sprite in node.childNodes:
                if not hasattr(sprite, "tagName") or sprite.tagName != "sprite":
                    continue
                n = sprite.getAttribute('n')
                x = sprite.getAttribute('x')
                y = sprite.getAttribute('y')
                width = sprite.getAttribute('w')
                height = sprite.getAttribute('h')
                origin = "Vector(30, 30)" if folder == "item" else "Vector(3, 3)"
                if name == "thrust":
                    origin = "Vector(0, 0)"
                print "{}.append(SheetEntry('{}/{}', PixelRect({}, {}, {}, {}), {}))".format(name, folder, n, x, y, width, height, origin)
        print "render.sheets['{0}'] = {0}".format(name)

if __name__ == "__main__":
    main()
