@@ -21,58 +21,6 @@ namespace PokemonAutomation{
2121namespace NintendoSwitch {
2222
2323
24- bool is_white_theme (VideoStream& stream, ProControllerContext& context){
25- context.wait_for_all_requests ();
26- VideoSnapshot snapshot = stream.video ().snapshot ();
27- ImageFloatBox window_top (0.60 , 0.02 , 0.35 , 0.05 );
28- ImageStats stats_window_top = image_stats (extract_box_reference (snapshot, window_top));
29- bool white_theme = stats_window_top.average .sum () > 600 ;
30- return white_theme;
31- }
32-
33- bool is_setting_selected (VideoStream& stream, ProControllerContext& context, ImageFloatBox selected_box, ImageFloatBox unselected_box1, ImageFloatBox unselected_box2){
34- VideoOverlaySet overlays (stream.overlay ());
35- overlays.add (COLOR_RED, selected_box);
36- overlays.add (COLOR_BLUE, unselected_box1);
37- overlays.add (COLOR_BLUE, unselected_box2);
38- context.wait_for_all_requests ();
39- context.wait_for (Milliseconds (250 ));
40- size_t max_attempts = 10 ; // multiple attempts because the highlighted icon/setting pulses. and sometimes there isn't enough contrast at the exact moment you take the snapshot.
41- bool is_selected = false ;
42- for (size_t i = 0 ; i < max_attempts; i++){
43- VideoSnapshot snapshot = stream.video ().snapshot ();
44-
45- ImageStats stats_unselected_box1 = image_stats (extract_box_reference (snapshot, unselected_box1));
46- double unselected1_average_sum = stats_unselected_box1.average .sum ();
47- stream.log (" unselected_average_sum1: " + std::to_string (unselected1_average_sum));
48-
49- ImageStats stats_unselected_box2 = image_stats (extract_box_reference (snapshot, unselected_box2));
50- double unselected2_average_sum = stats_unselected_box2.average .sum ();
51- stream.log (" unselected_average_sum2: " + std::to_string (unselected2_average_sum));
52-
53- double average_sum_unselected_diff = std::abs (unselected1_average_sum - unselected2_average_sum);
54-
55- ImageStats stats_selected_box = image_stats (extract_box_reference (snapshot, selected_box));
56- double selected_average_sum = stats_selected_box.average .sum ();
57- stream.log (" selected_average_sum: " + std::to_string (selected_average_sum));
58-
59- if (is_white_theme (stream, context)){ // light mode
60- // unselected should be brighter than selected
61- is_selected = selected_average_sum < std::min (unselected1_average_sum, unselected2_average_sum) - average_sum_unselected_diff - 20 ;
62- }else { // dark mode
63- // selected should be brighter than unselected
64- is_selected = selected_average_sum > std::max (unselected1_average_sum, unselected2_average_sum) + average_sum_unselected_diff + 20 ;
65- }
66-
67- if (is_selected){
68- return true ;
69- }
70- context.wait_for (Milliseconds (100 ));
71- }
72-
73- return false ;
74- }
75-
7624void home_to_date_time (VideoStream& stream, ProControllerContext& context, bool to_date_change, bool fast){
7725 size_t max_attempts = 5 ;
7826 for (size_t i = 0 ; i < max_attempts; i++){
@@ -104,19 +52,20 @@ void home_to_date_time(VideoStream& stream, ProControllerContext& context, bool
10452 }while (--iterations);
10553 }
10654
55+ context.wait_for_all_requests ();
10756 // Should now be in System Settings, with System highlighted
10857 ImageFloatBox system_setting_box (0.056 , 0.74 , 0.01 , 0.1 );
10958 ImageFloatBox other_setting1 (0.04 , 0.74 , 0.01 , 0.1 );
11059 ImageFloatBox other_setting2 (0.02 , 0.74 , 0.01 , 0.1 );
111- SelectedSettingWatcher system_setting (system_setting_box, other_setting1, other_setting2);
60+ SelectedSettingWatcher system_setting_selected (system_setting_box, other_setting1, other_setting2);
11261 int ret = run_until<ProControllerContext>(
11362 stream, context,
11463 [](ProControllerContext& context){
11564 for (int i = 0 ; i < 10 ; i++){
11665 ssf_issue_scroll (context, SSF_SCROLL_DOWN, 24ms);
11766 }
11867 },
119- {system_setting }
68+ {system_setting_selected }
12069 );
12170 if (ret < 0 ){ // failed to detect System highlighted. press home and re-try
12271 pbf_press_button (context, BUTTON_HOME, 100ms, 100ms);
@@ -148,15 +97,16 @@ void home_to_date_time(VideoStream& stream, ProControllerContext& context, bool
14897 ssf_press_button (context, BUTTON_A, 3 );
14998
15099 context.wait_for_all_requests ();
100+ context.wait_for (Milliseconds (250 ));
151101 // we expect to be within "Date and Time", with "Synchronize Clock via Internet" being highlighted
152102 ImageFloatBox sync_clock_box (0.168 , 0.185 , 0.01 , 0.1 );
153103 ImageFloatBox other_setting3 (0.1 , 0.185 , 0.01 , 0.1 );
154104 ImageFloatBox other_setting4 (0.05 , 0.185 , 0.01 , 0.1 );
155- SelectedSettingWatcher sync_clock (sync_clock_box, other_setting3, other_setting4);
105+ SelectedSettingWatcher sync_clock_selected (sync_clock_box, other_setting3, other_setting4);
156106 ret = wait_until (
157107 stream, context,
158108 Milliseconds (2000 ),
159- {sync_clock }
109+ {sync_clock_selected }
160110 );
161111 if (ret < 0 ){ // failed to detect System highlighted. press home and re-try
162112 pbf_press_button (context, BUTTON_HOME, 100ms, 100ms);
0 commit comments