papermario/tools/build/sprite/header.py

59 lines
2.0 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
Splat refactor (#257) * all non-world rodata migrated * data disasm * kinda working * updated yaml * bloop * linker header * configure 2.0 * bin * mass rename to remove code_ * pause rename * battle partner stuff * whew * more renames * more renames * more renaming * it builds! * updates * remove main prefix * one more thing * crc, yay0 * .data, .rodata, .bss * img * dead_atan2 * it buildsgit add -A * split battle/partner/6FAD10 * rm &s on sleepy_sheep syms * sha1sum ninja rule description * OK but commented out PaperMarioMapFS and PaperMarioNpcSprites * uncomment * fix mapfs * match func_8003CFB4 * . * clean up and name npc_iter_no_op * npc.c * enable cc warnings * name npc_find_near * use singular options.asset_path * smores * cc_dsl only when needed * kinda fix configure for splat refactor2 * ok! * new msg format * remove old msg format docs * slight bug fixes, splat adjustment * git subrepo pull (merge) --force tools/splat subrepo: subdir: "tools/splat" merged: "cfc140bb76" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "cfc140bb76" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * git subrepo pull (merge) --force tools/splat subrepo: subdir: "tools/splat" merged: "85349befcd" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "85349befcd" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * Update symbol addrs * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "a44631e194" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a44631e194" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" Co-authored-by: Alex Bates <hi@imalex.xyz>
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"))
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
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")