From 5957413979517ebaee1fbc16062e26f6dfe50621 Mon Sep 17 00:00:00 2001 From: Rachel Date: Wed, 29 Jan 2025 23:19:17 -0800 Subject: [PATCH] Move footprint header generation into datagen-species --- include/overlay113/footprint_data.h | 6 +- meson.build | 5 +- res/pokemon/meson.build | 16 +--- res/pokemon/none/data.json | 4 + src/overlay113/ov113_02260620.c | 6 +- tools/datagen/datagen_species.cpp | 36 ++++++++- tools/scripts/make_species_tables.py | 109 --------------------------- tools/scripts/meson.build | 1 - 8 files changed, 48 insertions(+), 135 deletions(-) delete mode 100644 tools/scripts/make_species_tables.py diff --git a/include/overlay113/footprint_data.h b/include/overlay113/footprint_data.h index b0234a5582..2dfc880415 100644 --- a/include/overlay113/footprint_data.h +++ b/include/overlay113/footprint_data.h @@ -2,9 +2,9 @@ #define POKEPLATINUM_FOOTPRINT_DATA_H typedef struct FootprintData { - u8 hasFootprint; - u8 footprintSize; - u16 unk_02; + u8 has; + u8 size; + u16 padding; } FootprintData; #endif // POKEPLATINUM_FOOTPRINT_DATA_H diff --git a/meson.build b/meson.build index ebae022075..0b730083b7 100644 --- a/meson.build +++ b/meson.build @@ -115,7 +115,6 @@ libcrypto_dep = dependency('libcrypto') libsyscall_dep = dependency('libsyscall') ppwlobby_dep = dependency('ppwlobby') - ############################################################ ### CONSTS ### ############################################################ @@ -146,7 +145,7 @@ subdir('lib') subdir('res') # Phony-like target to build all generated data files -alias_target('data', nitrofs_files, gen_species_headers) +alias_target('data', nitrofs_files) ############################################################ ### ARM9 BINARY ### @@ -160,9 +159,9 @@ main = executable('main', pokeplatinum_asm, c_consts_generators, naix_headers, - gen_species_headers, tutorable_moves_h, species_learnsets_by_tutor_h, + species_footprints_h, ], c_args: [ pokeplatinum_args, diff --git a/res/pokemon/meson.build b/res/pokemon/meson.build index 6b68123b4a..dfb4ea3a18 100644 --- a/res/pokemon/meson.build +++ b/res/pokemon/meson.build @@ -193,6 +193,7 @@ datagen_species_out = custom_target('datagen_species_out', 'pl_poke_data.narc', 'tutorable_moves.h', 'species_learnsets_by_tutor.h', + 'species_footprints.h', ], command: [ datagen_species_exe, @@ -208,6 +209,7 @@ datagen_species_out = custom_target('datagen_species_out', ) tutorable_moves_h = datagen_species_out[6] species_learnsets_by_tutor_h = datagen_species_out[7] +species_footprints_h = datagen_species_out[8] # OLD NARCs @@ -330,20 +332,6 @@ pokedex_data_giratina_altered_narc = custom_target('zukan_data_gira.narc', depend_files: [ species_data_files ], ) -species_header_target = meson.current_build_dir() - -gen_species_headers = custom_target('gen_species_headers', - output: 'footprint_data.h', - input: species_data_files, - env: py_consts_env, - depends: [ py_consts_generators ], - command: [ - make_species_tables_py, - '--source-dir', '@CURRENT_SOURCE_DIR@', - '--output-dir', species_header_target, - ] -) - nitrofs_files += datagen_species_out nitrofs_files += pl_poke_icon_narc diff --git a/res/pokemon/none/data.json b/res/pokemon/none/data.json index 54c0b5cf17..70ef2b2567 100644 --- a/res/pokemon/none/data.json +++ b/res/pokemon/none/data.json @@ -37,6 +37,10 @@ "by_tm": [ ] }, "evolutions": [ ], + "footprint": { + "has": false, + "size": "FOOTPRINT_SMALL" + }, "pokedex_data": { "height": 7, "weight": 69, diff --git a/src/overlay113/ov113_02260620.c b/src/overlay113/ov113_02260620.c index 3a385d48f8..a8631478b6 100644 --- a/src/overlay113/ov113_02260620.c +++ b/src/overlay113/ov113_02260620.c @@ -34,7 +34,7 @@ __attribute__((aligned(4))) static const u16 Unk_ov113_02260D6C[][2] = { { 0x2D4A, 0x5651 } }; -#include "res/pokemon/footprint_data.h" +#include "res/pokemon/species_footprints.h" static const TouchScreenRect Unk_ov113_02260D4C[] = { { 0xA0, 0xC0, 0x0, 0x20 }, @@ -158,7 +158,7 @@ BOOL PokemonHasOverworldFootprint(int species, int form, BOOL canShowArceus) return FALSE; } - return sSpeciesFootprintData[species].hasFootprint; + return sSpeciesFootprints[species].has; } int PokemonOverworldFootprintSize(int species, int form) @@ -167,5 +167,5 @@ int PokemonOverworldFootprintSize(int species, int form) return FOOTPRINT_LARGE; } - return sSpeciesFootprintData[species].footprintSize; + return sSpeciesFootprints[species].size; } diff --git a/tools/datagen/datagen_species.cpp b/tools/datagen/datagen_species.cpp index ade08d76ba..e8a1de670f 100644 --- a/tools/datagen/datagen_species.cpp +++ b/tools/datagen/datagen_species.cpp @@ -26,6 +26,7 @@ * - pl_poke_data.narc * - tutorable_moves.h * - species_learnsets_by_tutor.h + * - species_footprints.h */ #include #include @@ -408,6 +409,18 @@ static PokeSpriteFaceData ParsePokeSpriteFace(const rapidjson::Value &face) return data; } +static void TryEmitFootprint(const rapidjson::Document &root, std::ofstream &ofs) +{ + if (!root.HasMember("footprint")) { + return; + } + + const rapidjson::Value &footprint = root["footprint"]; + ofs << " { " + << (footprint["has"].GetBool() ? "TRUE, " : "FALSE, ") + << footprint["size"].GetString() << ", },\n"; +} + static ArchivedPokeSpriteData ParsePokeSprite(const rapidjson::Document &root) { ArchivedPokeSpriteData data = { 0 }; @@ -453,6 +466,19 @@ int main(int argc, char **argv) << "static const MovesetMask sSpeciesLearnsetsByTutor[MOVESET_MAX] = {\n"; byTutorMovesets << std::hex << std::setiosflags(std::ios::uppercase); // render all numeric inputs to the stream as hexadecimal + // Bootstrap the footprints header. + std::ofstream footprints(outputRoot / "species_footprints.h"); + footprints << sHeaderMessage << "\n" + << "#ifndef POKEPLATINUM_GENERATED_SPECIES_FOOTPRINTS_H\n" + << "#define POKEPLATINUM_GENERATED_SPECIES_FOOTPRINTS_H\n" + << "\n" + << "#include \"constants/species.h\"\n" + << "#include \"generated/footprint_sizes.h\"\n" + << "\n" + << "#include \"overlay113/footprint_data.h\"\n" + << "\n" + << "static const FootprintData sSpeciesFootprints[NATIONAL_DEX_COUNT + 1] = {\n"; + // Tutorable learnsets are stored as an array of bitmasks; each bit in the mask // denotes if a tutorable move can be learned by a given species. std::size_t tutorableLearnsetSize = (tutorableMoves.size() + 7) / 8; @@ -483,6 +509,7 @@ int main(int argc, char **argv) SpeciesLearnsetWithSize sizedLearnset = ParseLevelUpLearnset(doc); std::optional palPark = TryParsePalPark(doc); TryEmitTutorableLearnset(doc, byTutorMovesets, tutorableMoves, tutorableLearnsetSize); + TryEmitFootprint(doc, footprints); narc_pack_file_copy(personalVFS, reinterpret_cast(&data), sizeof(data)); narc_pack_file_copy(evoVFS, reinterpret_cast(&evos), sizeof(evos)); @@ -512,10 +539,15 @@ int main(int argc, char **argv) } byTutorMovesets << "};\n" - << "#endif // POKEPLATINUM_GENERATED_SPECIES_LEARNSETS_BY_TUTOR_H" - << std::endl; + << "\n" + << "#endif // POKEPLATINUM_GENERATED_SPECIES_LEARNSETS_BY_TUTOR_H\n"; byTutorMovesets.close(); + footprints << "};\n" + << "\n" + << "#endif // POKEPLATINUM_GENERATED_SPECIES_FOOTPRINTS_H\n"; + footprints.close(); + PackNarc(personalVFS, outputRoot / "pl_personal.narc"); PackNarc(evoVFS, outputRoot / "evo.narc"); PackNarc(wotblVFS, outputRoot / "wotbl.narc"); diff --git a/tools/scripts/make_species_tables.py b/tools/scripts/make_species_tables.py deleted file mode 100644 index f1735896de..0000000000 --- a/tools/scripts/make_species_tables.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import json -import pathlib - -from generated.footprint_sizes import FootprintSize -from generated.moves import Move -from generated.species import Species - - -argparser = argparse.ArgumentParser( - prog='make_species_tables.py', - description='Creates generated .h files for species-specific data' -) -argparser.add_argument('-s', '--source-dir', - required=True, - help='Path to the source directory (res/pokemon)') -argparser.add_argument('-o', '--output-dir', - required=True, - help='Path to the output directory (where the header files will be made)') -args = argparser.parse_args() - -source_dir = pathlib.Path(args.source_dir) -output_dir = pathlib.Path(args.output_dir) - -NATIONAL_DEX_COUNT = 493 - -FORM_INDICES = { - 'DEOXYS' : { - 'ATTACK': NATIONAL_DEX_COUNT + 1, - 'DEFENSE': NATIONAL_DEX_COUNT + 2, - 'SPEED': NATIONAL_DEX_COUNT + 3, - }, - 'WORMADAM': { - 'SANDY': NATIONAL_DEX_COUNT + 4, - 'TRASH': NATIONAL_DEX_COUNT + 5, - }, - 'GIRATINA': { - 'ORIGIN': NATIONAL_DEX_COUNT + 6, - }, - 'SHAYMIN': { - 'SKY': NATIONAL_DEX_COUNT + 7, - }, - 'ROTOM': { - 'HEAT': NATIONAL_DEX_COUNT + 8, - 'WASH': NATIONAL_DEX_COUNT + 9, - 'FROST': NATIONAL_DEX_COUNT + 10, - 'FAN': NATIONAL_DEX_COUNT + 11, - 'MOW': NATIONAL_DEX_COUNT + 12, - }, -} - -species_footprints = { - 0: { "has": False, "size": "FOOTPRINT_SMALL" } -} - -for file_path in source_dir.glob("**/data.json"): - with open(file_path, 'r') as data_file: - species_data = json.load(data_file) - - species_name = file_path.parent.stem.upper() - - if species_name in ["NONE", "EGG", "BAD_EGG"]: - continue - - isForm = False - - if file_path.parent.parent.stem == "forms": - form_name = species_name - species_name = file_path.parent.parent.parent.stem.upper() - - species_id = FORM_INDICES[species_name][form_name] - - isForm = True - else: - species_id = Species[f"SPECIES_{species_name}"].value - - if not isForm: - species_footprints[species_id] = species_data["footprint"] - - -generated_disclaimer = [ - "// This file is GENERATED. Changes will be overwritten here on build\n", - "// Check make_species_tables.py for reference\n", -] - -# write footprint table header -output_path = output_dir / "footprint_data.h" - -with open(output_path, "w") as output_file: - output_file.writelines(generated_disclaimer) - output_file.write("#ifndef POKEPLATINUM_GENERATED_FOOTPRINT_DATA_H\n") - output_file.write("#define POKEPLATINUM_GENERATED_FOOTPRINT_DATA_H\n") - output_file.write("#include \"overlay113/footprint_data.h\"\n") - output_file.write("#include \"constants/species.h\"\n") - output_file.write("\n") - output_file.write("static const FootprintData sSpeciesFootprintData[NATIONAL_DEX_COUNT + 1] = {\n") - - sorted_array = sorted(species_footprints.items()) - - for key, value in sorted_array: - - has_footprint = "TRUE" if species_footprints[key]["has"] else "FALSE" - footprint_size = FootprintSize[species_footprints[key]["size"]].value - - output_file.write(f" {{ {has_footprint}, {footprint_size} }},\n") - - output_file.write("};\n") - output_file.write("\n#endif\n") diff --git a/tools/scripts/meson.build b/tools/scripts/meson.build index 2ebef77811..c07e2a2700 100644 --- a/tools/scripts/meson.build +++ b/tools/scripts/meson.build @@ -5,7 +5,6 @@ make_script_bin_sh = find_program('make_script_bin.sh', native: true) make_pl_pokezukan_py = find_program('make_pl_pokezukan.py', native: true) make_shinzukan_py = find_program('make_shinzukan.py', native: true) make_pl_growtbl_py = find_program('make_pl_growtbl.py', native: true) -make_species_tables_py = find_program('make_species_tables.py', native: true) make_pokedex_data_py = find_program('make_pokedex_data.py', native: true) make_pokedex_text_banks_py = find_program('make_pokedex_text_banks.py', native: true) make_pokedex_enc_platinum_py = find_program('make_pokedex_enc_platinum.py', native: true)