Skip to content

Commit 856c72d

Browse files
committed
Refactor the Burmy and LeapGrinder notifications.
1 parent 6948524 commit 856c72d

27 files changed

+279
-139
lines changed

SerialPrograms/Source/CommonFramework/Notifications/ProgramNotifications.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void send_program_notification_with_file(
285285
filepath
286286
);
287287
}
288-
void send_program_notification(
288+
bool send_program_notification(
289289
ProgramEnvironment& env, EventNotificationOption& settings,
290290
Color color,
291291
const std::string& title,
@@ -294,7 +294,7 @@ void send_program_notification(
294294
const ImageViewRGB32& image, bool keep_file
295295
){
296296
if (!settings.ok_to_send_now(env.logger())){
297-
return;
297+
return false;
298298
}
299299
#if 1
300300
messages.emplace_back(
@@ -331,6 +331,8 @@ void send_program_notification(
331331
messages,
332332
ImageAttachment(image, settings.screenshot(), keep_file)
333333
);
334+
335+
return true;
334336
}
335337

336338

SerialPrograms/Source/CommonFramework/Notifications/ProgramNotifications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void send_program_notification_with_file(
5050
const std::string& current_stats_addendum,
5151
const std::string& filepath
5252
);
53-
void send_program_notification(
53+
bool send_program_notification(
5454
ProgramEnvironment& env, EventNotificationOption& settings,
5555
Color color,
5656
const std::string& title,

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,40 @@ struct RequestManagerConfig{
282282

283283

284284

285+
struct Command{
286+
uint64_t seqnum;
287+
uint64_t milliseconds;
288+
uint64_t buttons;
289+
uint16_t left_joystick_x;
290+
uint16_t left_joystick_y;
291+
uint16_t right_joystick_x;
292+
uint16_t right_joystick_y;
293+
294+
void write_to_hex(char str[64]) const{
295+
const char HEX_DIGITS[] = "0123456789abcdef";
296+
const char* ptr = (const char*)this;
297+
for (size_t c = 0; c < 64; c += 2){
298+
uint8_t hi = (uint8_t)ptr[0] >> 4;
299+
uint8_t lo = (uint8_t)ptr[0] & 0x0f;
300+
str[c + 0] = HEX_DIGITS[hi];
301+
str[c + 1] = HEX_DIGITS[lo];
302+
ptr++;
303+
}
304+
}
305+
void parse_from_hex(const char str[64]){
306+
char* ptr = (char*)this;
307+
for (size_t c = 0; c < 64; c += 2){
308+
char hi = str[c + 0];
309+
char lo = str[c + 1];
310+
hi = hi < 'a' ? hi - '0' : hi - 'a' + 10;
311+
lo = lo < 'a' ? lo - '0' : lo - 'a' + 10;
312+
ptr[0] = hi << 4 | lo;
313+
ptr++;
314+
}
315+
}
316+
};
317+
318+
285319

286320

287321

@@ -296,13 +330,35 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
296330

297331
using namespace std::chrono_literals;
298332

333+
Command command{
334+
123,
335+
100,
336+
512,
337+
2000, 3000,
338+
4000, 5000
339+
};
340+
341+
char str[65] = {};
342+
command.write_to_hex(str);
343+
cout << str << endl;
344+
memset(&command, 0, sizeof(Command));
345+
346+
command.parse_from_hex(str);
347+
348+
cout << command.milliseconds << endl;
349+
cout << command.buttons << endl;
350+
cout << command.left_joystick_x << endl;
351+
cout << command.left_joystick_y << endl;
352+
cout << command.right_joystick_x << endl;
353+
cout << command.right_joystick_y << endl;
299354

300355

356+
#if 0
301357
ImageRGB32 image("20250503-121259857603.png");
302358

303359
image = filter_rgb32_euclidean(image, (uint32_t)COLOR_PURPLE, 100, COLOR_RED, true);
304360
image.save("temp.png");
305-
361+
#endif
306362

307363

308364

SerialPrograms/Source/PokemonLA/Options/PokemonLA_MiscOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ResetMethodOption : public EnumDropdownOption<ResetMethod>{
2929
{ResetMethod::SoftReset, "reset", "Soft Reset"},
3030
{ResetMethod::GoBackToVillage, "return-to-village", "Go back to village"},
3131
},
32-
LockMode::LOCK_WHILE_RUNNING,
32+
LockMode::UNLOCK_WHILE_RUNNING,
3333
ResetMethod::SoftReset
3434
)
3535
{}
@@ -57,7 +57,7 @@ class StopOnOption : public EnumDropdownOption<StopOn>{
5757
{StopOn::ShinyOrAlpha, "shiny-or-alpha", "Shiny or Alpha"},
5858
{StopOn::ShinyAndAlpha, "shiny-and-alpha", "Shiny and Alpha"},
5959
},
60-
LockMode::LOCK_WHILE_RUNNING,
60+
LockMode::UNLOCK_WHILE_RUNNING,
6161
StopOn::ShinyOrAlpha
6262
)
6363
{}
@@ -79,7 +79,7 @@ class ExitBattleMethodOption : public EnumDropdownOption<ExitBattleMethod>{
7979
{ExitBattleMethod::RunAway, "run", "Run Away"},
8080
{ExitBattleMethod::MashAToKill, "mash-a-to-kill", "Mash A to Kill"},
8181
},
82-
LockMode::LOCK_WHILE_RUNNING,
82+
LockMode::UNLOCK_WHILE_RUNNING,
8383
ExitBattleMethod::RunAway
8484
)
8585
{}
@@ -98,7 +98,7 @@ class TimeOfDayOption : public EnumDropdownOption<TimeOfDay>{
9898
{TimeOfDay::EVENING, TIME_OF_DAY_NAMES[int(TimeOfDay::EVENING)], "Evening"},
9999
{TimeOfDay::MIDNIGHT, TIME_OF_DAY_NAMES[int(TimeOfDay::MIDNIGHT)], "Midnight"},
100100
},
101-
LockMode::LOCK_WHILE_RUNNING,
101+
LockMode::UNLOCK_WHILE_RUNNING,
102102
TimeOfDay::NONE
103103
)
104104
{}

SerialPrograms/Source/PokemonLA/Options/PokemonLA_ShinyDetectedAction.cpp

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,21 @@ ShinyRequiresAudioText::ShinyRequiresAudioText()
3333

3434

3535

36-
ShinyDetectedActionOption::ShinyDetectedActionOption(
36+
OverworldShinyDetectedActionOption::OverworldShinyDetectedActionOption(
3737
std::string label, std::string description,
3838
std::string default_delay,
39-
ShinyDetectedAction default_action
39+
OverworldShinyDetectedAction default_action
4040
)
41-
: ShinyDetectedActionOption(
42-
label,
43-
std::move(description),
44-
label,
45-
std::move(default_delay),
46-
std::move(default_action)
47-
)
48-
{}
49-
ShinyDetectedActionOption::ShinyDetectedActionOption(
50-
std::string label, std::string description,
51-
std::string notification_label,
52-
std::string default_delay,
53-
ShinyDetectedAction default_action
54-
)
55-
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
41+
: GroupOption(std::move(label), LockMode::UNLOCK_WHILE_RUNNING)
5642
, DESCRIPTION(std::move(description))
5743
, ACTION(
5844
"<b>Shiny Detected Action:</b>",
5945
{
60-
{ShinyDetectedAction::IGNORE, "ignore", "Ignore the shiny. Do not stop the program."},
61-
{ShinyDetectedAction::STOP_PROGRAM, "stop", "Stop program. Align camera for a screenshot. Then go Home."},
62-
{ShinyDetectedAction::TAKE_VIDEO_STOP_PROGRAM, "video+stop", "Stop program. Align camera for a screenshot + video. Then go Home."},
46+
{OverworldShinyDetectedAction::IGNORE, "ignore", "Ignore the shiny. Do not stop the program."},
47+
{OverworldShinyDetectedAction::STOP_PROGRAM, "stop", "Stop program. Align camera for a screenshot. Then go Home."},
48+
{OverworldShinyDetectedAction::TAKE_VIDEO_STOP_PROGRAM, "video+stop", "Stop program. Align camera for a screenshot + video. Then go Home."},
6349
},
64-
LockMode::LOCK_WHILE_RUNNING,
50+
LockMode::UNLOCK_WHILE_RUNNING,
6551
default_action
6652
)
6753
// , STOP_PROGRAM("<b>Stop Program:</b><br>Stop program and go Home if it hears a shiny.", true)
@@ -70,11 +56,11 @@ ShinyDetectedActionOption::ShinyDetectedActionOption(
7056
"<b>Screenshot Delay:</b><br>"
7157
"Align the camera, then wait this long before taking a screenshot + video of the shiny.<br>"
7258
"Set to zero to skip this. Don't set this too large or the shiny may run away!",
73-
LockMode::LOCK_WHILE_RUNNING,
59+
LockMode::UNLOCK_WHILE_RUNNING,
7460
std::move(default_delay)
7561
)
7662
, NOTIFICATIONS(
77-
std::move(notification_label),
63+
this->label(),
7864
true, true,
7965
ImageAttachmentMode::JPG,
8066
{"Notifs", "Showcase"}
@@ -88,8 +74,30 @@ ShinyDetectedActionOption::ShinyDetectedActionOption(
8874
// PA_ADD_OPTION(TAKE_VIDEO);
8975
PA_ADD_OPTION(SCREENSHOT_DELAY0);
9076
}
91-
bool ShinyDetectedActionOption::stop_on_shiny() const{
92-
return ACTION != ShinyDetectedAction::IGNORE;
77+
bool OverworldShinyDetectedActionOption::stop_on_shiny() const{
78+
return ACTION != OverworldShinyDetectedAction::IGNORE;
79+
}
80+
81+
82+
83+
BattleMatchActionOption::BattleMatchActionOption(
84+
std::string label, std::string description,
85+
std::string default_delay
86+
)
87+
: GroupOption(std::move(label), LockMode::UNLOCK_WHILE_RUNNING)
88+
, DESCRIPTION(std::move(description))
89+
, TAKE_VIDEO("<b>Take Video:</b>", LockMode::UNLOCK_WHILE_RUNNING, true)
90+
, NOTIFICATIONS(
91+
this->label(),
92+
true, true,
93+
ImageAttachmentMode::JPG,
94+
{"Notifs", "Showcase"}
95+
)
96+
{
97+
if (!DESCRIPTION.text().empty()){
98+
PA_ADD_OPTION(DESCRIPTION);
99+
}
100+
PA_ADD_OPTION(TAKE_VIDEO);
93101
}
94102

95103

@@ -99,7 +107,7 @@ bool ShinyDetectedActionOption::stop_on_shiny() const{
99107

100108
bool on_shiny_callback(
101109
ProgramEnvironment& env, VideoStream& stream,
102-
ShinyDetectedActionOption& options,
110+
OverworldShinyDetectedActionOption& options,
103111
float error_coefficient
104112
){
105113
{
@@ -109,8 +117,8 @@ bool on_shiny_callback(
109117

110118
// If we're not ignoring the shiny, return now. Actions will be deferred
111119
// until after the session ends.
112-
ShinyDetectedAction action = options.ACTION;
113-
if (action != ShinyDetectedAction::IGNORE){
120+
OverworldShinyDetectedAction action = options.ACTION;
121+
if (action != OverworldShinyDetectedAction::IGNORE){
114122
return true;
115123
}
116124
}
@@ -134,7 +142,7 @@ bool on_shiny_callback(
134142
}
135143
void on_shiny_sound(
136144
ProgramEnvironment& env, VideoStream& stream, ProControllerContext& context,
137-
ShinyDetectedActionOption& options,
145+
OverworldShinyDetectedActionOption& options,
138146
float error_coefficient
139147
){
140148
std::vector<std::pair<std::string, std::string>> embeds;
@@ -157,46 +165,45 @@ void on_shiny_sound(
157165
stream.video().snapshot(), true
158166
);
159167

160-
ShinyDetectedAction action = options.ACTION;
161-
if (action == ShinyDetectedAction::TAKE_VIDEO_STOP_PROGRAM){
168+
switch (options.ACTION){
169+
case OverworldShinyDetectedAction::IGNORE:
170+
break;
171+
case OverworldShinyDetectedAction::STOP_PROGRAM:
172+
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
173+
context.wait_for_all_requests();
174+
throw ProgramFinishedException();
175+
case OverworldShinyDetectedAction::TAKE_VIDEO_STOP_PROGRAM:
162176
pbf_press_button(context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0);
177+
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
178+
context.wait_for_all_requests();
179+
throw ProgramFinishedException();
163180
}
164-
165-
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
166-
context.wait_for_all_requests();
167-
throw ProgramFinishedException();
168181
}
169182

170-
void on_match_found(
183+
void on_battle_match_found(
171184
ProgramEnvironment& env, VideoStream& stream, ProControllerContext& context,
172-
ShinyDetectedActionOption& options, bool stop_program
185+
BattleMatchActionOption& options,
186+
bool allow_notification
173187
){
174-
std::vector<std::pair<std::string, std::string>> embeds;
175-
176-
pbf_mash_button(context, BUTTON_ZL, options.SCREENSHOT_DELAY0);
177188
context.wait_for_all_requests();
178189

179-
send_program_notification(
180-
env, options.NOTIFICATIONS,
181-
Pokemon::COLOR_STAR_SHINY,
182-
"Match Found",
183-
embeds, "",
184-
stream.video().snapshot(), true
185-
);
186-
187-
ShinyDetectedAction action = options.ACTION;
188-
if (action == ShinyDetectedAction::TAKE_VIDEO_STOP_PROGRAM){
189-
pbf_press_button(context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0);
190+
if (allow_notification){
191+
send_program_notification(
192+
env, options.NOTIFICATIONS,
193+
Pokemon::COLOR_STAR_SHINY,
194+
"Match Found",
195+
{}, "",
196+
stream.video().snapshot(), true
197+
);
190198
}
191199

192-
if (stop_program){
193-
stream.log("Stopping...");
194-
// pbf_press_button(context, BUTTON_HOME, 20, GameSettings::instance().GAME_TO_HOME_DELAY);
195-
context.wait_for_all_requests();
196-
throw ProgramFinishedException();
200+
if (options.TAKE_VIDEO){
201+
pbf_press_button(context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0);
197202
}
198203

199-
stream.log("Continuing...");
204+
stream.log("Stopping...");
205+
context.wait_for_all_requests();
206+
throw ProgramFinishedException();
200207
}
201208

202209

0 commit comments

Comments
 (0)