Skip to content

Commit 00d36ef

Browse files
authored
device selection for FRLG, gift reset notifs (#1128)
1 parent 44a6dec commit 00d36ef

5 files changed

Lines changed: 102 additions & 14 deletions

File tree

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,21 @@ void flee_battle(ConsoleHandle& console, ProControllerContext& context){
335335
}
336336
}
337337

338-
void home_black_border_check(ConsoleHandle& console, ProControllerContext& context){
339-
console.log("Going to home to check for black border.");
340-
pbf_press_button(context, BUTTON_HOME, 120ms, 880ms);
341-
context.wait_for_all_requests();
342-
StartProgramChecks::check_border(console);
343-
console.log("Returning to game.");
344-
resume_game_from_home(console, context);
345-
context.wait_for_all_requests();
346-
console.log("Entered game.");
338+
void home_black_border_check(ConsoleHandle& console, ProControllerContext& context) {
339+
if (GameSettings::instance().DEVICE == GameSettings::Device::switch_1_2) {
340+
console.log("Switch 1 or 2 selected in Settings.");
341+
console.log("Going to home to check for black border.");
342+
pbf_press_button(context, BUTTON_HOME, 120ms, 880ms);
343+
context.wait_for_all_requests();
344+
StartProgramChecks::check_border(console);
345+
console.log("Returning to game.");
346+
resume_game_from_home(console, context);
347+
context.wait_for_all_requests();
348+
console.log("Entered game.");
349+
}else{
350+
console.log("Non-Switch device selected in Settings.");
351+
console.log("Skipping black border check.", COLOR_BLUE);
352+
}
347353
}
348354

349355

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace PokemonFRLG{
2121

2222
// Press A+B+Select+Start at the same time to soft reset, then re-enters the game.
2323
// There are two random waits, one before pressing start and another after loading in the game.
24-
// This is to prevent repeatedly getting the same pokemon, due to FRLG's RNG
25-
// For now this assumes no dry battery.
24+
// This is to prevent repeatedly getting the same pokemon, due to FRLG's RNG.
2625
uint64_t soft_reset(ConsoleHandle& console, ProControllerContext &context);
2726

2827
// From the overworld, open the summary of the Pokemon in slot 6. This assumes the menu cursor is in the top slot (POKEDEX)

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Settings.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,28 @@ GameSettings& GameSettings::instance(){
2020
static GameSettings settings;
2121
return settings;
2222
}
23+
GameSettings::~GameSettings(){
24+
DEVICE.remove_listener(*this);
25+
GAME_BOX.remove_listener(*this);
26+
GAME_BOX.X.remove_listener(*this);
27+
GAME_BOX.Y.remove_listener(*this);
28+
GAME_BOX.WIDTH.remove_listener(*this);
29+
GAME_BOX.HEIGHT.remove_listener(*this);
30+
}
2331
GameSettings::GameSettings()
2432
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
33+
, m_game_device_settings("<font size=4><b>Game Device settings:</b></font>")
34+
, DEVICE(
35+
"<b>Device:</b><br>Select the device the game is running on. "
36+
"Refer to the documentation for specific setups.",
37+
{
38+
{Device::switch_1_2, "switch_1_2", "Nintendo Switch 1 and 2"},
39+
//{Device::dev_test, "dev_test", "dev test rg35xx"},
40+
//{Device::custom, "custom", "Custom"},
41+
},
42+
LockMode::LOCK_WHILE_RUNNING,
43+
Device::switch_1_2
44+
)
2545
, GAME_BOX(
2646
"Game Box: The part of the screen containing the actual video feed.",
2747
LockMode::LOCK_WHILE_RUNNING,
@@ -57,16 +77,53 @@ GameSettings::GameSettings()
5777
1000, 0, 48000 //2000
5878
)
5979
{
80+
PA_ADD_STATIC(m_game_device_settings);
81+
PA_ADD_OPTION(DEVICE);
6082
PA_ADD_STATIC(GAME_BOX);
6183
PA_ADD_STATIC(m_soft_reset_timings);
6284
PA_ADD_OPTION(SELECT_BUTTON_MASH0);
6385
PA_ADD_OPTION(ENTER_GAME_WAIT0);
6486
PA_ADD_STATIC(m_shiny_audio_settings);
6587
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
6688
PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY);
67-
}
6889

90+
GameSettings::on_config_value_changed(this);
91+
DEVICE.add_listener(*this);
92+
GAME_BOX.add_listener(*this);
93+
GAME_BOX.X.add_listener(*this);
94+
GAME_BOX.Y.add_listener(*this);
95+
GAME_BOX.WIDTH.add_listener(*this);
96+
GAME_BOX.HEIGHT.add_listener(*this);
97+
}
6998

