2023-05-04 11:03:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-11-11 17:33:55 +01:00
|
|
|
|
|
|
|
from sys import argv, path
|
|
|
|
from pathlib import Path
|
2023-06-26 12:27:37 +02:00
|
|
|
|
2023-07-10 07:57:27 +02:00
|
|
|
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:
|
2023-07-10 07:57:27 +02:00
|
|
|
print("usage: header.py [OUT] [NAME] [ID]")
|
2020-11-11 17:33:55 +01:00
|
|
|
exit(1)
|
|
|
|
|
2023-07-10 07:57:27 +02:00
|
|
|
_, 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
|
2023-06-26 12:27:37 +02:00
|
|
|
s = int(s_in)
|
2020-11-11 17:33:55 +01:00
|
|
|
assert s >= 1
|
|
|
|
|
2023-07-10 07:57:27 +02:00
|
|
|
sprite = npc_from_dir(sprite_name, asset_stack, load_images=False)
|
2020-11-11 17:33:55 +01:00
|
|
|
|
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")
|
|
|
|
|
2022-09-24 11:04:13 +02:00
|
|
|
# sprite definition
|
|
|
|
f.write(f"#define SPR_{sprite_name} 0x{s:02X}\n")
|
|
|
|
f.write("\n")
|
2020-11-11 17:33:55 +01:00
|
|
|
|
2022-09-24 11:04:13 +02: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
|
|
|
|
2022-09-24 11:04:13 +02: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")
|
2022-09-24 11:04:13 +02:00
|
|
|
|
|
|
|
# definitions for animations
|
|
|
|
for p, palette_name in enumerate(sprite.palette_names):
|
|
|
|
for a, name in enumerate(sprite.animation_names):
|
|
|
|
if palette_name == "Default":
|
2023-07-29 19:03:17 +02:00
|
|
|
f.write(f"#define ANIM_{sprite_name}_{name} 0x{s:02X}{p:02X}{a:02X}\n")
|
2022-09-24 11:04:13 +02:00
|
|
|
else:
|
2023-07-29 19:03:17 +02:00
|
|
|
f.write(f"#define ANIM_{sprite_name}_{palette_name}_{name} 0x{s:02X}{p:02X}{a:02X}\n")
|
2022-09-24 11:04:13 +02:00
|
|
|
f.write("\n")
|
|
|
|
|
2020-11-11 17:33:55 +01:00
|
|
|
f.write("#endif\n")
|