Skip to content

Commit

Permalink
Migrate Switch and BDSP settings over to TimeDurationOption.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Feb 2, 2025
1 parent 22d3be8 commit cbb64a7
Show file tree
Hide file tree
Showing 76 changed files with 393 additions and 366 deletions.
6 changes: 5 additions & 1 deletion Common/Cpp/Options/TimeDurationOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class MillisecondsOption : public TimeDurationOption<std::chrono::milliseconds>{
public:
template <class... Args>
MillisecondsOption(std::string label, Args&&... args)
: TimeDurationOption<std::chrono::milliseconds>(std::move(label), "milliseconds", std::forward<Args>(args)...)
: TimeDurationOption<std::chrono::milliseconds>(
std::move(label),
"milliseconds",
std::forward<Args>(args)...
)
{}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void pbf_mash_button(SwitchControllerContext& context, Button button, Millisecon
void grip_menu_connect_go_home(SwitchControllerContext& context){
pbf_press_button(context, BUTTON_L | BUTTON_R, 10, 40);
pbf_press_button(context, BUTTON_A, 10, 140);
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 80ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
namespace PokemonAutomation{
namespace NintendoSwitch{


using namespace std::chrono_literals;


// Wait for this many ticks on the Switch.
void pbf_wait (SwitchControllerContext& context, uint16_t ticks);
void pbf_wait (SwitchControllerContext& context, Milliseconds duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void change_date(
pbf_press_button(context, BUTTON_A, 20, 30);

// Re-enter the game.
pbf_press_button(context, BUTTON_HOME, 20, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);

return;
}
Expand Down
22 changes: 6 additions & 16 deletions SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*
*/

#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
#include "NintendoSwitch_Settings.h"

#include <iostream>
Expand All @@ -24,17 +23,10 @@ ConsoleSettings& ConsoleSettings::instance(){
}
ConsoleSettings::ConsoleSettings()
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
, CONNECT_CONTROLLER_DELAY(
"<b>Connection Controller Delay:</b><br>Wait this long before starting the program. The LEDs normally flash during this time.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"5 * TICKS_PER_SECOND"
)
, SETTINGS_TO_HOME_DELAY(
, SETTINGS_TO_HOME_DELAY0(
"<b>Settings to Home Delay:</b><br>Delay from pressing home anywhere in the settings to return to the home menu.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"120"
"960ms"
)
, START_GAME_REQUIRES_INTERNET(
"<b>Start Game Requires Internet:</b><br>"
Expand All @@ -43,12 +35,11 @@ ConsoleSettings::ConsoleSettings()
LockMode::LOCK_WHILE_RUNNING,
false
)
, START_GAME_INTERNET_CHECK_DELAY(
, START_GAME_INTERNET_CHECK_DELAY0(
"<b>Start Game Internet Check Delay:</b><br>"
"If starting the game requires checking the internet, wait this long for it.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"3 * TICKS_PER_SECOND"
"3000ms"
)
, TOLERATE_SYSTEM_UPDATE_MENU_FAST(
"<b>Tolerate System Update Menu (fast):</b><br>"
Expand All @@ -65,10 +56,9 @@ ConsoleSettings::ConsoleSettings()
)
, KEYBOARD_SECTION("<font size=4><b>Keyboard to Controller Mappings:</b></font>")
{
PA_ADD_OPTION(CONNECT_CONTROLLER_DELAY);
PA_ADD_OPTION(SETTINGS_TO_HOME_DELAY);
PA_ADD_OPTION(SETTINGS_TO_HOME_DELAY0);
PA_ADD_OPTION(START_GAME_REQUIRES_INTERNET);
PA_ADD_OPTION(START_GAME_INTERNET_CHECK_DELAY);
PA_ADD_OPTION(START_GAME_INTERNET_CHECK_DELAY0);
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_FAST);
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_SLOW);
PA_ADD_STATIC(KEYBOARD_SECTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "Common/Cpp/ImageResolution.h"
#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
//#include "Common/Cpp/Options/StringOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "CommonFramework/Panels/SettingsPanel.h"
#include "Controllers/NintendoSwitch_KeyboardMapping.h"

Expand All @@ -28,10 +27,9 @@ class ConsoleSettings : public BatchOption{
public:
static ConsoleSettings& instance();

TimeExpressionOption<uint16_t> CONNECT_CONTROLLER_DELAY;
TimeExpressionOption<uint16_t> SETTINGS_TO_HOME_DELAY;
MillisecondsOption SETTINGS_TO_HOME_DELAY0;
BooleanCheckBoxOption START_GAME_REQUIRES_INTERNET;
TimeExpressionOption<uint16_t> START_GAME_INTERNET_CHECK_DELAY;
MillisecondsOption START_GAME_INTERNET_CHECK_DELAY0;
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_FAST;
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_SLOW;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void FriendCodeAdder::program(SingleSwitchProgramEnvironment& env, SwitchControl
pbf_wait(context, SEARCH_TIME);
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 80ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
#include "NintendoSwitch/Inference/NintendoSwitch_DetectHome.h"
#include "NintendoSwitch_GameEntry.h"

Expand Down Expand Up @@ -93,7 +94,7 @@ void start_game_from_home_with_inference(
VideoStream& stream, SwitchControllerContext& context,
uint8_t game_slot,
uint8_t user_slot,
uint16_t start_game_wait
Milliseconds start_game_wait
){
context.wait_for_all_requests();
{
Expand All @@ -118,7 +119,7 @@ void start_game_from_home_with_inference(
}

if (game_slot != 0){
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY - 10);
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 80ms);
for (uint8_t c = 1; c < game_slot; c++){
pbf_press_dpad(context, DPAD_RIGHT, 5, 5);
}
Expand Down Expand Up @@ -157,7 +158,7 @@ void start_game_from_home_with_inference(
case 1:
stream.log("Detected user-select screen.");
move_to_user(context, user_slot);
pbf_press_button(context, BUTTON_A, 10, start_game_wait);
pbf_press_button(context, BUTTON_A, 80ms, start_game_wait);
break;
case 2:
stream.log("Detected update menu.", COLOR_RED);
Expand Down Expand Up @@ -187,7 +188,7 @@ void start_game_from_home(
bool tolerate_update_menu,
uint8_t game_slot,
uint8_t user_slot,
uint16_t start_game_mash
Milliseconds start_game_mash
){
context.wait_for_all_requests();
if (stream.video().snapshot()){
Expand All @@ -199,7 +200,7 @@ void start_game_from_home(
}

if (game_slot != 0){
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY - 10);
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 80ms);
for (uint8_t c = 1; c < game_slot; c++){
pbf_press_dpad(context, DPAD_RIGHT, 5, 5);
}
Expand Down Expand Up @@ -231,10 +232,10 @@ void start_game_from_home(

// Switch to mashing ZL instead of A to get into the game.
// Mash your way into the game.
uint16_t duration = start_game_mash;
Milliseconds duration = start_game_mash;
if (ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET){
// Need to wait a bit longer for the internet check.
duration += ConsoleSettings::instance().START_GAME_INTERNET_CHECK_DELAY;
duration += ConsoleSettings::instance().START_GAME_INTERNET_CHECK_DELAY0;
}
// pbf_mash_button(context, BUTTON_ZL, duration);
pbf_wait(context, duration);
Expand Down Expand Up @@ -277,14 +278,14 @@ class GameLoadingDetector : public VisualInferenceCallback{

bool openedgame_to_gamemenu(
VideoStream& stream, SwitchControllerContext& context,
uint16_t timeout
Milliseconds timeout
){
{
stream.log("Waiting to load game...");
GameLoadingDetector detector(false);
int ret = wait_until(
stream, context,
std::chrono::milliseconds(timeout * (1000 / TICKS_PER_SECOND)),
timeout,
{{detector}}
);
if (ret < 0){
Expand All @@ -297,7 +298,7 @@ bool openedgame_to_gamemenu(
GameLoadingDetector detector(true);
int ret = wait_until(
stream, context,
std::chrono::milliseconds(timeout * (1000 / TICKS_PER_SECOND)),
timeout,
{{detector}}
);
if (ret < 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ void start_game_from_home(
bool tolerate_update_menu,
uint8_t game_slot,
uint8_t user_slot,
uint16_t start_game_mash
Milliseconds start_game_mash
);

bool openedgame_to_gamemenu(
VideoStream& stream, SwitchControllerContext& context,
uint16_t timeout
Milliseconds timeout
);


Expand Down
98 changes: 42 additions & 56 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,91 +23,77 @@ GameSettings& GameSettings::instance(){
GameSettings::GameSettings()
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
, m_menu_navigation("<font size=4><b>Menu Navigation Timings:</b></font>")
, OVERWORLD_TO_MENU_DELAY(
, OVERWORLD_TO_MENU_DELAY0(
"<b>Overworld to Menu Delay:</b><br>Delay to bring up the menu when pressing X in the overworld.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"250"
"2000ms"
)
, MENU_TO_OVERWORLD_DELAY(
, MENU_TO_OVERWORLD_DELAY0(
"<b>Menu to Overworld Delay:</b><br>Delay to go from menu back to overworld.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"250"
"2000ms"
)
, GAME_TO_HOME_DELAY(
, GAME_TO_HOME_DELAY0(
"<b>Game to Home Delay:</b><br>Delay from pressing home to entering the the Switch home menu.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"125"
"1000ms"
)
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
, START_GAME_MASH(
, START_GAME_MASH0(
"<b>1. Start Game Mash:</b><br>Mash A for this long to start the game.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"2 * TICKS_PER_SECOND"
"2000ms"
)
, START_GAME_WAIT(
, START_GAME_WAIT0(
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"40 * TICKS_PER_SECOND"
"300s"
)
, ENTER_GAME_MASH(
, ENTER_GAME_MASH0(
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"5 * TICKS_PER_SECOND"
"5000ms"
)
, ENTER_GAME_WAIT(
, ENTER_GAME_WAIT0(
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"40 * TICKS_PER_SECOND"
"300s"
)
, m_box_timings("<font size=4><b>Box Timings:</b></font> (for egg programs)")
, BOX_SCROLL_DELAY_0(
, BOX_SCROLL_DELAY0(
"<b>Box Scroll Delay:</b><br>Delay to move the cursor.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"30"
"240ms"
)
, BOX_CHANGE_DELAY_0(
, BOX_CHANGE_DELAY0(
"<b>Box Change Delay:</b><br>Delay to change boxes.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"200"
"1600ms"
)
, BOX_PICKUP_DROP_DELAY(
, BOX_PICKUP_DROP_DELAY0(
"<b>Box Pickup/Drop Delay:</b><br>Delay to pickup/drop " + STRING_POKEMON + ".",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"50"
"400ms"
)
, MENU_TO_POKEMON_DELAY(
, MENU_TO_POKEMON_DELAY0(
"<b>Menu To " + STRING_POKEMON + " Delay:</b><br>Delay to enter " + STRING_POKEMON + " menu.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"300"
"2400ms"
)
, POKEMON_TO_BOX_DELAY0(
, POKEMON_TO_BOX_DELAY1(
"<b>" + STRING_POKEMON + " to Box Delay:</b><br>Delay to enter box system.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"320"
"2560ms"
)
, BOX_TO_POKEMON_DELAY(
, BOX_TO_POKEMON_DELAY0(
"<b>Box to " + STRING_POKEMON + " Delay:</b><br>Delay to exit box system.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"250"
"2000ms"
)
, POKEMON_TO_MENU_DELAY(
, POKEMON_TO_MENU_DELAY0(
"<b>" + STRING_POKEMON + " to Menu Delay:</b><br>Delay to return to menu.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"250"
"2000ms"
)
, m_advanced_options(
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
Expand Down Expand Up @@ -155,24 +141,24 @@ GameSettings::GameSettings()
// , m_experimental("<font size=4><b>Experimental/Beta Features:</b></font>")
{
PA_ADD_STATIC(m_menu_navigation);
PA_ADD_OPTION(OVERWORLD_TO_MENU_DELAY);
PA_ADD_OPTION(MENU_TO_OVERWORLD_DELAY);
PA_ADD_OPTION(GAME_TO_HOME_DELAY);
PA_ADD_OPTION(OVERWORLD_TO_MENU_DELAY0);
PA_ADD_OPTION(MENU_TO_OVERWORLD_DELAY0);
PA_ADD_OPTION(GAME_TO_HOME_DELAY0);

PA_ADD_STATIC(m_start_game_timings);
PA_ADD_OPTION(START_GAME_MASH);
PA_ADD_OPTION(START_GAME_WAIT);
PA_ADD_OPTION(ENTER_GAME_MASH);
PA_ADD_OPTION(ENTER_GAME_WAIT);
PA_ADD_OPTION(START_GAME_MASH0);
PA_ADD_OPTION(START_GAME_WAIT0);
PA_ADD_OPTION(ENTER_GAME_MASH0);
PA_ADD_OPTION(ENTER_GAME_WAIT0);

PA_ADD_STATIC(m_box_timings);
PA_ADD_OPTION(BOX_SCROLL_DELAY_0);
PA_ADD_OPTION(BOX_CHANGE_DELAY_0);
PA_ADD_OPTION(BOX_PICKUP_DROP_DELAY);
PA_ADD_OPTION(MENU_TO_POKEMON_DELAY);
PA_ADD_OPTION(POKEMON_TO_BOX_DELAY0);
PA_ADD_OPTION(BOX_TO_POKEMON_DELAY);
PA_ADD_OPTION(POKEMON_TO_MENU_DELAY);
PA_ADD_OPTION(BOX_SCROLL_DELAY0);
PA_ADD_OPTION(BOX_CHANGE_DELAY0);
PA_ADD_OPTION(BOX_PICKUP_DROP_DELAY0);
PA_ADD_OPTION(MENU_TO_POKEMON_DELAY0);
PA_ADD_OPTION(POKEMON_TO_BOX_DELAY1);
PA_ADD_OPTION(BOX_TO_POKEMON_DELAY0);
PA_ADD_OPTION(POKEMON_TO_MENU_DELAY0);

PA_ADD_STATIC(m_advanced_options);
PA_ADD_OPTION(SHINY_ALPHA_OVERALL_THRESHOLD);
Expand Down
Loading

0 comments on commit cbb64a7

Please sign in to comment.