Skip to content

Commit

Permalink
Migrate PLA and SV settings to TimeDurationOption.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Feb 3, 2025
1 parent 18c3c46 commit a63a142
Show file tree
Hide file tree
Showing 45 changed files with 132 additions and 153 deletions.
20 changes: 10 additions & 10 deletions Common/Qt/Options/TimeDurationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ TimeDurationOptionWidget<Type>::TimeDurationOptionWidget(QWidget& parent, TimeDu
, ConfigWidget(value, *this)
, m_value(value)
{
this->setToolTip(QString::fromStdString(
"Time duration in " + value.units() +
"<br><br>"
"For controller timings, this will be rounded "
"up to the tick size of the controller."
"<br><br>"
"The tick size for wired controllers is usually 8ms and are very precise."
"<br><br>"
"Wireless controllers have larger tick sizes and are imprecise due to wireless communication latency."
));

QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -102,6 +92,16 @@ TimeDurationOptionWidget<Type>::TimeDurationOptionWidget(QWidget& parent, TimeDu
m_box = new QLineEdit(QString::fromStdString(m_value.current_text()), this);
row0->addWidget(m_box);
row0->addWidget(new QLabel(QString::fromStdString(value.units()), this));
m_box->setToolTip(QString::fromStdString(
"Time duration in " + value.units() +
"<br><br>"
"For controller timings, this will be rounded "
"up to the tick size of the controller."
"<br><br>"
"The tick size for wired controllers is usually 8ms and are very precise."
"<br><br>"
"Wireless controllers have larger tick sizes and are imprecise due to wireless communication latency."
));

QLabel* description = new QLabel(QString::fromStdString(m_value.time_string()), this);
description->setAlignment(Qt::AlignHCenter);
Expand Down
9 changes: 4 additions & 5 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
*
*/

#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
#include "CommonFramework/Globals.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonBDSP_Settings.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{
using namespace Pokemon;

using namespace Pokemon;



Expand Down Expand Up @@ -181,9 +180,9 @@ GameSettings_Descriptor::GameSettings_Descriptor()
: PanelDescriptor(
Color(),
"PokemonBDSP:GlobalSettings",
STRING_POKEMON + " BDSP", STRING_POKEMON + " Settings",
STRING_POKEMON + " BDSP", "Game Settings",
"ComputerControl/blob/master/Wiki/Programs/PokemonBDSP/PokemonSettings.md",
"Global " + STRING_POKEMON + " Settings"
"Global " + STRING_POKEMON + " Brilliant Diamond and Shing Pearl Settings"
)
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void on_shiny_sound(
pbf_press_button(context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0);
}

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
context.wait_for_all_requests();
throw ProgramFinishedException();
}
Expand Down
46 changes: 15 additions & 31 deletions SerialPrograms/Source/PokemonLA/PokemonLA_Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*
*/

#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
#include "CommonFramework/Globals.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonLA_Settings.h"

Expand All @@ -29,25 +27,15 @@ GameSettings::GameSettings()
1.0, 0, 100
)
, m_menu_navigation("<font size=4><b>Menu Navigation Timings:</b></font>")
// , OVERWORLD_TO_MENU_DELAY(
// "<b>Overworld to Menu Delay:</b><br>Delay to bring up the menu when pressing X in the overworld.",
// "250"
// )
// , MENU_TO_OVERWORLD_DELAY(
// "<b>Menu to Overworld Delay:</b><br>Delay to go from menu back to overworld.",
// "250"
// )
, 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"
)
, LOAD_REGION_TIMEOUT(
, LOAD_REGION_TIMEOUT0(
"<b>Load Region Timeout:</b><br>Wait at most this long to enter a region before giving up.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"30 * TICKS_PER_SECOND"
"30s"
)
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
, START_GAME_MASH0(
Expand All @@ -58,19 +46,17 @@ GameSettings::GameSettings()
, START_GAME_WAIT1(
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
LockMode::LOCK_WHILE_RUNNING,
"40000ms"
"40s"
)
, 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,
"15 * TICKS_PER_SECOND"
"15s"
)
, m_advanced_options(
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
Expand Down Expand Up @@ -110,16 +96,14 @@ GameSettings::GameSettings()
PA_ADD_OPTION(POST_WARP_DELAY);

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(LOAD_REGION_TIMEOUT);
PA_ADD_OPTION(GAME_TO_HOME_DELAY0);
PA_ADD_OPTION(LOAD_REGION_TIMEOUT0);

PA_ADD_STATIC(m_start_game_timings);
PA_ADD_OPTION(START_GAME_MASH0);
PA_ADD_OPTION(START_GAME_WAIT1);
PA_ADD_OPTION(ENTER_GAME_MASH);
PA_ADD_OPTION(ENTER_GAME_WAIT);
PA_ADD_OPTION(ENTER_GAME_MASH0);
PA_ADD_OPTION(ENTER_GAME_WAIT0);

PA_ADD_STATIC(m_advanced_options);
PA_ADD_OPTION(SHINY_SOUND_THRESHOLD);
Expand All @@ -138,9 +122,9 @@ GameSettings_Descriptor::GameSettings_Descriptor()
: PanelDescriptor(
Color(),
"PokemonLA:GlobalSettings",
STRING_POKEMON + " LA", STRING_POKEMON + " Settings",
STRING_POKEMON + " LA", "Game Settings",
"ComputerControl/blob/master/Wiki/Programs/PokemonLA/PokemonSettings.md",
"Global " + STRING_POKEMON + " Settings"
"Global " + STRING_POKEMON + " Legends Arceus Settings"
)
{}

Expand Down
12 changes: 4 additions & 8 deletions SerialPrograms/Source/PokemonLA/PokemonLA_Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
#define PokemonAutomation_PokemonLA_Settings_H

#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/FloatingPointOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "CommonFramework/Panels/SettingsPanel.h"

namespace PokemonAutomation{
Expand All @@ -28,16 +26,14 @@ class GameSettings : public BatchOption{
FloatingPointOption POST_WARP_DELAY;

SectionDividerOption m_menu_navigation;
// TimeExpressionOption<uint16_t> OVERWORLD_TO_MENU_DELAY;
// TimeExpressionOption<uint16_t> MENU_TO_OVERWORLD_DELAY;
TimeExpressionOption<uint16_t> GAME_TO_HOME_DELAY;
TimeExpressionOption<uint16_t> LOAD_REGION_TIMEOUT;
MillisecondsOption GAME_TO_HOME_DELAY0;
MillisecondsOption LOAD_REGION_TIMEOUT0;

SectionDividerOption m_start_game_timings;
MillisecondsOption START_GAME_MASH0;
MillisecondsOption START_GAME_WAIT1;
TimeExpressionOption<uint16_t> ENTER_GAME_MASH;
TimeExpressionOption<uint16_t> ENTER_GAME_WAIT;
MillisecondsOption ENTER_GAME_MASH0;
MillisecondsOption ENTER_GAME_WAIT0;

SectionDividerOption m_advanced_options;
FloatingPointOption SHINY_SOUND_THRESHOLD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ void LeapGrinder::program(SingleSwitchProgramEnvironment& env, SwitchControllerC
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
// Switch from items to pokemons
pbf_press_button(context, BUTTON_X, 20, 30);
}
}

env.update_stats();
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void NuggetFarmerHighlands::program(SingleSwitchProgramEnvironment& env, SwitchC
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void DistortionWaiter::program(SingleSwitchProgramEnvironment& env, SwitchContro
{}, "",
env.console.video().snapshot()
);
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ bool OutbreakFinder::run_iteration(
}

env.log("No target MMO sprite found. Reset game...");
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void RamanasCombeeFinder::program(SingleSwitchProgramEnvironment& env, SwitchCon
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool reset_game_to_gamemenu(

bool gamemenu_to_ingame(
VideoStream& stream, SwitchControllerContext& context,
uint16_t mash_duration, uint16_t enter_game_timeout
Milliseconds mash_duration, Milliseconds enter_game_timeout
){
stream.log("Mashing A to enter game...");
BlackScreenOverWatcher detector(COLOR_RED, {0.2, 0.2, 0.6, 0.6});
Expand Down Expand Up @@ -81,7 +81,11 @@ bool reset_game_from_home(
){
bool ok = true;
ok &= reset_game_to_gamemenu(stream, context, tolerate_update_menu);
ok &= gamemenu_to_ingame(stream, context, GameSettings::instance().ENTER_GAME_MASH, GameSettings::instance().ENTER_GAME_WAIT);
ok &= gamemenu_to_ingame(
stream, context,
GameSettings::instance().ENTER_GAME_MASH0,
GameSettings::instance().ENTER_GAME_WAIT0
);
if (!ok){
dump_image(stream.logger(), env.program_info(), stream.video(), "StartGame");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool reset_game_to_gamemenu(
// mash A to enter the game and wait until the black screen is gone.
bool gamemenu_to_ingame(
VideoStream& stream, SwitchControllerContext& context,
uint16_t mash_duration, uint16_t enter_game_timeout
Milliseconds mash_duration, Milliseconds enter_game_timeout
);

// From Switch Home menu, start game and wait until the player character appears in game.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void mash_A_to_change_region(
int ret = run_until<SwitchControllerContext>(
stream, context,
[](SwitchControllerContext& context){
pbf_mash_button(context, BUTTON_A, GameSettings::instance().LOAD_REGION_TIMEOUT);
pbf_mash_button(context, BUTTON_A, GameSettings::instance().LOAD_REGION_TIMEOUT0);
},
{
{black_screen1a},
Expand All @@ -200,7 +200,7 @@ void mash_A_to_change_region(
ArcPhoneDetector phone(stream.logger(), stream.overlay(), std::chrono::milliseconds(250), true);
int ret = wait_until(
stream, context,
Milliseconds(GameSettings::instance().LOAD_REGION_TIMEOUT * 1000 / TICKS_PER_SECOND),
GameSettings::instance().LOAD_REGION_TIMEOUT0,
{phone}
);
if (ret < 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ void BurmyFinder::program(SingleSwitchProgramEnvironment& env, SwitchControllerC
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void CrobatFinder::run_iteration(SingleSwitchProgramEnvironment& env, SwitchCont
// then reset since no shiny was found
env.console.log("No shiny detected, restarting the game!");

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}

Expand All @@ -198,7 +198,7 @@ void CrobatFinder::program(SingleSwitchProgramEnvironment& env, SwitchController
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void FroslassFinder::run_iteration(SingleSwitchProgramEnvironment& env, SwitchCo
}

env.console.log("No shiny detected, Reset game!");
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}

Expand All @@ -177,7 +177,7 @@ void FroslassFinder::program(SingleSwitchProgramEnvironment& env, SwitchControll
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void GalladeFinder::run_iteration(SingleSwitchProgramEnvironment& env, SwitchCon
// then reset
env.console.log("No shiny detected, restarting the game!");

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}

Expand All @@ -183,7 +183,7 @@ void GalladeFinder::program(SingleSwitchProgramEnvironment& env, SwitchControlle
stats.errors++;
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void PostMMOSpawnReset::run_iteration(SingleSwitchProgramEnvironment& env, Switc
PostMMOSpawnReset_Descriptor::Stats& stats = env.current_stats<PostMMOSpawnReset_Descriptor::Stats>();

// From game to Switch Home
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
{
float shiny_coefficient = 1.0;
ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void ShinyHuntCustomPath::program(SingleSwitchProgramEnvironment& env, SwitchCon

if(RESET_METHOD == ResetMethod::SoftReset){
env.console.log("Resetting by closing the game.");
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}else{
env.console.log("Resetting by going to village.");
Expand All @@ -326,7 +326,7 @@ void ShinyHuntCustomPath::program(SingleSwitchProgramEnvironment& env, SwitchCon
e.send_notification(env, NOTIFICATION_ERROR_RECOVERABLE);

time_reset_run_count = 0;
pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
reset_game_from_home(env, env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}

Expand Down
Loading

0 comments on commit a63a142

Please sign in to comment.