Skip to content

Commit cbb64a7

Browse files
committed
Migrate Switch and BDSP settings over to TimeDurationOption.
1 parent 22d3be8 commit cbb64a7

File tree

76 files changed

+393
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+393
-366
lines changed

Common/Cpp/Options/TimeDurationOption.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ class MillisecondsOption : public TimeDurationOption<std::chrono::milliseconds>{
109109
public:
110110
template <class... Args>
111111
MillisecondsOption(std::string label, Args&&... args)
112-
: TimeDurationOption<std::chrono::milliseconds>(std::move(label), "milliseconds", std::forward<Args>(args)...)
112+
: TimeDurationOption<std::chrono::milliseconds>(
113+
std::move(label),
114+
"milliseconds",
115+
std::forward<Args>(args)...
116+
)
113117
{}
114118
};
115119

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void pbf_mash_button(SwitchControllerContext& context, Button button, Millisecon
8080
void grip_menu_connect_go_home(SwitchControllerContext& context){
8181
pbf_press_button(context, BUTTON_L | BUTTON_R, 10, 40);
8282
pbf_press_button(context, BUTTON_A, 10, 140);
83-
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY);
83+
pbf_press_button(context, BUTTON_HOME, 80ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
8484
}
8585

8686

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
namespace PokemonAutomation{
2424
namespace NintendoSwitch{
2525

26+
27+
using namespace std::chrono_literals;
28+
29+
2630
// Wait for this many ticks on the Switch.
2731
void pbf_wait (SwitchControllerContext& context, uint16_t ticks);
2832
void pbf_wait (SwitchControllerContext& context, Milliseconds duration);

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void change_date(
628628
pbf_press_button(context, BUTTON_A, 20, 30);
629629

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

633633
return;
634634
}

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*
55
*/
66

7-
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
87
#include "NintendoSwitch_Settings.h"
98

109
#include <iostream>
@@ -24,17 +23,10 @@ ConsoleSettings& ConsoleSettings::instance(){
2423
}
2524
ConsoleSettings::ConsoleSettings()
2625
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
27-
, CONNECT_CONTROLLER_DELAY(
28-
"<b>Connection Controller Delay:</b><br>Wait this long before starting the program. The LEDs normally flash during this time.",
29-
LockMode::LOCK_WHILE_RUNNING,
30-
TICKS_PER_SECOND,
31-
"5 * TICKS_PER_SECOND"
32-
)
33-
, SETTINGS_TO_HOME_DELAY(
26+
, SETTINGS_TO_HOME_DELAY0(
3427
"<b>Settings to Home Delay:</b><br>Delay from pressing home anywhere in the settings to return to the home menu.",
3528
LockMode::LOCK_WHILE_RUNNING,
36-
TICKS_PER_SECOND,
37-
"120"
29+
"960ms"
3830
)
3931
, START_GAME_REQUIRES_INTERNET(
4032
"<b>Start Game Requires Internet:</b><br>"
@@ -43,12 +35,11 @@ ConsoleSettings::ConsoleSettings()
4335
LockMode::LOCK_WHILE_RUNNING,
4436
false
4537
)
46-
, START_GAME_INTERNET_CHECK_DELAY(
38+
, START_GAME_INTERNET_CHECK_DELAY0(
4739
"<b>Start Game Internet Check Delay:</b><br>"
4840
"If starting the game requires checking the internet, wait this long for it.",
4941
LockMode::LOCK_WHILE_RUNNING,
50-
TICKS_PER_SECOND,
51-
"3 * TICKS_PER_SECOND"
42+
"3000ms"
5243
)
5344
, TOLERATE_SYSTEM_UPDATE_MENU_FAST(
5445
"<b>Tolerate System Update Menu (fast):</b><br>"
@@ -65,10 +56,9 @@ ConsoleSettings::ConsoleSettings()
6556
)
6657
, KEYBOARD_SECTION("<font size=4><b>Keyboard to Controller Mappings:</b></font>")
6758
{
68-
PA_ADD_OPTION(CONNECT_CONTROLLER_DELAY);
69-
PA_ADD_OPTION(SETTINGS_TO_HOME_DELAY);
59+
PA_ADD_OPTION(SETTINGS_TO_HOME_DELAY0);
7060
PA_ADD_OPTION(START_GAME_REQUIRES_INTERNET);
71-
PA_ADD_OPTION(START_GAME_INTERNET_CHECK_DELAY);
61+
PA_ADD_OPTION(START_GAME_INTERNET_CHECK_DELAY0);
7262
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_FAST);
7363
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_SLOW);
7464
PA_ADD_STATIC(KEYBOARD_SECTION);

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include "Common/Cpp/ImageResolution.h"
1111
#include "Common/Cpp/Options/StaticTextOption.h"
1212
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
13-
//#include "Common/Cpp/Options/StringOption.h"
14-
#include "Common/Cpp/Options/TimeExpressionOption.h"
13+
#include "Common/Cpp/Options/TimeDurationOption.h"
1514
#include "CommonFramework/Panels/SettingsPanel.h"
1615
#include "Controllers/NintendoSwitch_KeyboardMapping.h"
1716

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

31-
TimeExpressionOption<uint16_t> CONNECT_CONTROLLER_DELAY;
32-
TimeExpressionOption<uint16_t> SETTINGS_TO_HOME_DELAY;
30+
MillisecondsOption SETTINGS_TO_HOME_DELAY0;
3331
BooleanCheckBoxOption START_GAME_REQUIRES_INTERNET;
34-
TimeExpressionOption<uint16_t> START_GAME_INTERNET_CHECK_DELAY;
32+
MillisecondsOption START_GAME_INTERNET_CHECK_DELAY0;
3533
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_FAST;
3634
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_SLOW;
3735

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void FriendCodeAdder::program(SingleSwitchProgramEnvironment& env, SwitchControl
9090
pbf_wait(context, SEARCH_TIME);
9191
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
9292
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
93-
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY);
93+
pbf_press_button(context, BUTTON_HOME, 80ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
9494
}
9595
}
9696

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1616
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1717
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
18+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1819
#include "NintendoSwitch/Inference/NintendoSwitch_DetectHome.h"
1920
#include "NintendoSwitch_GameEntry.h"
2021

@@ -93,7 +94,7 @@ void start_game_from_home_with_inference(
9394
VideoStream& stream, SwitchControllerContext& context,
9495
uint8_t game_slot,
9596
uint8_t user_slot,
96-
uint16_t start_game_wait
97+
Milliseconds start_game_wait
9798
){
9899
context.wait_for_all_requests();
99100
{
@@ -118,7 +119,7 @@ void start_game_from_home_with_inference(
118119
}
119120

120121
if (game_slot != 0){
121-
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY - 10);
122+
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 80ms);
122123
for (uint8_t c = 1; c < game_slot; c++){
123124
pbf_press_dpad(context, DPAD_RIGHT, 5, 5);
124125
}
@@ -157,7 +158,7 @@ void start_game_from_home_with_inference(
157158
case 1:
158159
stream.log("Detected user-select screen.");
159160
move_to_user(context, user_slot);
160-
pbf_press_button(context, BUTTON_A, 10, start_game_wait);
161+
pbf_press_button(context, BUTTON_A, 80ms, start_game_wait);
161162
break;
162163
case 2:
163164
stream.log("Detected update menu.", COLOR_RED);
@@ -187,7 +188,7 @@ void start_game_from_home(
187188
bool tolerate_update_menu,
188189
uint8_t game_slot,
189190
uint8_t user_slot,
190-
uint16_t start_game_mash
191+
Milliseconds start_game_mash
191192
){
192193
context.wait_for_all_requests();
193194
if (stream.video().snapshot()){
@@ -199,7 +200,7 @@ void start_game_from_home(
199200
}
200201

201202
if (game_slot != 0){
202-
pbf_press_button(context, BUTTON_HOME, 10, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY - 10);
203+
ssf_press_button(context, BUTTON_HOME, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0, 80ms);
203204
for (uint8_t c = 1; c < game_slot; c++){
204205
pbf_press_dpad(context, DPAD_RIGHT, 5, 5);
205206
}
@@ -231,10 +232,10 @@ void start_game_from_home(
231232

232233
// Switch to mashing ZL instead of A to get into the game.
233234
// Mash your way into the game.
234-
uint16_t duration = start_game_mash;
235+
Milliseconds duration = start_game_mash;
235236
if (ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET){
236237
// Need to wait a bit longer for the internet check.
237-
duration += ConsoleSettings::instance().START_GAME_INTERNET_CHECK_DELAY;
238+
duration += ConsoleSettings::instance().START_GAME_INTERNET_CHECK_DELAY0;
238239
}
239240
// pbf_mash_button(context, BUTTON_ZL, duration);
240241
pbf_wait(context, duration);
@@ -277,14 +278,14 @@ class GameLoadingDetector : public VisualInferenceCallback{
277278

278279
bool openedgame_to_gamemenu(
279280
VideoStream& stream, SwitchControllerContext& context,
280-
uint16_t timeout
281+
Milliseconds timeout
281282
){
282283
{
283284
stream.log("Waiting to load game...");
284285
GameLoadingDetector detector(false);
285286
int ret = wait_until(
286287
stream, context,
287-
std::chrono::milliseconds(timeout * (1000 / TICKS_PER_SECOND)),
288+
timeout,
288289
{{detector}}
289290
);
290291
if (ret < 0){
@@ -297,7 +298,7 @@ bool openedgame_to_gamemenu(
297298
GameLoadingDetector detector(true);
298299
int ret = wait_until(
299300
stream, context,
300-
std::chrono::milliseconds(timeout * (1000 / TICKS_PER_SECOND)),
301+
timeout,
301302
{{detector}}
302303
);
303304
if (ret < 0){

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ void start_game_from_home(
2525
bool tolerate_update_menu,
2626
uint8_t game_slot,
2727
uint8_t user_slot,
28-
uint16_t start_game_mash
28+
Milliseconds start_game_mash
2929
);
3030

3131
bool openedgame_to_gamemenu(
3232
VideoStream& stream, SwitchControllerContext& context,
33-
uint16_t timeout
33+
Milliseconds timeout
3434
);
3535

3636

SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Settings.cpp

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,91 +23,77 @@ GameSettings& GameSettings::instance(){
2323
GameSettings::GameSettings()
2424
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
2525
, m_menu_navigation("<font size=4><b>Menu Navigation Timings:</b></font>")
26-
, OVERWORLD_TO_MENU_DELAY(
26+
, OVERWORLD_TO_MENU_DELAY0(
2727
"<b>Overworld to Menu Delay:</b><br>Delay to bring up the menu when pressing X in the overworld.",
2828
LockMode::LOCK_WHILE_RUNNING,
29-
TICKS_PER_SECOND,
30-
"250"
29+
"2000ms"
3130
)
32-
, MENU_TO_OVERWORLD_DELAY(
31+
, MENU_TO_OVERWORLD_DELAY0(
3332
"<b>Menu to Overworld Delay:</b><br>Delay to go from menu back to overworld.",
3433
LockMode::LOCK_WHILE_RUNNING,
35-
TICKS_PER_SECOND,
36-
"250"
34+
"2000ms"
3735
)
38-
, GAME_TO_HOME_DELAY(
36+
, GAME_TO_HOME_DELAY0(
3937
"<b>Game to Home Delay:</b><br>Delay from pressing home to entering the the Switch home menu.",
4038
LockMode::LOCK_WHILE_RUNNING,
41-
TICKS_PER_SECOND,
42-
"125"
39+
"1000ms"
4340
)
4441
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
45-
, START_GAME_MASH(
42+
, START_GAME_MASH0(
4643
"<b>1. Start Game Mash:</b><br>Mash A for this long to start the game.",
4744
LockMode::LOCK_WHILE_RUNNING,
48-
TICKS_PER_SECOND,
49-
"2 * TICKS_PER_SECOND"
45+
"2000ms"
5046
)
51-
, START_GAME_WAIT(
47+
, START_GAME_WAIT0(
5248
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
5349
LockMode::LOCK_WHILE_RUNNING,
54-
TICKS_PER_SECOND,
55-
"40 * TICKS_PER_SECOND"
50+
"300s"
5651
)
57-
, ENTER_GAME_MASH(
52+
, ENTER_GAME_MASH0(
5853
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
5954
LockMode::LOCK_WHILE_RUNNING,
60-
TICKS_PER_SECOND,
61-
"5 * TICKS_PER_SECOND"
55+
"5000ms"
6256
)
63-
, ENTER_GAME_WAIT(
57+
, ENTER_GAME_WAIT0(
6458
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
6559
LockMode::LOCK_WHILE_RUNNING,
66-
TICKS_PER_SECOND,
67-
"40 * TICKS_PER_SECOND"
60+
"300s"
6861
)
6962
, m_box_timings("<font size=4><b>Box Timings:</b></font> (for egg programs)")
70-
, BOX_SCROLL_DELAY_0(
63+
, BOX_SCROLL_DELAY0(
7164
"<b>Box Scroll Delay:</b><br>Delay to move the cursor.",
7265
LockMode::LOCK_WHILE_RUNNING,
73-
TICKS_PER_SECOND,
74-
"30"
66+
"240ms"
7567
)
76-
, BOX_CHANGE_DELAY_0(
68+
, BOX_CHANGE_DELAY0(
7769
"<b>Box Change Delay:</b><br>Delay to change boxes.",
7870
LockMode::LOCK_WHILE_RUNNING,
79-
TICKS_PER_SECOND,
80-
"200"
71+
"1600ms"
8172
)
82-
, BOX_PICKUP_DROP_DELAY(
73+
, BOX_PICKUP_DROP_DELAY0(
8374
"<b>Box Pickup/Drop Delay:</b><br>Delay to pickup/drop " + STRING_POKEMON + ".",
8475
LockMode::LOCK_WHILE_RUNNING,
85-
TICKS_PER_SECOND,
86-
"50"
76+
"400ms"
8777
)
88-
, MENU_TO_POKEMON_DELAY(
78+
, MENU_TO_POKEMON_DELAY0(
8979
"<b>Menu To " + STRING_POKEMON + " Delay:</b><br>Delay to enter " + STRING_POKEMON + " menu.",
9080
LockMode::LOCK_WHILE_RUNNING,
91-
TICKS_PER_SECOND,
92-
"300"
81+
"2400ms"
9382
)
94-
, POKEMON_TO_BOX_DELAY0(
83+
, POKEMON_TO_BOX_DELAY1(
9584
"<b>" + STRING_POKEMON + " to Box Delay:</b><br>Delay to enter box system.",
9685
LockMode::LOCK_WHILE_RUNNING,
97-
TICKS_PER_SECOND,
98-
"320"
86+
"2560ms"
9987
)
100-
, BOX_TO_POKEMON_DELAY(
88+
, BOX_TO_POKEMON_DELAY0(
10189
"<b>Box to " + STRING_POKEMON + " Delay:</b><br>Delay to exit box system.",
10290
LockMode::LOCK_WHILE_RUNNING,
103-
TICKS_PER_SECOND,
104-
"250"
91+
"2000ms"
10592
)
106-
, POKEMON_TO_MENU_DELAY(
93+
, POKEMON_TO_MENU_DELAY0(
10794
"<b>" + STRING_POKEMON + " to Menu Delay:</b><br>Delay to return to menu.",
10895
LockMode::LOCK_WHILE_RUNNING,
109-
TICKS_PER_SECOND,
110-
"250"
96+
"2000ms"
11197
)
11298
, m_advanced_options(
11399
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
@@ -155,24 +141,24 @@ GameSettings::GameSettings()
155141
// , m_experimental("<font size=4><b>Experimental/Beta Features:</b></font>")
156142
{
157143
PA_ADD_STATIC(m_menu_navigation);
158-
PA_ADD_OPTION(OVERWORLD_TO_MENU_DELAY);
159-
PA_ADD_OPTION(MENU_TO_OVERWORLD_DELAY);
160-
PA_ADD_OPTION(GAME_TO_HOME_DELAY);
144+
PA_ADD_OPTION(OVERWORLD_TO_MENU_DELAY0);
145+
PA_ADD_OPTION(MENU_TO_OVERWORLD_DELAY0);
146+
PA_ADD_OPTION(GAME_TO_HOME_DELAY0);
161147

162148
PA_ADD_STATIC(m_start_game_timings);
163-
PA_ADD_OPTION(START_GAME_MASH);
164-
PA_ADD_OPTION(START_GAME_WAIT);
165-
PA_ADD_OPTION(ENTER_GAME_MASH);
166-
PA_ADD_OPTION(ENTER_GAME_WAIT);
149+
PA_ADD_OPTION(START_GAME_MASH0);
150+
PA_ADD_OPTION(START_GAME_WAIT0);
151+
PA_ADD_OPTION(ENTER_GAME_MASH0);
152+
PA_ADD_OPTION(ENTER_GAME_WAIT0);
167153

168154
PA_ADD_STATIC(m_box_timings);
169-
PA_ADD_OPTION(BOX_SCROLL_DELAY_0);
170-
PA_ADD_OPTION(BOX_CHANGE_DELAY_0);
171-
PA_ADD_OPTION(BOX_PICKUP_DROP_DELAY);
172-
PA_ADD_OPTION(MENU_TO_POKEMON_DELAY);
173-
PA_ADD_OPTION(POKEMON_TO_BOX_DELAY0);
174-
PA_ADD_OPTION(BOX_TO_POKEMON_DELAY);
175-
PA_ADD_OPTION(POKEMON_TO_MENU_DELAY);
155+
PA_ADD_OPTION(BOX_SCROLL_DELAY0);
156+
PA_ADD_OPTION(BOX_CHANGE_DELAY0);
157+
PA_ADD_OPTION(BOX_PICKUP_DROP_DELAY0);
158+
PA_ADD_OPTION(MENU_TO_POKEMON_DELAY0);
159+
PA_ADD_OPTION(POKEMON_TO_BOX_DELAY1);
160+
PA_ADD_OPTION(BOX_TO_POKEMON_DELAY0);
161+
PA_ADD_OPTION(POKEMON_TO_MENU_DELAY0);
176162

177163
PA_ADD_STATIC(m_advanced_options);
178164
PA_ADD_OPTION(SHINY_ALPHA_OVERALL_THRESHOLD);

0 commit comments

Comments
 (0)