Skip to content

Commit

Permalink
Merge pull request #8 from savaughn/fix-pokedex-entry
Browse files Browse the repository at this point in the history
update pokedex seen/owned entry
  • Loading branch information
savaughn authored Sep 29, 2023
2 parents 82b73dd + edd9c9f commit ef53790
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ MACOS_DESTINATION = $(BUILD_DIR)/$(MACOS_BUNDLE)/Contents/MacOS
INFO_PLIST = $(BUILD_DIR)/$(MACOS_BUNDLE)/Contents/Info.plist

# Define mGBA path and save file
ROM_PATH = $(realpath rom)
ROM_PATH = $(realpath saves)
ROM_FILE = pk-crystal.gbc


Expand Down
1 change: 1 addition & 0 deletions include/pksavhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ void printParty(struct pksav_gen2_save *save);
void swapPartyPokemonAtIndices(struct pksav_gen2_save *save, int pokemon_index1, int pokemon_index2);
void swapPokemonAtIndexBetweenSaves(struct pksav_gen2_save *player1_save, struct pksav_gen2_save *player2_save, int selected_index1, int selected_index2);
void create_trainer(struct pksav_gen2_save *save, struct TrainerInfo *trainer);
void updateSeenOwnedPokemon(struct pksav_gen2_save *save, int pokemon_party_index);

#endif /* PKSAVHELPER_H */
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ int main(int argc, char *argv[])
trainerSelection[1].pokemon_index = -1;

swapPokemonAtIndexBetweenSaves(&save_player1, &save_player2, selected_index_trainer1, selected_index_trainer2);
updateSeenOwnedPokemon(&save_player1, selected_index_trainer1);
updateSeenOwnedPokemon(&save_player2, selected_index_trainer2);
saveToFile(&save_player1, player1_save_path, &error_handler);
saveToFile(&save_player2, player2_save_path, &error_handler);
}
Expand Down
20 changes: 20 additions & 0 deletions src/pksavhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ int error_handler(enum pksav_error error, const char *message)
exit(1);
}

void updateSeenOwnedPokemon(struct pksav_gen2_save *save, int pokemon_party_index)
{
enum pksav_error err;
uint16_t pokemon_species = save->pokemon_storage.p_party->species[pokemon_party_index];

// update pokedex seen
err = pksav_set_pokedex_bit(save->pokedex_lists.p_seen, pokemon_species, true);
if (err != PKSAV_ERROR_NONE)
{
error_handler(err, "Error setting seen pokedex bit");
}

// update pokedex owned
err = pksav_set_pokedex_bit(save->pokedex_lists.p_owned, pokemon_species, true);
if (err != PKSAV_ERROR_NONE)
{
error_handler(err, "Error setting owned pokedex bit");
}
}

struct pksav_gen2_save loadSaveFromFile(const char *path, Error_Handler error_handler)
{
enum pksav_error err = PKSAV_ERROR_NONE;
Expand Down

0 comments on commit ef53790

Please sign in to comment.