|
18 | 18 | #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" |
19 | 19 | #include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h" |
20 | 20 | #include "PokemonLZA/Inference/PokemonLZA_MainMenuDetector.h" |
| 21 | +#include "PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" |
21 | 22 | #include "PokemonLZA_MenuNavigation.h" |
22 | 23 |
|
23 | 24 | namespace PokemonAutomation{ |
24 | 25 | namespace NintendoSwitch{ |
25 | 26 | namespace PokemonLZA{ |
26 | 27 |
|
27 | 28 | void overworld_to_main_menu(ConsoleHandle& console, ProControllerContext& context){ |
28 | | - MainMenuWatcher main_menu_watcher(COLOR_RED, &console.overlay()); |
29 | | - int ret = run_until<ProControllerContext>( |
30 | | - console, context, |
31 | | - [&](ProControllerContext& context){ |
32 | | - for(int i = 0; i < 5; i++){ |
33 | | - pbf_press_button(context, BUTTON_X, 100ms, 3s); |
| 29 | + WallClock deadline = current_time() + std::chrono::seconds(120); |
| 30 | + while (current_time() < deadline){ |
| 31 | + OverworldPartySelectionWatcher overworld(COLOR_RED, &console.overlay()); |
| 32 | + MainMenuWatcher main_menu(COLOR_GREEN, &console.overlay()); |
| 33 | + BoxWatcher box(COLOR_BLUE, &console.overlay()); |
| 34 | + context.wait_for_all_requests(); |
| 35 | + int ret = wait_until( |
| 36 | + console, context, |
| 37 | + std::chrono::seconds(30), |
| 38 | + { |
| 39 | + overworld, |
| 40 | + main_menu, |
| 41 | + box, |
34 | 42 | } |
35 | | - }, |
36 | | - {{main_menu_watcher}} |
37 | | - ); |
38 | | - |
39 | | - if (ret < 0){ |
40 | | - OperationFailedException::fire( |
41 | | - ErrorReport::SEND_ERROR_REPORT, |
42 | | - "overworld_to_main_menu(): No main menu detected after pressing \"X\" 5 times.", |
43 | | - console |
44 | 43 | ); |
| 44 | + context.wait_for(std::chrono::milliseconds(100)); |
| 45 | + switch (ret){ |
| 46 | + case 0: |
| 47 | + console.log("Detected Overworld..."); |
| 48 | + pbf_press_button(context, BUTTON_X, 160ms, 240ms); |
| 49 | + continue; |
| 50 | + case 1: |
| 51 | + console.log("Detected Main Menu..."); |
| 52 | + return; |
| 53 | + case 2: |
| 54 | + console.log("Detected Box System..."); |
| 55 | + pbf_press_button(context, BUTTON_B, 160ms, 240ms); |
| 56 | + continue; |
| 57 | + default: |
| 58 | + OperationFailedException::fire( |
| 59 | + ErrorReport::SEND_ERROR_REPORT, |
| 60 | + "overworld_to_main_menu(): No state detected after 30 seconds.", |
| 61 | + console |
| 62 | + ); |
| 63 | + } |
45 | 64 | } |
46 | | - console.log("Entered main menu."); |
| 65 | + |
| 66 | + OperationFailedException::fire( |
| 67 | + ErrorReport::SEND_ERROR_REPORT, |
| 68 | + "overworld_to_main_menu(): Failed to enter box system after 2 minutes.", |
| 69 | + console |
| 70 | + ); |
47 | 71 | } |
48 | 72 |
|
49 | 73 | void overworld_to_box_system(ConsoleHandle& console, ProControllerContext& context){ |
50 | | - overworld_to_main_menu(console, context); |
51 | | - BoxWatcher box_watcher(COLOR_RED, &console.overlay()); |
52 | | - int ret = run_until<ProControllerContext>( |
53 | | - console, context, |
54 | | - [&](ProControllerContext& context){ |
55 | | - for(int i = 0; i < 5; i++){ |
56 | | - pbf_press_button(context, BUTTON_A, 100ms, 2s); |
| 74 | + WallClock deadline = current_time() + std::chrono::seconds(120); |
| 75 | + while (current_time() < deadline){ |
| 76 | + OverworldPartySelectionWatcher overworld(COLOR_RED, &console.overlay()); |
| 77 | + MainMenuWatcher main_menu(COLOR_GREEN, &console.overlay()); |
| 78 | + BoxWatcher box(COLOR_BLUE, &console.overlay()); |
| 79 | + context.wait_for_all_requests(); |
| 80 | + int ret = wait_until( |
| 81 | + console, context, |
| 82 | + std::chrono::seconds(30), |
| 83 | + { |
| 84 | + overworld, |
| 85 | + main_menu, |
| 86 | + box, |
57 | 87 | } |
58 | | - }, |
59 | | - {{box_watcher}} |
60 | | - ); |
61 | | - |
62 | | - if (ret < 0){ |
63 | | - OperationFailedException::fire( |
64 | | - ErrorReport::SEND_ERROR_REPORT, |
65 | | - "overworld_to_box_system(): No box system view detected after pressing \"A\" 5 times from main menu.", |
66 | | - console |
67 | 88 | ); |
| 89 | + context.wait_for(std::chrono::milliseconds(100)); |
| 90 | + switch (ret){ |
| 91 | + case 0: |
| 92 | + console.log("Detected Overworld..."); |
| 93 | + pbf_press_button(context, BUTTON_X, 160ms, 240ms); |
| 94 | + continue; |
| 95 | + case 1: |
| 96 | + console.log("Detected Main Menu..."); |
| 97 | + pbf_press_button(context, BUTTON_A, 160ms, 240ms); |
| 98 | + continue; |
| 99 | + case 2: |
| 100 | + console.log("Detected Box System..."); |
| 101 | + return; |
| 102 | + default: |
| 103 | + OperationFailedException::fire( |
| 104 | + ErrorReport::SEND_ERROR_REPORT, |
| 105 | + "overworld_to_box_system(): No state detected after 30 seconds.", |
| 106 | + console |
| 107 | + ); |
| 108 | + } |
68 | 109 | } |
69 | | - console.log("Entered box system."); |
| 110 | + |
| 111 | + OperationFailedException::fire( |
| 112 | + ErrorReport::SEND_ERROR_REPORT, |
| 113 | + "overworld_to_box_system(): Failed to enter box system after 2 minutes.", |
| 114 | + console |
| 115 | + ); |
70 | 116 | } |
71 | 117 |
|
72 | 118 |
|
|
0 commit comments