Skip to content

Commit 28bf7de

Browse files
authored
Continue bench resets if unable to save (#860)
* Continue bench resets if unable to save * Retry save if unsuccessful
1 parent 4bf44fa commit 28bf7de

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace PokemonLZA{
2727

2828

2929

30-
void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
30+
bool save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
3131

3232
bool seen_save_button = false;
3333
bool seen_saved_dialog = false;
@@ -59,9 +59,9 @@ void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
5959
std::chrono::seconds(30),
6060
{
6161
overworld,
62+
dialog,
6263
main_menu,
6364
save_button,
64-
dialog,
6565
}
6666
);
6767
context.wait_for(100ms);
@@ -71,22 +71,28 @@ void save_game_to_menu(ConsoleHandle& console, ProControllerContext& context){
7171
pbf_press_button(context, BUTTON_X, 160ms, 240ms);
7272
continue;
7373
case 1:
74+
if (!seen_save_button){
75+
console.log("Detected dialog before save prompt. Unable to save.", COLOR_RED);
76+
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
77+
return false;
78+
}
79+
80+
console.log("Detected dialog...");
81+
seen_saved_dialog = true;
82+
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
83+
continue;
84+
case 2:
7485
console.log("Detected main menu...");
7586
if (seen_save_button && seen_saved_dialog){
76-
return;
87+
return true;
7788
}
7889
pbf_press_button(context, BUTTON_R, 160ms, 240ms);
7990
continue;
80-
case 2:
91+
case 3:
8192
console.log("Detected save button...");
8293
seen_save_button = true;
8394
pbf_press_button(context, BUTTON_A, 160ms, 240ms);
8495
continue;
85-
case 3:
86-
console.log("Detected dialog...");
87-
seen_saved_dialog = true;
88-
pbf_press_button(context, BUTTON_B, 160ms, 240ms);
89-
continue;
9096
}
9197
}
9298
}

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace PokemonLZA{
2424

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

2930

3031

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_ShinyHunt_BenchSit.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ShinyHunt_BenchSit::ShinyHunt_BenchSit()
8888
)
8989
, PERIODIC_SAVE(
9090
"<b>Periodically Save:</b><br>"
91-
"Save the game every this many bench sits. This reduces the loss to game crashes. Set to zero to disable.",
91+
"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",
9292
LockMode::UNLOCK_WHILE_RUNNING,
9393
100,
9494
0
@@ -181,6 +181,19 @@ void ShinyHunt_BenchSit::program(SingleSwitchProgramEnvironment& env, ProControl
181181
shiny_sound_handler.process_pending(context);
182182
stats.resets++;
183183
env.update_stats();
184+
185+
uint32_t periodic_save = PERIODIC_SAVE;
186+
if (periodic_save != 0 && rounds_since_last_save >= periodic_save) {
187+
bool save_successful = save_game_to_menu(env.console, context);
188+
pbf_mash_button(context, BUTTON_B, 2000ms);
189+
if (save_successful) {
190+
env.console.overlay().add_log("Game Saved Successfully", COLOR_BLUE);
191+
rounds_since_last_save = 0;
192+
} else {
193+
env.console.overlay().add_log("Game Save Failed. Will attempt to save after the next reset.", COLOR_RED);
194+
}
195+
}
196+
184197
Milliseconds duration = WALK_FORWARD_DURATION;
185198
if (duration > Milliseconds::zero()){
186199
if (WALK_DIRECTION.current_value() == 0){ // forward
@@ -212,13 +225,6 @@ void ShinyHunt_BenchSit::program(SingleSwitchProgramEnvironment& env, ProControl
212225
}
213226

214227
shiny_sound_handler.process_pending(context);
215-
216-
uint32_t periodic_save = PERIODIC_SAVE;
217-
if (periodic_save != 0 && rounds_since_last_save >= periodic_save) {
218-
save_game_to_menu(env.console, context);
219-
pbf_mash_button(context, BUTTON_B, 2000ms);
220-
rounds_since_last_save = 0;
221-
}
222228
}
223229
},
224230
{shiny_detector}

0 commit comments

Comments
 (0)