papermario/tools/build/sprite/header.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2020-11-11 17:33:55 +01:00
from sys import argv, path
from pathlib import Path
path.append(str(Path(__file__).parent.parent))
from sprite.npc_sprite import from_dir as npc_from_dir
2020-11-11 17:33:55 +01:00
if __name__ == "__main__":
if len(argv) < 4:
print("usage: header.py [OUT] [NAME] [ID]")
2020-11-11 17:33:55 +01:00
exit(1)
_, outfile, sprite_name, s_in, asset_stack_raw = argv
asset_stack = tuple(Path(d) for d in asset_stack_raw.split(","))
2020-11-11 17:33:55 +01:00
with open(outfile, "w") as f:
# get sprite index
s = int(s_in)
2020-11-11 17:33:55 +01:00
assert s >= 1
sprite = npc_from_dir(sprite_name, asset_stack, load_images=False)
2020-11-11 17:33:55 +01: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")
# sprite definition
f.write(f"#define SPR_{sprite_name} 0x{s:02X}\n")
f.write("\n")
2020-11-11 17:33:55 +01:00
# definitions for images
for i, image_name in enumerate(sprite.image_names):
f.write(f"#define SPR_IMG_{sprite_name}_{image_name} 0x{i:X}\n")
f.write("\n")
2020-11-11 17:33:55 +01:00
# definitions for palettes
for p, palette_name in enumerate(sprite.palette_names):
if palette_name == "Default":
f.write(f"#define SPR_PAL_{sprite_name} 0x{p:X}\n")
else:
f.write(f"#define SPR_PAL_{sprite_name}_{palette_name} 0x{p:X}\n")
2020-11-11 17:33:55 +01:00
f.write("\n")
# definitions for animations
for p, palette_name in enumerate(sprite.palette_names):
for a, name in enumerate(sprite.animation_names):
if palette_name == "Default":
f.write(f"#define ANIM_{sprite_name}_{name} 0x{s:02X}{p:02X}{a:02X}\n")
else:
f.write(f"#define ANIM_{sprite_name}_{palette_name}_{name} 0x{s:02X}{p:02X}{a:02X}\n")
f.write("\n")
2020-11-11 17:33:55 +01:00
f.write("#endif\n")