Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace PokemonLZA{



void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
bool save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){

bool seen_save_button = false;
bool seen_saved_dialog = false;
Expand Down Expand Up @@ -59,9 +59,9 @@ void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
std::chrono::seconds(30),
{
overworld,
dialog,
main_menu,
save_button,
dialog,
}
);
context.wait_for(100ms);
Expand All @@ -71,22 +71,28 @@ void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
pbf_press_button(context, BUTTON_X, 160ms, 240ms);
continue;
case 1:
if (!seen_save_button){
console.log("Detected dialog before save prompt. Unable to save.", COLOR_RED);
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
return false;
}

console.log("Detected dialog...");
seen_saved_dialog = true;
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
continue;
case 2:
console.log("Detected main menu...");
if (seen_save_button && seen_saved_dialog){
return;
return true;
}
pbf_press_button(context, BUTTON_R, 160ms, 240ms);
continue;
case 2:
case 3:
console.log("Detected save button...");
seen_save_button = true;
pbf_press_button(context, BUTTON_A, 160ms, 240ms);
continue;
case 3:
console.log("Detected dialog...");
seen_saved_dialog = true;
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
continue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace PokemonLZA{

// Starting from either the overworld or the main menu, save the game.
// This function returns in the main menu.
void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context);
// Return true if the game is saved successfully, false otherwise.
bool save_game_to_menu(ConsoleHandle& console, ProControllerContext& context);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ShinyHunt_BenchSit::ShinyHunt_BenchSit()
)
, PERIODIC_SAVE(
"<b>Periodically Save:</b><br>"
"Save the game every this many bench sits. This reduces the loss to game crashes. Set to zero to disable.",
"Save the game every this many bench sits. This reduces the loss to game crashes. Set to zero to disable. Saving will be unsuccessful if you are under attack",
LockMode::UNLOCK_WHILE_RUNNING,
100,
0
Expand Down Expand Up @@ -181,6 +181,19 @@ void ShinyHunt_BenchSit::program(SingleSwitchProgramEnvironment& env, ProControl
shiny_sound_handler.process_pending(context);
stats.resets++;
env.update_stats();

uint32_t periodic_save = PERIODIC_SAVE;
if (periodic_save != 0 && rounds_since_last_save >= periodic_save) {
bool save_successful = save_game_to_menu(env.console, context);
pbf_mash_button(context, BUTTON_B, 2000ms);
if (save_successful) {
env.console.overlay().add_log("Game Saved Successfully", COLOR_BLUE);
rounds_since_last_save = 0;
} else {
env.console.overlay().add_log("Game Save Failed. Will attempt to save after the next reset.", COLOR_RED);
}
}

Milliseconds duration = WALK_FORWARD_DURATION;
if (duration > Milliseconds::zero()){
if (WALK_DIRECTION.current_value() == 0){ // forward
Expand Down Expand Up @@ -212,13 +225,6 @@ void ShinyHunt_BenchSit::program(SingleSwitchProgramEnvironment& env, ProControl
}

shiny_sound_handler.process_pending(context);

uint32_t periodic_save = PERIODIC_SAVE;
if (periodic_save != 0 && rounds_since_last_save >= periodic_save) {
save_game_to_menu(env.console, context);
pbf_mash_button(context, BUTTON_B, 2000ms);
rounds_since_last_save = 0;
}
}
},
{shiny_detector}
Expand Down