papermario/tools/gen_sprite_animations_h.py

45 lines
1.3 KiB
Python
Raw Normal View History

2020-11-11 17:33:55 +01:00
#! /usr/bin/python3
from sys import argv, path
from pathlib import Path
import os
2021-01-24 16:45:29 +01:00
path.append(os.path.join(os.path.dirname(__file__), "splat"))
2020-11-19 10:31:10 +01:00
from splat_ext.PaperMarioNpcSprites import Sprite
2020-11-11 17:33:55 +01:00
if __name__ == "__main__":
if len(argv) < 4:
2021-01-14 12:57:39 +01:00
print("usage: gen_sprite_animations_h.py [OUT] [DIR] [ID]")
2020-11-11 17:33:55 +01:00
exit(1)
2021-01-14 12:57:39 +01:00
_, outfile, sprite_dir, s = argv
2020-11-11 17:33:55 +01:00
with open(outfile, "w") as f:
# get sprite index
2021-01-14 12:57:39 +01:00
s = int(s)
2020-11-11 17:33:55 +01:00
assert s >= 1
sprite_dir = Path(sprite_dir)
sprite = Sprite.from_dir(sprite_dir, read_images=False)
sprite_name = sprite_dir.stem
f.write(f"#ifndef _SPRITE_{sprite_name.upper()}_H_\n")
f.write(f"#define _SPRITE_{sprite_name.upper()}_H_\n")
f.write("\n")
f.write('#include "types.h"\n')
f.write("\n")
f.write(f"#define _NPC_SPRITE_{sprite_name} 0x{s:02X}\n")
seen_palette_names = set()
for p, palette_name in enumerate(sprite.palette_names):
if palette_name not in seen_palette_names:
seen_palette_names.add(palette_name)
f.write(f"#define _NPC_PALETTE_{sprite_name}_{palette_name} 0x{p:02X}\n")
for a, name in enumerate(sprite.animation_names):
f.write(f"#define _NPC_ANIM_{sprite_name}_{name} 0x{a:02X}\n")
f.write("\n")
f.write("#endif\n")