2020-11-11 17:33:55 +01:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
from sys import argv, path
|
|
|
|
from pathlib import Path
|
2021-04-13 09:47:52 +02:00
|
|
|
path.append(str(Path(__file__).parent.parent.parent / "splat"))
|
|
|
|
path.append(str(Path(__file__).parent.parent.parent / "splat_ext"))
|
2021-07-16 11:28:37 +02:00
|
|
|
from pm_npc_sprites 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
|
|
|
|
|
2021-08-24 18:42:29 +02:00
|
|
|
f.write(f"#ifndef _NPC_SPRITE_{sprite_name.upper()}_H_\n")
|
|
|
|
f.write(f"#define _NPC_SPRITE_{sprite_name.upper()}_H_\n")
|
2020-11-11 17:33:55 +01:00
|
|
|
f.write("\n")
|
|
|
|
f.write('#include "types.h"\n')
|
|
|
|
f.write("\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)
|
|
|
|
|
2021-08-24 18:42:29 +02:00
|
|
|
for a, name in enumerate(sprite.animation_names):
|
|
|
|
f.write(f"#define NPC_ANIM_{sprite_name}_{palette_name}_{name} 0x{s:02X}{p:02X}{a:02X}\n")
|
2020-11-11 17:33:55 +01:00
|
|
|
|
|
|
|
f.write("\n")
|
|
|
|
f.write("#endif\n")
|