99+
void GameSettings::on_config_value_changed(void* object){
100+
switch (DEVICE){
101+
case Device::switch_1_2:
102+
GAME_BOX.X.set(0.09375);
103+
GAME_BOX.Y.set(0.00462963);
104+
GAME_BOX.WIDTH.set(0.8125);
105+
GAME_BOX.HEIGHT.set(0.962963);
106+
GAME_BOX.set_visibility(ConfigOptionState::DISABLED);
107+
break;
108+
case Device::dev_test:
109+
GAME_BOX.X.set(0.125);
110+
GAME_BOX.Y.set(0.0564814814814815);
111+
GAME_BOX.WIDTH.set(0.7494791666666667);
112+
GAME_BOX.HEIGHT.set(0.8861111111111111);
113+
GAME_BOX.set_visibility(ConfigOptionState::DISABLED);
114+
break;
115+
case Device::custom:
116+
GAME_BOX.set_visibility(ConfigOptionState::ENABLED);
117+
break;
118+
default:
119+
GAME_BOX.X.set(0.09375);
120+
GAME_BOX.Y.set(0.00462963);
121+
GAME_BOX.WIDTH.set(0.8125);
122+
GAME_BOX.HEIGHT.set(0.962963);
123+
GAME_BOX.set_visibility(ConfigOptionState::ENABLED);
124+
break;
125+
}
126+
}
70127

71128

72129

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Settings.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PokemonAutomation_PokemonFRLG_Settings_H
88
#define PokemonAutomation_PokemonFRLG_Settings_H
99

10+
#include "Common/Cpp/Options/EnumDropdownOption.h"
1011
#include "Common/Cpp/Options/StaticTextOption.h"
1112
#include "Common/Cpp/Options/FloatingPointOption.h"
1213
#include "Common/Cpp/Options/TimeDurationOption.h"
@@ -18,11 +19,21 @@ namespace NintendoSwitch{
1819
namespace PokemonFRLG{
1920

2021

21-
class GameSettings : public BatchOption{
22+
class GameSettings : public BatchOption, private ConfigOption::Listener{
23+
~GameSettings();
2224
GameSettings();
2325
public:
2426
static GameSettings& instance();
2527

28+
enum class Device{
29+
switch_1_2,
30+
dev_test,
31+
custom,
32+
};
33+
34+
SectionDividerOption m_game_device_settings;
35+
EnumDropdownOption<Device> DEVICE;
36+
2637
BoxOption GAME_BOX;
2738

2839
SectionDividerOption m_soft_reset_timings;
@@ -34,11 +45,12 @@ class GameSettings : public BatchOption{
3445
FloatingPointOption SHINY_SOUND_THRESHOLD;
3546
FloatingPointOption SHINY_SOUND_LOW_FREQUENCY;
3647

48+
private:
49+
virtual void on_config_value_changed(void* object) override;
3750
};
3851

3952

4053

41-
4254
class GameSettings_Descriptor : public PanelDescriptor{
4355
public:
4456
GameSettings_Descriptor();

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_GiftReset.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ GiftReset::GiftReset()
7878
&NOTIFICATION_SHINY,
7979
&NOTIFICATION_STATUS_UPDATE,
8080
&NOTIFICATION_PROGRAM_FINISH,
81+
&NOTIFICATION_ERROR_RECOVERABLE,
8182
})
8283
{
8384
PA_ADD_OPTION(TARGET);
@@ -126,6 +127,7 @@ void GiftReset::obtain_pokemon(SingleSwitchProgramEnvironment& env, ProControlle
126127
}
127128
env.log("Initial A press completed.");
128129
}else{
130+
//Need to double check what the first dialog box is for the other gifts
129131
pbf_press_button(context, BUTTON_A, 320ms, 640ms);
130132
}
131133
bool seen_selection_arrow = false;
@@ -253,6 +255,10 @@ bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControl
253255
if (ret < 0){
254256
env.update_stats();
255257
env.log("open_summary(): Unable to open Start menu after 10 attempts.", COLOR_RED);
258+
send_program_recoverable_error_notification(
259+
env, NOTIFICATION_ERROR_RECOVERABLE,
260+
"open_summary(): Unable to open Start menu after 10 attempts."
261+
);
256262
return false;
257263
}
258264

@@ -282,6 +288,10 @@ bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControl
282288
env.log("Entered party menu.");
283289
}else{
284290
env.log("open_summary(): Unable to enter party menu.", COLOR_RED);
291+
send_program_recoverable_error_notification(
292+
env, NOTIFICATION_ERROR_RECOVERABLE,
293+
"open_summary(): Unable to enter party menu."
294+
);
285295
return false;
286296
}
287297

@@ -307,6 +317,10 @@ bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControl
307317
env.log("Entered summary.");
308318
}else{
309319
env.log("open_summary(): Unable to enter summary.", COLOR_RED);
320+
send_program_recoverable_error_notification(
321+
env, NOTIFICATION_ERROR_RECOVERABLE,
322+
"open_summary(): Unable to enter summary."
323+
);
310324
return false;
311325
}
312326
pbf_wait(context, 1000ms);

0 commit comments

Comments
 (0)