Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include "CommonFramework/Tools/ErrorDumper.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Resources/Pokemon_PokemonSlugs.h"
#include "Pokemon/Inference/Pokemon_TypeReader.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_BallReader.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_AlphaDetector.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_BallReader.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_BoxGenderDetector.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_BoxViewDetector.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_GigantamaxDetector.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_OriginMarkReader.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_ShinyDetector.h"
Expand Down Expand Up @@ -322,46 +324,59 @@ void print_boxes_data(const std::vector<std::optional<CollectedPokemonInfo>>& bo
env.console.log(ss.str());
}

void exit_menus(SingleSwitchProgramEnvironment& env, ProControllerContext& context, std::chrono::milliseconds video_delay){
VideoSnapshot screen = env.console.video().snapshot();
VideoOverlaySet video_overlay_set(env.console);
void exit_menus(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
BoxViewWatcher box_watcher(&env.console.overlay());
int ret = run_until<ProControllerContext>(
env.console, context,
[](ProControllerContext& context){
for (size_t i = 0; i < 20; i++){
pbf_press_button(context, BUTTON_B, 80ms, 250ms);
Comment thread
Dalton-V marked this conversation as resolved.
Resolved
context.wait_for_all_requests();
}
},
{ box_watcher }
);

ImageFloatBox select_check(0.495, 0.0045, 0.01, 0.005); // square color to check which mode is active
FloatPixel image_value = image_stats(extract_box_reference(screen, select_check)).average;
if (ret != 0){
dump_image(env.console, ProgramInfo(), "SelectSquare", env.console.video().snapshot());
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT, "HomeBoxNavigation_ExitMenus(): could not find box view after 20 attempts", env.console
);
}

env.console.log("Color detected from the select square: " + image_value.to_string());
// Page view can be detected as Box view. Extra B to ensure we are in box view and not page view.
pbf_press_button(context, BUTTON_B, 80ms, 250ms);
context.wait_for(250ms);
context.wait_for_all_requests();
}

//if the correct color is not detected, getting out of every possible menu to make sure the program work no matter where you start it in your pokemon home
video_overlay_set.add(COLOR_BLUE, select_check);
if (image_value.r <= image_value.g + image_value.b){
for (int var = 0; var < 5; ++var){
pbf_press_button(context, BUTTON_B, 80ms, video_delay + 80ms);
}
context.wait_for_all_requests();
context.wait_for(std::chrono::milliseconds(video_delay));
screen = env.console.video().snapshot();
image_value = image_stats(extract_box_reference(screen, select_check)).average;
env.console.log("Color detected from the select square: " + image_value.to_string());
if (image_value.r <= image_value.g + image_value.b){
for (int i = 0; i < 2; ++i){
pbf_press_button(context, BUTTON_ZR, 80ms, video_delay + 240ms); //additional delay because this animation is slower than the rest
context.wait_for_all_requests();
screen = env.console.video().snapshot();
image_value = image_stats(extract_box_reference(screen, select_check)).average;
env.console.log("Color detected from the select square: " + image_value.to_string());
if (image_value.r > image_value.g + image_value.b){
break;
}
else if (i == 1){
dump_image(env.console, ProgramInfo(), "SelectSquare", screen);
env.console.log("ERROR: Could not find correct color mode please check color logs and timings\n", COLOR_RED);
return;
}
}
void switch_selection_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, BoxSelectionMode desired_mode){
context.wait_for_all_requests();
const SelectionArrowDetector detector;
auto selection = detector.detect(env.console.video().snapshot());
if (!selection){
exit_menus(env, context);
selection = detector.detect(env.console.video().snapshot());
if (!selection){
dump_image(env.console, ProgramInfo(), "SelectionArrow", env.console.video().snapshot());
OperationFailedExceptionWithScreenshot::fire(
ErrorReportMode::SEND_ERROR_REPORT,
"HomeBoxNavigation_SwitchSelectionMode(): could not find selection arrow after exiting menus",
env.console
);
}
}
if (selection->mode == desired_mode){
return;
}

video_overlay_set.clear();
// ZL cycles Normal -> Relocate -> Multi -> Normal; ZR goes in reverse.
const bool select_left =
(selection->mode == BoxSelectionMode::Normal && desired_mode == BoxSelectionMode::Relocate)
|| (selection->mode == BoxSelectionMode::Relocate && desired_mode == BoxSelectionMode::Multi)
|| (selection->mode == BoxSelectionMode::Multi && desired_mode == BoxSelectionMode::Normal);
pbf_press_button(context, select_left ? BUTTON_ZL : BUTTON_ZR, 80ms, 300ms);
context.wait_for_all_requests();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#define PokemonAutomation_PokemonHome_BoxNavigation_H

#include <array>
#include <cstddef>
#include <optional>
#include <vector>
#include "Common/Cpp/Time.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "Pokemon/Pokemon_BoxCursor.h"
#include "Pokemon/Pokemon_CollectedPokemonInfo.h"
#include "Pokemon/Options/Pokemon_BoxSortingTable.h"
#include "VideoGames/PokemonHome/Inference/PokemonHome_SelectionArrowDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -61,7 +61,10 @@ void print_boxes_data(
SingleSwitchProgramEnvironment& env
);

void exit_menus(SingleSwitchProgramEnvironment& env, ProControllerContext& context, std::chrono::milliseconds video_delay);
// Backout of any menus to the box view.
void exit_menus(SingleSwitchProgramEnvironment& env, ProControllerContext& context);

void switch_selection_mode(SingleSwitchProgramEnvironment& env, ProControllerContext& context, BoxSelectionMode desired_mode);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ void BoxSorter::program(SingleSwitchProgramEnvironment& env, ProControllerContex
BoxCursor dest_cursor;
BoxCursor nav_cursor = {0, 0, 0};

exit_menus(env, context, VIDEO_DELAY.get());

exit_menus(env, context);
switch_selection_mode(env, context, BoxSelectionMode::Normal);

BoxViewWatcher box_view_watcher(&env.console.overlay());
SummaryScreenWatcher summary_screen_watcher(&env.console.overlay());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ void BoxSorterLivingDex::program(SingleSwitchProgramEnvironment& env, ProControl
);
}

exit_menus(env, context, VIDEO_DELAY.get());
exit_menus(env, context);
switch_selection_mode(env, context, BoxSelectionMode::Normal);

nav_cursor = populate_box_data(env, context, sort_preferences, living_dex_boxes_data, living_dex_box_count, nav_cursor, OT_NAME_LANGUAGE);

Expand Down
Loading