diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.cpp new file mode 100644 index 0000000000..d90e5fc5d1 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.cpp @@ -0,0 +1,63 @@ +/* Menu Cursor + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch_MenuCursor.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + +using namespace std::chrono_literals; + + +namespace{ + +void add_presses(std::vector& moves, DpadPosition direction, size_t count){ + moves.insert(moves.end(), count, direction); +} +void add_sideways(std::vector& moves, size_t from_column, size_t to_column){ + if (to_column > from_column){ + add_presses(moves, DPAD_RIGHT, to_column - from_column); + }else{ + add_presses(moves, DPAD_LEFT, from_column - to_column); + } +} + +} // namespace + + +std::optional> menu_cursor_moves(const MenuGrid& grid, size_t from, size_t to){ + if (grid.columns == 0 || from >= grid.count || to >= grid.count){ + return std::nullopt; + } + const size_t from_row = from / grid.columns; + const size_t from_column = from % grid.columns; + const size_t to_row = to / grid.columns; + const size_t to_column = to % grid.columns; + std::vector moves; + if (to_row > from_row){ + // The start's row is above the target's, so it is full: sideways first. + add_sideways(moves, from_column, to_column); + add_presses(moves, DPAD_DOWN, to_row - from_row); + }else{ + // Up to the target's row first, which is full unless it is the start's. + add_presses(moves, DPAD_UP, from_row - to_row); + add_sideways(moves, from_column, to_column); + } + return moves; +} + + +void press_cursor_moves(ProControllerContext& context, const std::vector& moves){ + for (DpadPosition move : moves){ + pbf_press_dpad(context, move, 80ms, 320ms); + } +} + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.h b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.h new file mode 100644 index 0000000000..077dfd0175 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.h @@ -0,0 +1,44 @@ +/* Menu Cursor + * + * From: https://github.com/PokemonAutomation/ + * + * Moves the cursor of a fixed list or grid (a game's language select, the + * player's look) to an item by its index. The menu's shape is data; the + * presses follow from it; a detector for the menu reads where the cursor is. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_MenuCursor_H +#define PokemonAutomation_NintendoSwitch_MenuCursor_H + +#include +#include +#include +#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +// A menu of `count` items in rows of `columns`, numbered left to right, then +// top to bottom; a list has one column. Only the last row may be short. +struct MenuGrid{ + size_t columns = 1; + size_t count = 0; +}; + +// The D-pad presses that take the cursor from item `from` to item `to`. +// None crosses an edge, so they hold whether or not the menu wraps, and +// sideways presses happen on a full row. nullopt when either item is outside +// the grid. +std::optional> menu_cursor_moves(const MenuGrid& grid, size_t from, size_t to); + +// Presses `moves` in order, one D-pad tap each. +void press_cursor_moves(ProControllerContext& context, const std::vector& moves); + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.cpp new file mode 100644 index 0000000000..3f41a2cee2 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.cpp @@ -0,0 +1,160 @@ +/* Menu Cursor - Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "NintendoSwitch_MenuCursor.h" +#include "NintendoSwitch_MenuCursor_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + +namespace{ + + +std::string describe(const std::vector& moves){ + std::string out; + for (DpadPosition move : moves){ + out += (out.empty() ? "" : " ") + dpad_to_string(move); + } + return out.empty() ? "(none)" : out; +} + +struct MovesCase{ + std::string_view what; + MenuGrid grid; + size_t from; + size_t to; + std::vector expected; +}; + +UnitTestResult test_cursor_moves(){ + const MenuGrid list{1, 9}; + const MenuGrid looks{4, 8}; + // Seven items in rows of three: the last row holds one. + const MenuGrid ragged{3, 7}; + const MovesCase cases[] = { + {"list: stay", list, 1, 1, {}}, + {"list: down", list, 1, 2, {DPAD_DOWN}}, + {"list: up to the top", list, 1, 0, {DPAD_UP}}, + {"list: top to bottom, no wrap", list, 0, 8, std::vector(8, DPAD_DOWN)}, + {"grid: right on the top row", looks, 0, 2, {DPAD_RIGHT, DPAD_RIGHT}}, + {"grid: down a row", looks, 0, 4, {DPAD_DOWN}}, + {"grid: sideways, then down", looks, 1, 7, {DPAD_RIGHT, DPAD_RIGHT, DPAD_DOWN}}, + {"grid: up, then sideways", looks, 7, 0, {DPAD_UP, DPAD_LEFT, DPAD_LEFT, DPAD_LEFT}}, + // The short row has only column 0: sideways happens on the full row above. + {"ragged: into the short row", ragged, 2, 6, {DPAD_LEFT, DPAD_LEFT, DPAD_DOWN, DPAD_DOWN}}, + {"ragged: out of the short row", ragged, 6, 5, {DPAD_UP, DPAD_RIGHT, DPAD_RIGHT}}, + }; + for (const MovesCase& c : cases){ + const std::optional> moves = menu_cursor_moves(c.grid, c.from, c.to); + if (!moves){ + return std::string(c.what) + ": no moves."; + } + if (*moves != c.expected){ + return std::string(c.what) + ": " + describe(*moves) + ", expected " + describe(c.expected) + "."; + } + } + if (menu_cursor_moves(looks, 0, 8) || menu_cursor_moves(looks, 8, 0) || menu_cursor_moves(MenuGrid{0, 4}, 0, 1)){ + return "An item outside the grid, or a grid with no columns, must give no moves."; + } + return true; +} + +// Walks the moves from `from` to `to` on `grid`; what went wrong, or "". +std::string check_walk(const MenuGrid& grid, size_t from, size_t to){ + const std::string pair = std::to_string(grid.columns) + "x" + std::to_string(grid.count) + + " from " + std::to_string(from) + " to " + std::to_string(to); + const std::optional> moves = menu_cursor_moves(grid, from, to); + if (!moves){ + return pair + ": no moves."; + } + long row = (long)(from / grid.columns); + long column = (long)(from % grid.columns); + for (DpadPosition move : *moves){ + row += move == DPAD_DOWN ? 1 : move == DPAD_UP ? -1 : 0; + column += move == DPAD_RIGHT ? 1 : move == DPAD_LEFT ? -1 : 0; + const long index = row * (long)grid.columns + column; + if (row < 0 || column < 0 || column >= (long)grid.columns || index >= (long)grid.count){ + return pair + ": " + describe(*moves) + " leaves the grid."; + } + } + if (row * (long)grid.columns + column != (long)to){ + return pair + ": " + describe(*moves) + " ends elsewhere."; + } + return ""; +} + +// Every pair of items in a few shapes: the moves land on the target and never +// leave the grid or step on a missing item. +UnitTestResult test_cursor_moves_stay_inside(){ + for (const MenuGrid& grid : {MenuGrid{1, 9}, MenuGrid{4, 8}, MenuGrid{3, 7}, MenuGrid{5, 1}}){ + for (size_t from = 0; from < grid.count; from++){ + for (size_t to = 0; to < grid.count; to++){ + const std::string error = check_walk(grid, from, to); + if (!error.empty()){ + return error; + } + } + } + } + return true; +} + +struct MenuCursorInput{ + std::string name; + UnitTestResult (*body)(); +}; + +struct MenuCursorExpectation{ +}; + +struct MenuCursorCase{ + MenuCursorInput input; + MenuCursorExpectation expectation; +}; + +class Test_MenuCursor : public UnitTest{ +public: + explicit Test_MenuCursor(MenuCursorCase test_case) + : UnitTest("NintendoSwitch::MenuCursor - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_case.input.body(); + } + +private: + MenuCursorCase m_case; +}; + +const MenuCursorCase MENU_CURSOR_CASES[] = { + { + .input = {"presses from item to item", test_cursor_moves}, + .expectation = {}, + }, + { + .input = {"presses stay inside the grid", test_cursor_moves_stay_inside}, + .expectation = {}, + }, +}; + + +} // namespace + + +void add_tests_MenuCursor(UnitTestDatabase& database){ + for (const MenuCursorCase& item : MENU_CURSOR_CASES){ + database.add(item); + } +} + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.h b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.h new file mode 100644 index 0000000000..10b6131cb3 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.h @@ -0,0 +1,23 @@ +/* Menu Cursor - Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_MenuCursor_Tests_H +#define PokemonAutomation_NintendoSwitch_MenuCursor_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +// The cursor presses for list and grid items. No console. +void add_tests_MenuCursor(UnitTestDatabase& database); + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp b/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp index 4b81977e67..6d4490bdac 100644 --- a/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" @@ -42,9 +43,14 @@ const PlayerModelIcons& PLAYER_MODEL_ICONS(){ PlayerModelOption::PlayerModelOption() - : StringSelectOption( + : PlayerModelOption( "Character model:
The appearance chosen for the player character. " - "Each one is watched through a different eye template.", + "Each one is watched through a different eye template." + ) +{} +PlayerModelOption::PlayerModelOption(std::string label) + : StringSelectOption( + std::move(label), PLAYER_MODEL_ICONS().database, LockMode::LOCK_WHILE_RUNNING, "model-1" diff --git a/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h b/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h index e54cd04850..9f3f358206 100644 --- a/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h +++ b/SerialPrograms/Source/PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h @@ -8,6 +8,7 @@ #define PokemonAutomation_PokemonBDSP_PlayerModelOption_H #include +#include #include "CommonTools/Options/StringSelectOption.h" namespace PokemonAutomation{ @@ -22,6 +23,8 @@ const uint8_t BDSP_PLAYER_MODEL_COUNT = 8; class PlayerModelOption : public StringSelectOption{ public: PlayerModelOption(); + // The same choices, under another label. + explicit PlayerModelOption(std::string label); uint8_t model_number() const{ return (uint8_t)(index() + 1); } }; diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index efb7aaaf5e..33b8447c4f 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -8,6 +8,7 @@ #include "Inference/PokemonBDSP_DialogDetector.h" #include "Inference/PokemonBDSP_MenuDetector.h" #include "Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.h" +#include "Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.h" @@ -42,6 +43,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_DialogDetector(database); add_tests_MenuDetector(database); add_tests_AutoStory_Actions(database); + add_tests_AutoStory_Settings(database); add_tests_AutoStory_Launch(database); add_tests_AutoStory_Maps(database); add_tests_AutoStory_StoryWorld(database); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index 446a771ed8..eb7cd1864d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -10,9 +10,11 @@ */ #include +#include #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" @@ -20,9 +22,13 @@ #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Logging/Logger.h" +#include "NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor_Tests.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" +#include "PokemonBDSP/Options/PokemonBDSP_PlayerModelOption.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_IntroMenuDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_NameLimitReader.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_BattleMoves.h" #include "PokemonBDSP_AutoStory_Center.h" @@ -36,6 +42,7 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonBDSP{ +using namespace detail; namespace{ @@ -208,7 +215,7 @@ std::string check_boot(IntroProgress& progress){ } UnitTestResult check_confirming_screens(){ - for (const std::string screen : {"dialog", "rival-list-tell", "rival-list-preset", "menu"}){ + for (const std::string screen : {"dialog", "language-select", "rival-list-tell", "rival-list-preset", "menu"}){ if (!intro_screen_confirms_bdsp(screen)){ return std::string("Expected \"") + screen + "\" to confirm BDSP."; } @@ -252,10 +259,339 @@ UnitTestResult test_intro_gate(Logger&){ if (decide_intro_step("other", progress) != IntroStep::ADVANCE){ return "Once BDSP's dialogue has shown, the clock stops."; } + IntroProgress before_look = progress; + before_look.look_pending = true; + if (decide_intro_step("other", before_look) != IntroStep::WAIT){ + return "Between the language pick and the look pick, an unknown screen waits: A there can take the default look."; + } return check_confirming_screens(); } +// The menus' data, grids, detectors and the look option agree on their sizes. +UnitTestResult check_intro_menu_sizes(){ + if (bdsp_language_menu().size() != BDSP_LANGUAGE_GRID.count || BDSP_LANGUAGE_GRID.count != LANGUAGE_SELECT_BUTTONS){ + return "The language select's data, grid and detector must agree on ten buttons."; + } + if (BDSP_LOOK_GRID.count != LOOK_SELECT_PORTRAITS || BDSP_LOOK_GRID.count != BDSP_PLAYER_MODEL_COUNT){ + return "The look grid, its detector and PlayerModelOption must agree on eight looks."; + } + return true; +} + +// The presses for the language select (two columns of five, read row by +// row, from wherever its cursor is) and the appearance grid (two rows of +// four, from the first look). +UnitTestResult test_intro_pick_moves(Logger&){ + using Moves = std::optional>; + const IntroPicks french{Language::French, 2}; + struct Case{ + std::string_view what; + Moves actual; + Moves expected; + }; + const Case cases[] = { + {"French from English, where the cursor starts (lab run 3)", + language_pick_moves(0, french), Moves(std::vector{DPAD_DOWN, DPAD_DOWN})}, + {"English from English", + language_pick_moves(0, IntroPicks{Language::English, 0}), Moves(std::vector{})}, + {"French from Traditional Chinese, bottom right", + language_pick_moves(9, french), Moves(std::vector{DPAD_UP, DPAD_UP, DPAD_LEFT})}, + {"Japanese: its kana button, right of English", + language_pick_moves(0, IntroPicks{Language::Japanese, 0}), Moves(std::vector{DPAD_RIGHT})}, + {"Traditional Chinese from English", + language_pick_moves(0, IntroPicks{Language::ChineseTraditional, 0}), + Moves(std::vector{DPAD_RIGHT, DPAD_DOWN, DPAD_DOWN, DPAD_DOWN, DPAD_DOWN})}, + {"Italian, bottom left", + language_pick_moves(0, IntroPicks{Language::Italian, 0}), Moves(std::vector(4, DPAD_DOWN))}, + {"a language the menu lacks", + language_pick_moves(0, IntroPicks{Language::None, 0}), std::nullopt}, + {"a cursor outside the menu", + language_pick_moves(LANGUAGE_SELECT_BUTTONS, french), std::nullopt}, + {"Model 1, where the cursor starts", + look_pick_moves(0, IntroPicks{Language::English, 0}), Moves(std::vector{})}, + {"Model 3, Dawn's first look (lab run 3)", + look_pick_moves(0, french), Moves(std::vector{DPAD_RIGHT, DPAD_RIGHT})}, + {"Model 3 from Model 8", + look_pick_moves(7, french), Moves(std::vector{DPAD_UP, DPAD_LEFT})}, + {"Model 8, the last", + look_pick_moves(0, IntroPicks{Language::English, 7}), Moves(std::vector{DPAD_RIGHT, DPAD_RIGHT, DPAD_RIGHT, DPAD_DOWN})}, + {"no Model 9", + look_pick_moves(0, IntroPicks{Language::English, 8}), std::nullopt}, + {"a cursor outside the look grid", + look_pick_moves(LOOK_SELECT_PORTRAITS, french), std::nullopt}, + }; + for (const Case& c : cases){ + if (c.actual != c.expected){ + return std::string("Wrong presses for ") + std::string(c.what) + "."; + } + } + return check_intro_menu_sizes(); +} + +// Each select takes its pick, then A if it still shows. Other screens take +// A. The player's keyboard with a pick still to make fails. +UnitTestResult test_intro_pick_steps(Logger&){ + struct Case{ + std::string_view what; + std::string_view screen; + bool language_pending; + bool look_pending; + IntroStep expected; + }; + const Case cases[] = { + {"the language select", "language-select", true, true, IntroStep::PICK_LANGUAGE}, + {"the language select, picked", "language-select", false, true, IntroStep::ADVANCE}, + {"a logo before the language", "other", true, true, IntroStep::ADVANCE}, + {"a dialogue before the language", "dialog", true, true, IntroStep::ADVANCE}, + {"the look select", "look-select", false, true, IntroStep::PICK_LOOK}, + {"the look select, picked", "look-select", false, false, IntroStep::ADVANCE}, + {"Rowan, look to pick", "dialog", false, true, IntroStep::ADVANCE}, + {"a cutscene, look to pick", "other", false, true, IntroStep::WAIT}, + {"both picked", "dialog", false, false, IntroStep::ADVANCE}, + {"black, look to pick", "black", false, true, IntroStep::WAIT}, + {"the user select", "user-select", true, true, IntroStep::SELECT_USER}, + {"the keyboard, language missed", "keyboard", true, false, IntroStep::FAIL_PICK_MISSED}, + {"the keyboard, look missed", "keyboard", false, true, IntroStep::FAIL_PICK_MISSED}, + {"the keyboard, both picked", "keyboard", false, false, IntroStep::ENTER_PLAYER_NAME}, + }; + for (const Case& c : cases){ + IntroProgress progress = intro_progress(0); + progress.language_pending = c.language_pending; + progress.look_pending = c.look_pending; + if (decide_intro_step(c.screen, progress) != c.expected){ + return std::string("Wrong step for ") + std::string(c.what) + "."; + } + } + const IntroProgress first_look = intro_start(IntroPicks{Language::English, 0}); + if (!first_look.language_pending || first_look.look_pending){ + return "The language is always picked on its select; the first look needs no grid."; + } + const IntroProgress run3 = intro_start(IntroPicks{Language::French, 2}); + if (!run3.language_pending || !run3.look_pending){ + return "French and Model 3 need both menus."; + } + return true; +} + +// The intro is taken up, without a restart, only before the language is +// picked: past it the game's language may not be the one asked for (jp1, +// lab-B 2026-11-15: taken up on the look select of a Traditional Chinese +// game while Japanese was asked for, it typed the name on a CJK keyboard). +UnitTestResult test_intro_restart(Logger&){ + struct Input{ + std::string_view screen; + }; + struct Expectation{ + bool restart; + }; + struct Case{ + std::string_view name; + Input input; + Expectation expectation; + }; + const Case cases[] = { + {"the title or a logo", {"other"}, {true}}, + {"black", {"black"}, {true}}, + {"the bedroom's menu", {"menu"}, {true}}, + {"the user select", {"user-select"}, {false}}, + {"the language select", {"language-select"}, {false}}, + {"the look select", {"look-select"}, {true}}, + {"a dialogue", {"dialog"}, {true}}, + {"the player's keyboard", {"keyboard"}, {true}}, + {"the rival's name list", {"rival-list-tell"}, {true}}, + {"a preset rival name", {"rival-list-preset"}, {true}}, + }; + for (const Case& c : cases){ + if (intro_restart_needed(c.input.screen) != c.expectation.restart){ + return std::string("Wrong restart for ") + std::string(c.name) + "."; + } + } + return true; +} + +// After the pick, Japanese's language select stays up while the game loads +// the language: the pick and 9 A presses in the capture run, 10 in jp2 +// (lab-B 2026-11-15), where the cap of 10 failed the intro. The cap allows +// twice that. +UnitTestResult test_language_select_visits(Logger&){ + const size_t japanese_load_visits = 1 + 10; + if (INTRO_LANGUAGE_SELECT_VISITS < 2 * japanese_load_visits){ + return std::format("The language select may come up {} times; Japanese's load alone took {}.", + INTRO_LANGUAGE_SELECT_VISITS, japanese_load_visits); + } + return true; +} + +// The keyboard's counter gives the name's limit; a longer name stops the +// intro, an unread limit does not. +UnitTestResult test_name_limit(Logger&){ + struct ParseCase{ + std::string_view name; + std::string_view input; + std::optional expectation; + }; + const ParseCase parse_cases[] = { + {"an empty field", "0/6", 6}, + {"OCR's newline", "0/5\n", 5}, + {"spaces", " 0 / 12 ", 12}, + {"a typed name", "6/12", 12}, + {"nothing", "", std::nullopt}, + {"no limit", "0/", std::nullopt}, + {"a zero limit", "0/0", std::nullopt}, + {"text", "Name", std::nullopt}, + {"text after it", "0/6 x", std::nullopt}, + }; + for (const ParseCase& c : parse_cases){ + if (parse_keyboard_counter(c.input) != c.expectation){ + return std::string("Wrong limit for ") + std::string(c.name) + "."; + } + } + struct FitCase{ + std::string_view name; + std::string_view input_name; + std::optional input_limit; + bool expectation_fails; + }; + const FitCase fit_cases[] = { + {"Kosmos in 12", "Kosmos", 12, false}, + {"Kosmos in 6", "Kosmos", 6, false}, + {"Kosmos in 5", "Kosmos", 5, true}, + {"limit not read", "Kosmos", std::nullopt, false}, + {"two-byte letters in 5", "\xc3\xa9\xc3\xa9\xc3\xa9", 5, false}, + }; + for (const FitCase& c : fit_cases){ + if (name_limit_problem(c.input_name, c.input_limit).has_value() != c.expectation_fails){ + return std::string("Wrong fit for ") + std::string(c.name) + "."; + } + } + return true; +} + +// Capture mode names a file per language select item; Japanese twice. +UnitTestResult test_language_tags(Logger&){ + const std::vector& tags = bdsp_language_tags(); + if (tags.size() != LANGUAGE_SELECT_BUTTONS || tags.size() != bdsp_language_menu().size()){ + return "One tag per language select button."; + } + if (tags[1] != "ja-kana" || bdsp_language_menu()[1] != Language::Japanese){ + return "Item 1 is the kana Japanese."; + } + return true; +} + +// The screen at each 250 ms poll, a letter per look. Past the end the last +// letter holds, or with `cycle` the letters start over. +struct BurstInput{ + std::string screens; + bool cycle = false; +}; +struct BurstResult{ + size_t saves; + std::optional stop_at; + bool operator==(const BurstResult&) const = default; +}; +// Runs FrameBurst over `input`, a change being any other letter. +BurstResult run_burst(const BurstInput& input){ + using std::chrono::milliseconds; + FrameBurst burst; + char saved = 0; + char previous = 0; + BurstResult result{0, std::nullopt}; + const std::string& screens = input.screens; + milliseconds at(0); + for (size_t i = 0; i < 400 && !result.stop_at; i++, at += milliseconds(250)){ + const char screen = i < screens.size() ? screens[i] + : input.cycle ? screens[i % screens.size()] : screens.back(); + const auto change = [screen](char other){ return other == screen ? 0.0 : 100.0; }; + const BurstStep step = burst.see(at, change(saved), change(previous)); + previous = screen; + if (step.save){ + saved = screen; + result.saves++; + } + if (step.stop){ + result.stop_at = at; + } + } + return result; +} + +// Capture mode's recording after the look: a frame on each change and each +// second, until the screen holds still for CAPTURE_STILL_FOR (not before +// CAPTURE_MIN_LENGTH), or CAPTURE_MAX_LENGTH. +UnitTestResult test_after_look_burst(Logger&){ + using std::chrono::milliseconds; + using Input = BurstInput; + using Expectation = BurstResult; + struct Case{ + std::string name; + Input input; + Expectation expectation; + }; + const Case cases[] = { + {"a fade, then the keyboard from 1.5 s", {"LLssssK"}, {9, milliseconds(8000)}}, + {"still from the start", {"L"}, {9, milliseconds(8000)}}, + {"a change at 6 s", {std::string(24, 'L') + "K"}, {10, milliseconds(9000)}}, + {"never still", {"ab", true}, {121, CAPTURE_MAX_LENGTH}}, + }; + for (const Case& c : cases){ + const BurstResult got = run_burst(c.input); + if (got != c.expectation){ + return std::format("{}: {} frames saved, stopped at {}.", c.name, got.saves, + got.stop_at ? std::format("{} ms", got.stop_at->count()) : std::string("never")); + } + } + return true; +} + +// The intro's two selects from lab-B 2026-11-09 (each cursor on its first +// item), the screens one A before and after the look select, and screens +// that are neither. Screenshots are in the unit test resources; a missing +// one is passed over, and the test is skipped when all are. +UnitTestResult test_intro_menu_screenshots(Logger& logger){ + ImageRGB32 black(1920, 1080); + black.fill(0xff000000); + if (language_select_cursor(black) || look_select_cursor(black)){ + return "A black screen read as an intro menu."; + } + struct Case{ + std::string_view file; + std::optional language; + std::optional look; + }; + const Case cases[] = { + {.file = "PokemonBDSP/AutoStory/LanguageSelect-20261109.png", .language = 0, .look = std::nullopt}, + {.file = "PokemonBDSP/AutoStory/LookSelect-20261109.png", .language = std::nullopt, .look = 0}, + {.file = "PokemonBDSP/AutoStory/LookSelectBefore-20261109.png", .language = std::nullopt, .look = std::nullopt}, + {.file = "PokemonBDSP/AutoStory/LookSelectAfterA-20261109.png", .language = std::nullopt, .look = std::nullopt}, + {.file = "PokemonBDSP/AutoStory/OreburghCenterCounter-20261108-094735.png", .language = std::nullopt, .look = std::nullopt}, + {.file = "PokemonBDSP/AutoStory/OreburghCenterDoorstep-20261108.png", .language = std::nullopt, .look = std::nullopt}, + }; + size_t read = 0; + for (const Case& c : cases){ + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); + if (!Filesystem::is_regular_file(path)){ + logger.log("Screenshot not found: " + path); + continue; + } + read++; + const ImageRGB32 screen(path); + const std::optional language = language_select_cursor(screen); + const std::optional look = look_select_cursor(screen); + logger.log(std::string(c.file) + ": language " + (language ? std::to_string(*language) : "none") + + ", look " + (look ? std::to_string(*look) : "none")); + if (language != c.language || look != c.look){ + return std::string(c.file) + ": wrong intro menu read."; + } + } + if (read == 0){ + return UnitTestResult(UnitTestResult::SKIPPED, "No intro menu screenshots found."); + } + return true; +} + + // The Mart's doorway on the failure screenshots of r121a and r122a, kept in // the unit test resources (the CommandLineTests checkout): where it is // relative to the player, who is in the middle of the screen. @@ -274,7 +610,7 @@ UnitTestResult test_lit_doorway_screenshots(Logger& logger){ {"PokemonBDSP/AutoStory/SandgemMartDoorFarLeft-20261030-024648.png", -1.3, -0.5, 2.5, 4.5}, }; for (const Case& c : cases){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + c.file; + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); if (!Filesystem::is_regular_file(path)){ return UnitTestResult(UnitTestResult::SKIPPED, "Screenshot not found: " + path); } @@ -345,7 +681,7 @@ UnitTestResult test_pokemon_center_inside(Logger& logger){ {.file = "PokemonBDSP/AutoStory/JubilifeCenterDoorstep-20261030-c5.png", .inside = false, .doorway = true}, }; for (const Case& c : cases){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + c.file; + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); if (!Filesystem::is_regular_file(path)){ return UnitTestResult(UnitTestResult::SKIPPED, "Screenshot not found: " + path); } @@ -383,7 +719,7 @@ UnitTestResult test_pokemon_center_counter(Logger& logger){ {.file = "PokemonBDSP/AutoStory/OreburghCenterDoorstep-20261108.png", .inside = false}, }; for (const Case& c : cases){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + c.file; + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); if (!Filesystem::is_regular_file(path)){ return UnitTestResult(UnitTestResult::SKIPPED, "Screenshot not found: " + path); } @@ -417,7 +753,7 @@ UnitTestResult test_school_lamp(Logger& logger){ {"PokemonBDSP/AutoStory/JubilifeSchoolOneTilePast-20261030.png", 0.5, 1.5}, }; for (const Case& c : cases){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + c.file; + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); if (!Filesystem::is_regular_file(path)){ return UnitTestResult(UnitTestResult::SKIPPED, "Screenshot not found: " + path); } @@ -441,6 +777,29 @@ UnitTestResult test_school_lamp(Logger& logger){ // no name read, Piplup's Pound at 35 PP and Growl at 22 PP, and the old // "newest move that is not a status move" fallback used Growl until the // training gave up after 25 turns. +// A menu read on an empty image, or with buttons outside the frame, reads +// nothing instead of crashing (SIGSEGV in gray_box, 2026-11-12). +UnitTestResult test_move_menu_unreadable(Logger&){ + BattleMoveMenuState moves; + moves.move_count = 2; + moves.buttons[0] = ImageFloatBox{1.1, 0.5, 0.4, 0.1}; + moves.buttons[1] = ImageFloatBox{1.5, 1.5, 0.4, 0.1}; + const ImageRGB32 frame(64, 36); + const ImageViewRGB32 inputs[] = {ImageViewRGB32(), frame}; + for (const ImageViewRGB32& screen : inputs){ + const std::vector slots = read_move_menu(screen, moves); + if (slots.size() != 2){ + return "read_move_menu returned " + std::to_string(slots.size()) + " slots, expected 2."; + } + for (const MoveSlot& slot : slots){ + if (!slot.slug.empty() || slot.pp != -1){ + return "a button outside the frame read a move."; + } + } + } + return true; +} + UnitTestResult test_choose_move(Logger&){ struct Case{ std::string_view name; std::vector slots; size_t best; }; const Case cases[] = { @@ -482,7 +841,7 @@ UnitTestResult test_move_menu_screenshots(Logger& logger){ }; const Language story = story_language(); for (const Case& c : cases){ - const std::string path = UNIT_TEST_RESOURCE_PATH() + c.file; + const std::string path = UNIT_TEST_RESOURCE_PATH() + std::string(c.file); if (!Filesystem::is_regular_file(path)){ return UnitTestResult(UnitTestResult::SKIPPED, "Screenshot not found: " + path); } @@ -566,6 +925,38 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"new-game intro: BDSP or stop", test_intro_gate}, .expectation = {}, }, + { + .input = {"new-game intro: language and look presses", test_intro_pick_moves}, + .expectation = {}, + }, + { + .input = {"new-game intro: steps until the picks are made", test_intro_pick_steps}, + .expectation = {}, + }, + { + .input = {"new-game intro: taken up only before the language pick", test_intro_restart}, + .expectation = {}, + }, + { + .input = {"new-game intro: the language select through the language's load", test_language_select_visits}, + .expectation = {}, + }, + { + .input = {"new-game intro: the name keyboard's limit", test_name_limit}, + .expectation = {}, + }, + { + .input = {"new-game intro: capture file per language", test_language_tags}, + .expectation = {}, + }, + { + .input = {"new-game intro: capture records what follows the look", test_after_look_burst}, + .expectation = {}, + }, + { + .input = {"intro menu screenshots", test_intro_menu_screenshots}, + .expectation = {}, + }, { .input = {"lit doorway screenshots", test_lit_doorway_screenshots}, .expectation = {}, @@ -590,6 +981,10 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"battle moves: the pick from names and PP", test_choose_move}, .expectation = {}, }, + { + .input = {"battle moves: unreadable menu reads nothing", test_move_menu_unreadable}, + .expectation = {}, + }, { .input = {"battle moves: move menu screenshots in each language", test_move_menu_screenshots}, .expectation = {}, @@ -600,6 +995,8 @@ void add_tests_AutoStory_Actions(UnitTestDatabase& database){ for (const auto& item : AUTO_STORY_ACTIONS_CASES){ database.add(item); } + // The menu cursor's own tests, with those of the intro, its first user. + add_tests_MenuCursor(database); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BattleMoves.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BattleMoves.cpp index cae25a7d4d..6557c928a8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BattleMoves.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BattleMoves.cpp @@ -221,6 +221,10 @@ GrayBox gray_box(const ImageViewRGB32& box){ ret.gray[y * box.width() + x] = (int)(((pixel >> 16) & 0xff) + ((pixel >> 8) & 0xff) + (pixel & 0xff)) / 3; } } + if (ret.gray.empty()){ + // Nothing to read: a box outside the frame, or an empty image. + return ret; + } std::vector sorted = ret.gray; std::nth_element(sorted.begin(), sorted.begin() + sorted.size() / 2, sorted.end()); const int background = sorted[sorted.size() / 2]; @@ -259,6 +263,9 @@ std::string read_move_name(const ImageViewRGB32& screen, const ImageFloatBox& bu const ImageFloatBox name_box{button.x + button.width * 0.17, button.y + button.height * 0.08, button.width * 0.53, button.height * 0.80}; const GrayBox box = gray_box(extract_box_reference(screen, name_box)); + if (box.gray.empty()){ + return ""; + } const auto [band_top, band_bottom] = tallest_text_band(box); // Black text on white, with a margin, for the OCR. const size_t pad = 6; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h index 6f3ca50a14..ada565e660 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroProbe.h @@ -15,6 +15,7 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonBDSP{ +namespace detail{ // When X opens nothing the menu detector knows, the player is still in @@ -39,6 +40,7 @@ struct XProbe{ bool intro_in_control_without_menu(const XProbe& probe); +} // namespace detail } // namespace PokemonBDSP } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h index 2b41241cf7..d91340e93c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_IntroSteps.h @@ -6,7 +6,6 @@ * the intro has got only, so it is tested without a console. * */ -// code-health: allow header_symbols -- one intro state machine: its steps, its progress and the limits the step is decided from #ifndef PokemonAutomation_PokemonBDSP_AutoStory_IntroSteps_H #define PokemonAutomation_PokemonBDSP_AutoStory_IntroSteps_H @@ -14,7 +13,7 @@ #include #include #include -#include +#include namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -27,6 +26,9 @@ enum class IntroStep{ SELECT_USER, // A on the Switch's user select FAIL_NOT_IN_GAME, // HOME is showing FAIL_NOT_BDSP, // no BDSP screen within INTRO_TIME_BEFORE_BDSP + FAIL_PICK_MISSED, // the player's keyboard, with a pick still to make + PICK_LANGUAGE, // the language select: move to the game's language, A + PICK_LOOK, // the look select: move to the chosen look, A ENTER_PLAYER_NAME, // type the name on the first keyboard CANCEL_RIVAL_KEYBOARD, // X: back to the rival's name list MOVE_TO_PRESET, // Down: off "I'll tell you..." @@ -40,6 +42,10 @@ enum class IntroStep{ }; // Progress tracking state for the new-game introductory sequence. struct IntroProgress{ + // Picks still to make on the language select and the appearance grid. + // The first look needs no menu: A takes it. + bool language_pending = false; + bool look_pending = false; bool player_named = false; // A preset name was picked from the rival's list, and how many screens // have shown since without the list coming back. "Barry, is it?" and @@ -61,6 +67,15 @@ struct IntroProgress{ // B presses on unknown screens since the last X. size_t b_presses = 0; }; +// Whether `screen` (classify_intro_screen()) is one only BDSP's intro shows: +// its dialogue box, its language and look selects, the rival's name list, its main menu. The keyboard and +// the user select are the Switch's. +bool intro_screen_confirms_bdsp(std::string_view screen); + +// Decides the next controller action based on the current screen and intro progress. +IntroStep decide_intro_step(std::string_view screen, const IntroProgress& progress); + +namespace detail{ // How long the intro presses A on unknown screens, from the first screen // that is not black, before a BDSP screen must show: the logos, the title // and the language select. Another game launched by mistake (r1, @@ -69,16 +84,10 @@ struct IntroProgress{ inline constexpr std::chrono::milliseconds INTRO_TIME_BEFORE_BDSP = std::chrono::seconds(60); // How long the boot may stay black after the restart. inline constexpr std::chrono::milliseconds INTRO_BOOT_LIMIT = std::chrono::seconds(60); -// Whether `screen` (classify_intro_screen()) is one only BDSP's intro shows: -// its dialogue box, the rival's name list, its main menu. The keyboard and -// the user select are the Switch's. -bool intro_screen_confirms_bdsp(const std::string& screen); - // Screens after the rival's name is picked, each taking A, before the name // counts as confirmed and B takes over: "Barry, is it?", the box closing // (Barry alone), the Yes/No, and a few of Rowan's lines after it. inline constexpr size_t INTRO_SCREENS_AFTER_RIVAL_PICK = 8; - // Once the rival is named, the intro only has dialogue and cutscenes left // before the bedroom, and screens the classifier misses (r2: a dialogue box // without its arrow). Each unknown screen takes B, which advances dialogue, @@ -88,14 +97,12 @@ inline constexpr size_t INTRO_B_BEFORE_X = 5; // X presses that opened no menu before the intro gives up: with // INTRO_B_BEFORE_X B presses between them, about two minutes. inline constexpr size_t INTRO_X_WITHOUT_MENU = 20; - -// Notes `screen`, read `since_start` into the intro, in `progress`: the -// game is confirmed on a BDSP screen; black screens leave the clock alone. -void note_intro_screen(IntroProgress& progress, const std::string& screen, std::chrono::milliseconds since_start); -// Decides the next controller action based on the current screen and intro progress. -IntroStep decide_intro_step(const std::string& screen, const IntroProgress& progress); // Counts `step` in `progress`. void record_intro_step(IntroProgress& progress, IntroStep step); +// Notes `screen`, read `since_start` into the intro, in `progress`: the +// game is confirmed on a BDSP screen; black screens leave the clock alone. +void note_intro_screen(IntroProgress& progress, std::string_view screen, std::chrono::milliseconds since_start); +} // namespace detail } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.cpp index 9598f6651d..395c48ee64 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.cpp @@ -4,9 +4,12 @@ * */ +#include +#include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTools/ImageDiff.h" +#include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" @@ -22,6 +25,8 @@ #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" #include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "PokemonBDSP/Inference/PokemonBDSP_NameListDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_IntroMenuDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_NameLimitReader.h" #include "PokemonBDSP_AutoStory_IntroProbe.h" #include "PokemonBDSP_AutoStory_IntroSteps.h" #include "PokemonBDSP_AutoStory_NewGame.h" @@ -31,6 +36,88 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ using namespace std::chrono_literals; +using namespace detail; + + +const std::vector& bdsp_language_menu(){ + static const std::vector menu{ + Language::English, Language::Japanese, + Language::Spanish, Language::Japanese, + Language::French, Language::Korean, + Language::German, Language::ChineseSimplified, + Language::Italian, Language::ChineseTraditional, + }; + return menu; +} + +namespace detail{ +const std::vector& bdsp_language_tags(){ + static const std::vector tags{ + "en", "ja-kana", + "es", "ja", + "fr", "ko", + "de", "zh-Hans", + "it", "zh-Hant", + }; + return tags; +} +} // namespace detail + +namespace{ + +std::optional language_item(Language language){ + const std::vector& menu = bdsp_language_menu(); + const auto it = std::find(menu.begin(), menu.end(), language); + if (it == menu.end()){ + return std::nullopt; + } + return (size_t)(it - menu.begin()); +} + +} // namespace + +std::optional> language_pick_moves(size_t cursor, const IntroPicks& picks){ + const std::optional to = language_item(picks.game_language); + if (!to){ + return std::nullopt; + } + return menu_cursor_moves(BDSP_LANGUAGE_GRID, cursor, *to); +} +std::optional> look_pick_moves(size_t cursor, const IntroPicks& picks){ + return menu_cursor_moves(BDSP_LOOK_GRID, cursor, picks.look); +} + +namespace detail{ +IntroProgress intro_start(const IntroPicks& picks){ + IntroProgress progress; + progress.language_pending = true; + progress.look_pending = picks.look != 0; + return progress; +} +bool intro_restart_needed(std::string_view screen){ + return !(screen == "user-select" || screen == "language-select"); +} +std::optional name_limit_problem(std::string_view name, std::optional limit){ + if (!limit){ + return std::nullopt; + } + // Characters, not UTF-8 bytes: count the bytes that start one. + size_t characters = 0; + for (char c : name){ + if (((unsigned char)c & 0xc0) != 0x80){ + characters++; + } + } + if (characters <= *limit){ + return std::nullopt; + } + return std::format( + "The name keyboard takes at most {} characters in this language, and the player name \"{}\" has {}. " + "Stopped at the name screen with nothing typed: pick a name of at most {} characters and start again.", + *limit, name, characters, *limit + ); +} +} // namespace detail std::string classify_intro_screen(ConsoleHandle* console, const ImageViewRGB32& screen){ @@ -44,6 +131,13 @@ std::string classify_intro_screen(ConsoleHandle* console, const ImageViewRGB32& if (SystemKeyboardDetector().detect(screen)){ return "keyboard"; } + // Before the dialogue box: its prompt sits in one. + if (language_select_cursor(screen)){ + return "language-select"; + } + if (look_select_cursor(screen)){ + return "look-select"; + } switch (NameListDetector().selected_row(screen)){ case -1: break; @@ -67,7 +161,7 @@ std::string classify_intro_screen(ConsoleHandle* console, const ImageViewRGB32& return "other"; } -IntroStep decide_intro_step(const std::string& screen, const IntroProgress& progress){ +IntroStep decide_intro_step(std::string_view screen, const IntroProgress& progress){ if (screen == "user-select"){ return IntroStep::SELECT_USER; } @@ -75,8 +169,18 @@ IntroStep decide_intro_step(const std::string& screen, const IntroProgress& prog return IntroStep::FAIL_NOT_IN_GAME; } if (screen == "keyboard"){ + if (!progress.player_named && (progress.language_pending || progress.look_pending)){ + return IntroStep::FAIL_PICK_MISSED; + } return progress.player_named ? IntroStep::CANCEL_RIVAL_KEYBOARD : IntroStep::ENTER_PLAYER_NAME; } + if (screen == "language-select"){ + // Once picked, A again only if the select still shows. + return progress.language_pending ? IntroStep::PICK_LANGUAGE : IntroStep::ADVANCE; + } + if (screen == "look-select"){ + return progress.look_pending ? IntroStep::PICK_LOOK : IntroStep::ADVANCE; + } if (screen == "rival-list-tell"){ return IntroStep::MOVE_TO_PRESET; } @@ -102,13 +206,21 @@ IntroStep decide_intro_step(const std::string& screen, const IntroProgress& prog if (!progress.game_confirmed && progress.unconfirmed_for >= INTRO_TIME_BEFORE_BDSP){ return IntroStep::FAIL_NOT_BDSP; } + // Between the language pick and the look pick, an unknown screen is a fade or + // a cutscene frame, and the look select can show for a frame before it reads + // as one (A on that frame takes look 1). Wait there; the + // professor's lines are read as dialog and take their A. + if (!progress.language_pending && progress.look_pending){ + return IntroStep::WAIT; + } return IntroStep::ADVANCE; } -bool intro_screen_confirms_bdsp(const std::string& screen){ - return screen == "dialog" || screen == "rival-list-tell" || screen == "rival-list-preset" || screen == "menu"; +bool intro_screen_confirms_bdsp(std::string_view screen){ + return screen == "dialog" || screen == "language-select" || screen == "look-select" || screen == "rival-list-tell" || screen == "rival-list-preset" || screen == "menu"; } -void note_intro_screen(IntroProgress& progress, const std::string& screen, std::chrono::milliseconds since_start){ +namespace detail{ +void note_intro_screen(IntroProgress& progress, std::string_view screen, std::chrono::milliseconds since_start){ if (intro_screen_confirms_bdsp(screen)){ progress.game_confirmed = true; } @@ -157,6 +269,20 @@ void record_intro_step(IntroProgress& progress, IntroStep step){ } } +BurstStep FrameBurst::see(std::chrono::milliseconds at, double from_saved, double from_previous){ + if (from_previous > CAPTURE_CHANGE){ + m_last_change = at; + } + BurstStep step; + step.save = !m_last_saved || from_saved > CAPTURE_CHANGE || at - *m_last_saved >= CAPTURE_EVERY; + if (step.save){ + m_last_saved = at; + } + step.stop = at >= CAPTURE_MAX_LENGTH || (at >= CAPTURE_MIN_LENGTH && at - m_last_change >= CAPTURE_STILL_FOR); + return step; +} +} // namespace detail + namespace{ // Waits until the keyboard is gone (or, with `gone` false, has appeared). @@ -188,6 +314,15 @@ void enter_player_name(VideoStream& stream, ProControllerContext& context, StepT pbf_press_button(context, BUTTON_B, 60ms, 250ms); context.wait_for_all_requests(); } + // The keyboard drops presses past its limit: stop before typing. + VideoSnapshot screen = stream.video().snapshot(); + const std::optional limit = screen ? read_keyboard_name_limit(*screen.frame) : std::nullopt; + trace.action(limit + ? std::format("The keyboard takes up to {} characters.", *limit) + : std::string("The keyboard's character counter did not read; typing anyway.")); + if (const std::optional problem = name_limit_problem(name, limit)){ + trace.fail(*problem); + } trace.action("Typing the player's name: " + name); FastCodeEntry::type_on_system_keyboard(stream, context, name); pbf_press_button(context, BUTTON_PLUS, 80ms, 0ms); @@ -202,14 +337,98 @@ struct IntroRun{ SingleSwitchProgramEnvironment& env; ProControllerContext& context; StepTrace& trace; + const IntroPicks& picks; const std::string& player_name; WallClock start; IntroProgress progress; size_t x_without_menu = 0; // X opened something and B closed it, from a still screen. bool in_control = false; + // The language select's item to pick. + size_t language_target = 0; + // Capture mode (capture_intro_screens()): the run ends with the + // recording after the look's A, saved as _after-look_NNN.png; + // the screen is saved before the look's pick, and with + // `capture_language_pick` before the language's. + bool capture = false; + bool capture_language_pick = false; + std::string capture_tag; + bool capture_done = false; }; +// Saves `frame` as /_.png. +void save_frame(IntroRun& run, const VideoSnapshot& frame, std::string_view what){ + const std::string path = std::format("{}{}_{}.png", SCREENSHOTS_PATH(), run.capture_tag, what); + frame.frame->save(path); + run.trace.action("Captured " + path); +} + +// Saves the frame on screen now, whatever it shows, as /_.png. +void save_capture(IntroRun& run, std::string_view what){ + run.context.wait_for_all_requests(); + const VideoSnapshot screen = run.env.console.video().snapshot(); + if (!screen){ + run.trace.action(std::format("No video frame for {}_{}: nothing saved.", run.capture_tag, what)); + return; + } + save_frame(run, screen, what); +} + +// How much the whole screen changed from `before` to `after`, pixel RMSD; +// large when either is missing. +double frame_change(const VideoSnapshot& before, const VideoSnapshot& after){ + if (!before || !after){ + return 1000; + } + return ImageMatch::pixel_RMSD(*before.frame, *after.frame); +} + +// Polls between capture mode's frames after the look. +const Milliseconds CAPTURE_POLL = 250ms; + +// Capture mode, from the look's A: records what the game shows next as +// _after-look_NNN.png (FrameBurst decides which frames and when to +// stop), reading nothing on it. It presses nothing. On lab-B (2026-11-09, +// English) the look's A goes straight to the system name keyboard, and on +// that keyboard no button is safe: A types the key under the cursor, B +// deletes a character or, on an empty field, closes the keyboard, PLUS +// confirms the name, X cancels it (CANCEL_RIVAL_KEYBOARD), and the D-pad +// and sticks move the cursor the next A types from. So dialogue that some +// language may show before its keyboard is not advanced: the recording +// runs at least CAPTURE_MIN_LENGTH and ends on it, and the trace says so. +void record_after_look(IntroRun& run){ + VideoStream& stream = run.env.console; + run.context.wait_for_all_requests(); + const WallClock start = current_time(); + FrameBurst burst; + VideoSnapshot saved; + VideoSnapshot previous; + size_t count = 0; + std::chrono::milliseconds at(0); + // Bounded by CAPTURE_MAX_LENGTH: FrameBurst stops there, and so does a feed with no frames. + while (at < CAPTURE_MAX_LENGTH){ + VideoSnapshot frame = stream.video().snapshot(); + at = std::chrono::duration_cast(current_time() - start); + if (frame){ + const BurstStep step = burst.see(at, frame_change(saved, frame), frame_change(previous, frame)); + if (step.save){ + save_frame(run, frame, std::format("after-look_{:03}", count++)); + saved = frame; + } + previous = std::move(frame); + if (step.stop){ + break; + } + } + run.context.wait_for(CAPTURE_POLL); + } + run.trace.action(std::format( + "Recorded {} frames over {} s after the look's pick, pressing nothing. If the last ones show " + "dialogue rather than the name keyboard, that dialogue blocks the keyboard in capture mode.", + count, at.count() / 1000)); + run.capture_done = true; +} + void press(IntroRun& run, Button button){ pbf_press_button(run.context, button, 80ms, 0ms); } @@ -272,7 +491,7 @@ void probe_for_menu(IntroRun& run){ const XProbeResult result = x_from_still_screen(run); run.in_control = result == XProbeResult::IN_CONTROL; if (result != XProbeResult::NOTHING){ - return; // The next read sees the menu, or the in-control state, and finishes. + return; // The next read sees the menu, or the finished state, and finishes. } run.trace.action("X opened no menu; B again before the next X."); if (++run.x_without_menu >= INTRO_X_WITHOUT_MENU){ @@ -280,12 +499,112 @@ void probe_for_menu(IntroRun& run){ } } -// Carries out what decide_intro_step() chose for `screen`. -void act(IntroRun& run, const std::string& screen){ +void advance(IntroRun& run){ + pbf_press_button(run.context, BUTTON_A, 60ms, 400ms); +} + +// One of the intro's two menus: its shape and its cursor reader. +struct IntroMenu{ + std::string_view what; + MenuGrid grid; + std::optional (*read)(const ImageViewRGB32& screen); +}; +const IntroMenu LANGUAGE_MENU{"language", BDSP_LANGUAGE_GRID, language_select_cursor}; +const IntroMenu LOOK_MENU{"look", BDSP_LOOK_GRID, look_select_cursor}; + +// Reads of a menu before its cursor must be on the pick. +const size_t INTRO_PICK_TRIES = 3; + +// The menu's cursor as read now; nullopt when the menu is not showing. +std::optional read_cursor(IntroRun& run, const IntroMenu& menu){ + run.context.wait_for_all_requests(); + const VideoSnapshot screen = run.env.console.video().snapshot(); + if (!screen){ + return std::nullopt; + } + return menu.read(*screen.frame); +} + +// Reads the cursor, moves it to `target` and reads it there, up to +// INTRO_PICK_TRIES times (a press dropped as the screen fades in), then +// saves a screenshot and presses A. Whether it picked: false when the menu +// went away, and the next read decides. +bool pick_on_grid(IntroRun& run, const IntroMenu& menu, size_t target){ + for (size_t attempt = 0; attempt < INTRO_PICK_TRIES; attempt++){ + const std::optional cursor = read_cursor(run, menu); + if (!cursor){ + return false; + } + run.trace.action(std::string("Picking the ") + std::string(menu.what) + ": cursor on item " + std::to_string(*cursor) + + ", the pick is item " + std::to_string(target) + "."); + if (*cursor == target){ + run.trace.screen(std::string("pick-") + std::string(menu.what)); + press(run, BUTTON_A); + pbf_wait(run.context, 500ms); + return true; + } + press_cursor_moves(run.context, *menu_cursor_moves(menu.grid, *cursor, target)); + } + run.trace.fail(std::string("The ") + std::string(menu.what) + " menu's cursor did not reach its pick in " + + std::to_string(INTRO_PICK_TRIES) + " tries."); +} + +// PICK_LANGUAGE or PICK_LOOK. +void pick_on_intro_menu(IntroRun& run, IntroStep step){ + const bool language = step == IntroStep::PICK_LANGUAGE; + if (language ? run.capture_language_pick : run.capture){ + save_capture(run, language ? "before-language-pick" : "before-look-pick"); + } + if (language){ + if (pick_on_grid(run, LANGUAGE_MENU, run.language_target)){ + run.progress.language_pending = false; + } + return; + } + if (pick_on_grid(run, LOOK_MENU, run.picks.look)){ + run.progress.look_pending = false; + if (run.capture){ + record_after_look(run); + } + } +} + +// Notes `screen` in the run's progress, decides the step for it and counts it. +IntroStep next_intro_step(IntroRun& run, std::string_view screen){ note_intro_screen(run.progress, screen, std::chrono::duration_cast(current_time() - run.start)); const IntroStep step = decide_intro_step(screen, run.progress); record_intro_step(run.progress, step); + return step; +} + +// Stops the intro for one of the FAIL_ steps. +[[noreturn]] void fail_intro(const IntroRun& run, IntroStep step){ + if (step == IntroStep::FAIL_NOT_IN_GAME){ + run.trace.fail("The Switch HOME menu is showing: the game is not running in front."); + } + if (step == IntroStep::FAIL_NOT_BDSP){ + run.trace.fail("The game in front is not BDSP: no BDSP screen in " + + std::to_string(run.progress.unconfirmed_for.count() / 1000) + " s of unknown screens."); + } + run.trace.fail(std::string("The player's name keyboard showed before the ") + + (run.progress.language_pending ? "language select" : "appearance grid") + + " was read."); +} + +// ENTER_PLAYER_NAME: types the name, or in capture mode records the screen +// as after the look, typing nothing. +void name_player(IntroRun& run){ + if (run.capture){ + record_after_look(run); + return; + } + enter_player_name(run.env.console, run.context, run.trace, run.player_name); +} + +// Carries out what decide_intro_step() chose for `screen`. +void act(IntroRun& run, std::string_view screen){ + const IntroStep step = next_intro_step(run, screen); switch (step){ case IntroStep::SELECT_USER: // The cursor starts on the user that launched the game. @@ -293,12 +612,15 @@ void act(IntroRun& run, const std::string& screen){ pbf_wait(run.context, 1000ms); return; case IntroStep::FAIL_NOT_IN_GAME: - run.trace.fail("The Switch HOME menu is showing: the game is not running in front."); case IntroStep::FAIL_NOT_BDSP: - run.trace.fail("The game in front is not BDSP: no BDSP screen in " + - std::to_string(run.progress.unconfirmed_for.count() / 1000) + " s of unknown screens."); + case IntroStep::FAIL_PICK_MISSED: + fail_intro(run, step); + case IntroStep::PICK_LANGUAGE: + case IntroStep::PICK_LOOK: + pick_on_intro_menu(run, step); + return; case IntroStep::ENTER_PLAYER_NAME: - enter_player_name(run.env.console, run.context, run.trace, run.player_name); + name_player(run); return; case IntroStep::CANCEL_RIVAL_KEYBOARD: // Opened from "I'll tell you..."; inputs during the slide-in are dropped. @@ -316,7 +638,7 @@ void act(IntroRun& run, const std::string& screen){ close_menu_and_finish(run); return; case IntroStep::ADVANCE: - pbf_press_button(run.context, BUTTON_A, 60ms, 400ms); + advance(run); return; case IntroStep::ADVANCE_WITH_B: case IntroStep::CLEAR_WITH_B: @@ -354,9 +676,10 @@ std::vector intro_states(IntroRun& run){ return classify_intro_screen(&run.env.console, screen) == name; }; return { - {"in-control", - [&run](const ImageViewRGB32&){ return run.in_control; }, nullptr, - [&run]{ run.trace.action("X opened and B closed the menu from a still bedroom: the player is in control."); }, + // The player in control without the menu read, or capture mode's recording done. + {"finished", + [&run](const ImageViewRGB32&){ return run.in_control || run.capture_done; }, nullptr, + [&run]{ run.trace.action(run.capture_done ? "Recording after the look done." : "X opened and B closed the menu from a still bedroom: the player is in control."); }, {}, 1, true}, {"user-select", [=](const ImageViewRGB32& s){ return screen_is(s, "user-select"); }, nullptr, @@ -366,10 +689,16 @@ std::vector intro_states(IntroRun& run){ [&run]{ act(run, "home"); }, {}, 1}, {"player-keyboard", [=, &run](const ImageViewRGB32& s){ return !run.progress.player_named && screen_is(s, "keyboard"); }, nullptr, - [&run]{ act(run, "keyboard"); }, {"dialog", "black", "other"}, 1}, + [&run]{ act(run, "keyboard"); }, {"finished", "dialog", "black", "other"}, 1}, {"rival-keyboard", [=, &run](const ImageViewRGB32& s){ return run.progress.player_named && screen_is(s, "keyboard"); }, nullptr, [&run]{ act(run, "keyboard"); }, {"rival-list-tell", "dialog", "black", "other"}, 3}, + {"language-select", + [=](const ImageViewRGB32& s){ return screen_is(s, "language-select"); }, nullptr, + [&run]{ act(run, "language-select"); }, {}, INTRO_LANGUAGE_SELECT_VISITS}, + {"look-select", + [=](const ImageViewRGB32& s){ return screen_is(s, "look-select"); }, nullptr, + [&run]{ act(run, "look-select"); }, {}, 10}, {"rival-list-tell", [=](const ImageViewRGB32& s){ return screen_is(s, "rival-list-tell"); }, nullptr, [&run]{ act(run, "rival-list-tell"); }, {"rival-list-preset", "black", "other"}, 6}, @@ -392,6 +721,33 @@ std::vector intro_states(IntroRun& run){ }; } +// The restart reopens the game HOME's cursor is on, which is the game +// running in front only while it runs: with none running (r1, 2026-11-01), +// closing it fails, HOME is pressed again, the cursor goes to the first +// tile, and another game was launched. So BDSP must be running in front. +// Returns the frame on screen, if any. +VideoSnapshot require_game_in_front(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot start = env.console.video().snapshot(); + if (start && HomeMenuDetector(env.console, COLOR_RED).detect(start)){ + throw UserSetupError(env.console, + "Start a new game with BDSP running in front, not from the Switch's HOME menu: " + "the intro restarts the game in front."); + } + return start; +} + +// Only closes and reopens the game: the states take it from the user select +// on. reset_game_from_home() waits for a loaded save's black screen to end, and a +// new game's first screen is a dialog on black, so it would sit there until its +// timeout. +void restart_game(SingleSwitchProgramEnvironment& env, ProControllerContext& context, StepTrace& trace){ + trace.action("Restarting the game."); + go_home(env.console, context); + from_home_close_and_reopen_game(env.console, context, true); + wait_out_boot(env.console, context, trace); +} + } // namespace @@ -399,39 +755,62 @@ std::vector intro_states(IntroRun& run){ void play_new_game_intro( SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const IntroPicks& picks, const std::string& player_name ){ VideoStream& stream = env.console; StepTrace trace(stream, "Intro"); - // The restart below reopens the game HOME's cursor is on, which is the - // game running in front only while it runs: with none running (r1, - // 2026-11-01), closing it fails, HOME is pressed again, the cursor goes - // to the first tile, and another game was launched. So BDSP must be - // running in front when the intro starts. - context.wait_for_all_requests(); - VideoSnapshot start = stream.video().snapshot(); - if (start && HomeMenuDetector(env.console, COLOR_RED).detect(start)){ - throw UserSetupError(env.console, - "Start a new game with BDSP running in front, not from the Switch's HOME menu: " - "the intro restarts the game in front."); + if (!language_pick_moves(0, picks)){ + throw UserSetupError(env.console, "BDSP's language select lacks the game's language: pick one it lists."); + } + if (!look_pick_moves(0, picks)){ + throw UserSetupError(env.console, "The player's look must be one of BDSP's eight."); } - // Only close and reopen the game: the states below take it from the user select - // on. reset_game_from_home() waits for a loaded save's black screen to end, and a - // new game's first screen is a dialog on black, so it would sit there until its - // timeout. - trace.action("Restarting the game."); - go_home(env.console, context); - from_home_close_and_reopen_game(env.console, context, true); - - wait_out_boot(stream, context, trace); - IntroRun run{env, context, trace, player_name, current_time(), {}, 0}; + const VideoSnapshot start = require_game_in_front(env, context); + const std::string first = start ? classify_intro_screen(&env.console, *start.frame) : "other"; + if (intro_restart_needed(first)){ + restart_game(env, context, trace); + }else{ + // Nothing is picked yet, and the user select would go away with a restart. + trace.action("The intro shows (" + first + "), before the language pick: taking it up there, without a restart."); + } + IntroRun run{env, context, trace, picks, player_name, current_time(), intro_start(picks), 0}; + run.language_target = *language_item(picks.game_language); + trace.action(std::string("Picks: language ") + language_data(picks.game_language).name + + " (item " + std::to_string(run.language_target) + "), look " + std::to_string(picks.look + 1) + "."); const std::vector states = intro_states(run); run_screen_machine(stream, context, states, std::chrono::minutes(15), trace); trace.action("Intro done."); } +void capture_intro_screens(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t look){ + StepTrace trace(env.console, "IntroCapture"); + const IntroPicks picks{Language::English, look}; + if (!look_pick_moves(0, picks)){ + throw UserSetupError(env.console, "The player's look must be one of BDSP's eight."); + } + require_game_in_front(env, context); + const std::string no_name; + const std::vector& tags = bdsp_language_tags(); + for (size_t item = 0; item < tags.size(); item++){ + // No save exists, so each restart plays the intro from the start. + restart_game(env, context, trace); + IntroRun run{env, context, trace, picks, no_name, current_time(), intro_start(picks), 0}; + run.progress.look_pending = true; + run.language_target = item; + run.capture = true; + // The language list shows before any language is picked: once is enough. + run.capture_language_pick = item == 0; + run.capture_tag = std::string(tags[item]); + trace.action("Capturing language item " + std::to_string(item) + " (" + run.capture_tag + ")."); + const std::vector states = intro_states(run); + run_screen_machine(env.console, context, states, std::chrono::minutes(10), trace); + } + trace.action("Captured " + std::to_string(tags.size()) + " languages to " + SCREENSHOTS_PATH()); +} + } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.h index 422611745c..41936a0391 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_NewGame.h @@ -4,43 +4,157 @@ * * Plays a new game's intro (language, Professor Rowan, appearance, names) up to * the bedroom with the player in control, which is where the Tutorial starts. + * The language and the player's look are picked from their menus by index + * (NintendoSwitch_MenuCursor.h); the menus' shapes are the data below. + * Both menus are read by their detector (PokemonBDSP_AutoStory_IntroMenuDetector.h). * */ +// code-health: allow header_symbols -- the intro's entry points (play, capture), its two menus' data, its screen classifier and capture mode's recording policy #ifndef PokemonAutomation_PokemonBDSP_AutoStory_NewGame_H #define PokemonAutomation_PokemonBDSP_AutoStory_NewGame_H +#include +#include +#include #include +#include +#include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "NintendoSwitch/Programs/MenuCursor/NintendoSwitch_MenuCursor.h" +#include "PokemonBDSP_AutoStory_IntroSteps.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonBDSP{ +// The language select: two columns of five buttons, English, Espanol, +// Francais, Deutsch, Italiano on the left; Japanese in kana, Japanese in +// kanji, Korean, Simplified and Traditional Chinese on the right (lab-B +// 2026-11-09). Items are numbered row by row, as MenuGrid reads them. +inline constexpr MenuGrid BDSP_LANGUAGE_GRID{2, 10}; +// The language of each item of BDSP_LANGUAGE_GRID. Japanese is there twice; +// its first item, the kana, is the one picked. +const std::vector& bdsp_language_menu(); +// The look select ("Choose your photo."): two rows of four portraits, the +// cursor on the first (lab-B 2026-11-09). PlayerModelOption's "Model N" is +// item N - 1, row by row: Lucas light, Lucas dark, Dawn dark-haired, Dawn +// dark; Lucas blond, Lucas brown, Dawn blond, Dawn brown-haired. A on it +// goes straight to the name keyboard. +inline constexpr MenuGrid BDSP_LOOK_GRID{4, 8}; + +// What the intro picks on its menus. +struct IntroPicks{ + Language game_language = Language::English; + // An item of BDSP_LOOK_GRID. + size_t look = 0; +}; +// The presses from the language select's item `cursor` to the game's +// language; nullopt when the menu lacks it or `cursor` is outside it. +std::optional> language_pick_moves(size_t cursor, const IntroPicks& picks); +// The presses from the look select's item `cursor` to the chosen look; +// nullopt when either is outside the grid. +std::optional> look_pick_moves(size_t cursor, const IntroPicks& picks); + + // Which intro screen `screen` shows, as the intro's steps tell them apart: -// "user-select", "home", "keyboard", "rival-list-tell" (the rival's name list on +// "user-select", "home", "keyboard", "language-select", "look-select", "rival-list-tell" (the rival's name list on // "I'll tell you..."), "rival-list-preset" (on a preset name), "menu", "dialog" or // "black" (the boot, fades) or "other". The Switch's own screens need // `console`; without it they read as whatever else they look like. std::string classify_intro_screen(ConsoleHandle* console, const ImageViewRGB32& screen); +namespace detail{ +// How often the language select may come up, its pick included, before the +// intro fails. After the pick it stays up while the game loads the +// language, and each look takes A (a pick whose A was dropped): Japanese's +// load took the pick and 10 looks (lab-B 2026-11-15), about 6 s. +inline constexpr size_t INTRO_LANGUAGE_SELECT_VISITS = 30; +// Short names of BDSP_LANGUAGE_GRID's items, in its order, for capture +// mode's file names: "en", "ja-kana", "es", "ja", ... +const std::vector& bdsp_language_tags(); +// The progress a new intro starts from: which of `picks` need a menu. +IntroProgress intro_start(const IntroPicks& picks); +// Whether the intro restarts the game when `screen` (classify_intro_screen()) +// shows at its start: on every screen but the user select and the language +// select, which come before the language is picked. Past the pick the game's +// language may not be the one asked for, and nothing on screen tells it. +bool intro_restart_needed(std::string_view screen); +// Why `name` cannot be typed on a keyboard that takes `limit` characters, +// or nullopt when it fits or the limit was not read. +std::optional name_limit_problem(std::string_view name, std::optional limit); + +// Capture mode's recording after the look's A, which reads nothing on the +// screen: frames are polled, one is saved when it changed or a while after +// the last, and the recording stops when the screen holds still. +// A change between two frames, pixel RMSD over the whole screen, larger +// than this is a change: a frame that far from the last saved is saved. +inline constexpr double CAPTURE_CHANGE = 4; +// A frame is saved at least this long after the last saved. +inline constexpr std::chrono::milliseconds CAPTURE_EVERY = std::chrono::seconds(1); +// The recording stops when no poll changed the screen for this long... +inline constexpr std::chrono::milliseconds CAPTURE_STILL_FOR = std::chrono::seconds(3); +// ...but not before this, which leaves dialogue that pauses before the +// keyboard time to show in the frames, +inline constexpr std::chrono::milliseconds CAPTURE_MIN_LENGTH = std::chrono::seconds(8); +// and at the latest at this. +inline constexpr std::chrono::milliseconds CAPTURE_MAX_LENGTH = std::chrono::seconds(30); +// What the recording does with one polled frame. +struct BurstStep{ + bool save = false; + bool stop = false; +}; +// The recording's save and stop decisions; times are since it began. +class FrameBurst{ +public: + // The frame polled at `at`: `from_saved` is its change from the last + // saved frame (any value before the first save), `from_previous` from + // the frame polled before it. + BurstStep see(std::chrono::milliseconds at, double from_saved, double from_previous); + +private: + std::optional m_last_saved; + std::chrono::milliseconds m_last_change{0}; +}; +} // namespace detail + // From the title screen or any intro screen of a game with no save, with BDSP // running in front: from HOME it throws UserSetupError, since the restart would -// launch whatever tile HOME's cursor is on. Restarts the game first, so it -// always starts from the title, waits out the black boot (up to +// launch whatever tile HOME's cursor is on, as it does for picks no menu has. +// On the user select or the language select (intro_restart_needed()) it takes +// the intro up from there, without closing the game. Otherwise it restarts the game, so it +// starts from the title, waits out the black boot (up to // INTRO_BOOT_LIMIT) without pressing anything, and fails if no BDSP screen shows within -// INTRO_TIME_BEFORE_BDSP of screens. Names the player `player_name` -// and picks the rival's default name (Barry) from the list. Each step reads the +// INTRO_TIME_BEFORE_BDSP of screens. Picks the language and the look in +// `picks`, names the player `player_name` (failing at the name screen, +// nothing typed, when the keyboard takes fewer characters) and picks the rival's default name +// (Barry) from the list. The language and look selects are read, moved on +// and read again before their A. The player's keyboard showing with a pick +// still to make fails. Each step reads the // screen and waits for the expected next one; an unexpected screen fails with a // screenshot and the recent screens. void play_new_game_intro( SingleSwitchProgramEnvironment& env, ProControllerContext& context, + const IntroPicks& picks, const std::string& player_name ); +// Developer: shoots the intro's screens for each language of the language +// select, for a game with no save running in front. Per language it +// restarts the game, picks the language and `look` (an item of +// BDSP_LOOK_GRID), and records what shows after the look's A, pressing +// nothing, as /_after-look_NNN.png (bdsp_language_tags(), +// NN from 00 in order; FrameBurst). Each round saves the screen as the look +// is about to be picked as _before-look-pick.png, and the first round +// the one before the language pick as _before-language-pick.png. It +// never types or confirms a name, and leaves the game where the last +// recording ended. +void capture_intro_screens(SingleSwitchProgramEnvironment& env, ProControllerContext& context, size_t look); + } // namespace PokemonBDSP } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.cpp index bf3540c9c8..4c154ab930 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.cpp @@ -7,6 +7,7 @@ */ #include +#include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTools/ImageBoxes.h" @@ -18,6 +19,7 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_Bag.h" #include "PokemonBDSP_AutoStory_BagScreen.h" #include "PokemonBDSP_AutoStory_Settings.h" @@ -27,6 +29,46 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ using namespace std::chrono_literals; +using detail::OptionsLayout; +using detail::OptionsRow; + + +namespace detail{ + +OptionsLayout options_layout(Language language){ + OptionsLayout layout{ + .rows = { + {.label = "textspeed", .value = "fast", .columns = 3, .column = 2}, + {.label = "changewindow", .value = "type1"}, + {.label = "battleeffects", .value = "off", .columns = 2, .column = 1}, + {.label = "battlestyle", .value = "set", .columns = 2, .column = 1}, + {.label = "sendtoboxes", .value = "automatic", .columns = 2, .column = 1}, + {.label = "givenicknames", .value = "dontgive", .columns = 2, .column = 1}, + {.label = "gyroscope", .value = "use", .columns = 2, .column = 0}, + {.label = "autosave", .value = "off", .columns = 2, .column = 1}, + {.label = "shownicknames", .value = "show", .columns = 2, .column = 0}, + {.label = "backgroundmusic", .value = "8", .slider = true}, + {.label = "soundeffects", .value = "8", .slider = true}, + }, + .label_images = language == Language::English, + }; + if (language == Language::Japanese){ + layout.rows.insert(layout.rows.begin() + 1, OptionsRow{.label = "mojimode", .value = ""}); + } + return layout; +} + +std::optional options_value_column(double x, size_t columns){ + // The values' box: the one the value images were cut from. + constexpr double LEFT = 0.33; + constexpr double WIDTH = 0.54; + if (columns == 0 || x < LEFT || x >= LEFT + WIDTH){ + return std::nullopt; + } + return (size_t)((x - LEFT) / WIDTH * columns); +} + +} // namespace detail namespace{ @@ -113,6 +155,28 @@ class TutorialOptionPositionDetector { } return red > value.width() * value.height() * 0.0005; } + // The centre of the selected value's red ink, as a fraction of the + // screen width; none without red ink. + std::optional selected_value_x(const ImageViewRGB32& screen, double y) const { + const ImageFloatBox box{0.33, y - 0.025, 0.54, 0.05}; + ImageViewRGB32 value = extract_box_reference(screen, box); + size_t red = 0; + double x_sum = 0; + for (size_t py = 0; py < value.height(); py++){ + for (size_t px = 0; px < value.width(); px++){ + uint32_t p = value.pixel(px, py); + int r = (p >> 16) & 255, g = (p >> 8) & 255, b = p & 255; + if (r > g + 20 && r > b + 20){ + red++; + x_sum += (double)px; + } + } + } + if (red == 0 || value.width() == 0){ + return std::nullopt; + } + return box.x + box.width * (x_sum / red) / value.width(); + } }; @@ -164,33 +228,18 @@ bool autosave_off_highlight(const ImageViewRGB32& screen, double y){ return off >= 10 && on * 10 < off; } -// The options the story needs, as each reference image names them: the -// row's label and the value to select. -struct Setting{ - std::string label; - std::string value; -}; -const Setting SETTINGS[] = { - {"textspeed", "fast"}, {"changewindow", "type1"}, - {"battleeffects", "off"}, {"battlestyle", "set"}, - {"sendtoboxes", "automatic"}, {"givenicknames", "dontgive"}, - {"gyroscope", "use"}, {"autosave", "off"}, - {"shownicknames", "show"}, {"backgroundmusic", "8"}, - {"soundeffects", "8"}, -}; -constexpr size_t SETTING_COUNT = sizeof(SETTINGS) / sizeof(SETTINGS[0]); -constexpr size_t AUTOSAVE_ROW = 7; -constexpr size_t FIRST_SLIDER_ROW = 9; // The Options screen and its selected row, as one reader. struct OptionsScreen{ TutorialOptionsDetector options_screen; TutorialOptionPositionDetector position; }; -// A row's label and target value, as the reference images show them. +// A row's label and target value, as the reference images show them; +// none for a label without images in the game language, or a row the +// story leaves as it is. struct OptionReferences{ - ImageRGB32 label; - ImageRGB32 value; + std::optional label; + std::optional value; }; // From the overworld (or the main menu): the main menu, settled. @@ -245,8 +294,8 @@ void open_options(VideoStream& stream, ProControllerContext& context, const Tuto } // How well the selected row's value matches the reference. -double option_value_score(const ImageViewRGB32& frame, double y, size_t row, const ImageRGB32& value_reference){ - if (row >= FIRST_SLIDER_ROW){ +double option_value_score(const ImageViewRGB32& frame, double y, const OptionsRow& row, const ImageRGB32& value_reference){ + if (row.slider){ // Compare the numeric value rather than the long slider: // neighboring slider levels otherwise look too similar. ImageViewRGB32 number = value_reference.sub_image( @@ -264,18 +313,18 @@ double option_value_score(const ImageViewRGB32& frame, double y, size_t row, con // Whether Options shows Autosave selected and set to Off: a frame's look. bool autosave_off_on_screen( const ImageViewRGB32& check, const TutorialOptionsDetector& options_screen, - const TutorialOptionPositionDetector& position, const ImageRGB32& autosave_label + const TutorialOptionPositionDetector& position, const std::optional& autosave_label ){ const double check_y = check ? position.selected_row(check) : -1; return check && options_screen.detect(check) && check_y >= 0 && - option_image_score(check, {0.08, check_y - 0.025, 0.24, 0.05}, autosave_label, false) >= 0.80 && + (!autosave_label || option_image_score(check, {0.08, check_y - 0.025, 0.24, 0.05}, *autosave_label, false) >= 0.80) && autosave_off_highlight(check, check_y); } // Autosave Off, on three more frames 200 ms apart. void confirm_autosave_off( VideoStream& stream, ProControllerContext& context, const TutorialOptionsDetector& options_screen, - const TutorialOptionPositionDetector& position, const ImageRGB32& label_reference + const TutorialOptionPositionDetector& position, const std::optional& label_reference ){ for (size_t confirmation = 0; confirmation < 3; confirmation++){ pbf_wait(context, 200ms); @@ -290,8 +339,8 @@ void confirm_autosave_off( // One press toward the target value. Sliders clamp at zero: establish a // known endpoint, then increment; the target image is verified afterward. -void correct_option(ProControllerContext& context, size_t row, bool& slider_reset){ - if (row >= FIRST_SLIDER_ROW && !slider_reset){ +void correct_option(ProControllerContext& context, const OptionsRow& row, bool& slider_reset){ + if (row.slider && !slider_reset){ for (size_t step = 0; step < 12; step++){ pbf_press_dpad(context, DPAD_LEFT, 80ms, 100ms); } @@ -303,62 +352,110 @@ void correct_option(ProControllerContext& context, size_t row, bool& slider_rese } // The selected row on screen, if it is the expected one with its value -// highlighted; -1 otherwise. +// highlighted; -1 otherwise. Without a label image (a game language +// other than English) the row is the one the presses reached: the +// selected row with its value highlighted. double expected_row_y( - VideoStream& stream, const ImageViewRGB32& frame, const TutorialOptionsDetector& options_screen, - const TutorialOptionPositionDetector& position, size_t row, const ImageRGB32& label_reference + VideoStream& stream, const ImageViewRGB32& frame, const OptionsScreen& screen, + const OptionsRow& row, const std::optional& label_reference ){ - const double y = frame && options_screen.detect(frame) ? position.selected_row(frame) : -1; - const bool value_visible = y >= 0 && position.selected_value(frame, y); + const double y = frame && screen.options_screen.detect(frame) ? screen.position.selected_row(frame) : -1; + const bool value_visible = y >= 0 && screen.position.selected_value(frame, y); + if (!label_reference){ + stream.log("[Tutorial settings] Expected row=" + std::string(row.label) + + " row_y=" + std::to_string(y) + " highlighted_value=" + std::to_string(value_visible) + + " (no label image for the game language)"); + return y >= 0 && value_visible ? y : -1; + } const double label_score = y >= 0 ? option_image_score(frame, - {0.08, y - 0.025, 0.24, 0.05}, label_reference, false) : 0; - stream.log("[Tutorial settings] Expected row=" + std::string(SETTINGS[row].label) + + {0.08, y - 0.025, 0.24, 0.05}, *label_reference, false) : 0; + stream.log("[Tutorial settings] Expected row=" + std::string(row.label) + " row_y=" + std::to_string(y) + " highlighted_value=" + std::to_string(value_visible) + " label_match=" + std::to_string(label_score)); return y >= 0 && value_visible && label_score >= 0.80 ? y : -1; } +// Whether the selected row (at `y`) shows the target value by its column: +// the check for a game language without the rows' images. +bool option_column_verified( + VideoStream& stream, const ImageViewRGB32& frame, double y, const OptionsRow& row, + const TutorialOptionPositionDetector& position +){ + if (!row.column){ + // The Change Window arrow picker: its value has no column; the + // story keeps the new game's Type 1. + stream.log("[Tutorial settings] " + std::string(row.label) + " kept as it is (no column to check)."); + return true; + } + const std::optional x = position.selected_value_x(frame, y); + const std::optional column = x ? detail::options_value_column(*x, row.columns) : std::nullopt; + stream.log("[Tutorial settings] " + std::string(row.label) + " selected column=" + + (column ? std::to_string(*column) : "none") + " target=" + std::to_string(*row.column)); + return column == row.column; +} + // Whether the selected row (at `y`) shows the target value: checked on // the frame, with the row's boxes on the overlay. bool option_verified( - VideoStream& stream, ProControllerContext& context, const ImageViewRGB32& frame, double y, size_t row, + VideoStream& stream, ProControllerContext& context, const ImageViewRGB32& frame, double y, const OptionsRow& row, const OptionsScreen& screen, const OptionReferences& references ){ - const ImageRGB32& value_reference = references.value; + const bool autosave = row.label == "autosave"; // These are regular video-overlay boxes, so the existing overlay // display control can show/hide every active ROI. OverlayBoxScope row_overlay(stream.overlay(), COLOR_RED, {0.07, y - 0.04, 0.84, 0.08}, ""); OverlayBoxScope label_overlay(stream.overlay(), COLOR_YELLOW, {0.08, y - 0.025, 0.24, 0.05}, ""); OverlayBoxScope value_overlay(stream.overlay(), COLOR_GREEN, {0.33, y - 0.025, 0.54, 0.05}, ""); VideoOverlaySet autosave_rois(stream.overlay()); - if (row == AUTOSAVE_ROW){ + if (autosave){ autosave_rois.add(COLOR_GREEN, {0.63, y - 0.022, 0.055, 0.044}); autosave_rois.add(COLOR_RED, {0.34, y - 0.022, 0.055, 0.044}); } - const double score = option_value_score(frame, y, row, value_reference); - stream.log("[Tutorial settings] " + std::string(SETTINGS[row].label) + " target match=" + std::to_string(score)); - // The reference recording uses inactive pale-red text; the focused live - // row has a thicker dark-red glyph mask. Verified Fast scores 0.734 - // while Slow/Normal score 0. - if (score < 0.65 || (row == AUTOSAVE_ROW && !autosave_off_highlight(frame, y))){ + if (references.value){ + const double score = option_value_score(frame, y, row, *references.value); + stream.log("[Tutorial settings] " + std::string(row.label) + " target match=" + std::to_string(score)); + // The reference recording uses inactive pale-red text; the focused live + // row has a thicker dark-red glyph mask. Verified Fast scores 0.734 + // while Slow/Normal score 0. + if (score < 0.65){ + return false; + } + }else if (!option_column_verified(stream, frame, y, row, screen.position)){ + return false; + } + if (autosave && !autosave_off_highlight(frame, y)){ return false; } - if (row == AUTOSAVE_ROW){ + if (autosave){ confirm_autosave_off(stream, context, screen.options_screen, screen.position, references.label); } return true; } -// Sets the option on `row`, the row selected now, to its target value. -void set_option(VideoStream& stream, ProControllerContext& context, size_t row, const OptionsScreen& screen){ - const std::string base = RESOURCE_PATH() + "PokemonBDSP/Autostory/Options/" + SETTINGS[row].label; - const OptionReferences references{ImageRGB32(base + "_label.png"), ImageRGB32(base + "_value.png")}; +// The reference images `row` is checked with in a layout: label and value +// with label images, else only a slider's number. +OptionReferences option_references(const OptionsRow& row, bool label_images){ + const std::string base = RESOURCE_PATH() + "PokemonBDSP/Autostory/Options/" + std::string(row.label); + OptionReferences references; + if (label_images){ + references.label.emplace(base + "_label.png"); + } + if (label_images || row.slider){ + references.value.emplace(base + "_value.png"); + } + return references; +} + +// Sets the option on `row`, the row selected now, to its target value; a +// row without a value is only confirmed selected. +void set_option(VideoStream& stream, ProControllerContext& context, const OptionsRow& row, bool label_images, const OptionsScreen& screen){ + const OptionReferences references = option_references(row, label_images); bool slider_reset = false; for (size_t attempt = 0; attempt < 30; attempt++){ // Detect the selected row afresh after every navigation/correction. context.wait_for_all_requests(); auto frame = stream.video().snapshot(); - const double y = expected_row_y(stream, frame, screen.options_screen, screen.position, row, references.label); + const double y = expected_row_y(stream, frame, screen, row, references.label); if (y < 0){ // A menu can be detected while its row/text is still fading // in. Re-read without directional inputs first. @@ -368,17 +465,21 @@ void set_option(VideoStream& stream, ProControllerContext& context, size_t row, continue; } OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, - "Settings checkpoint: Unable to confirm expected row " + std::string(SETTINGS[row].label), stream); + "Settings checkpoint: Unable to confirm expected row " + std::string(row.label), stream); + } + if (row.value.empty()){ + stream.log("[Tutorial settings] Left " + std::string(row.label) + " as it is."); + return; } if (option_verified(stream, context, frame, y, row, screen, references)){ - stream.log("[Tutorial settings] Verified " + std::string(SETTINGS[row].label) + "=" + SETTINGS[row].value); + stream.log("[Tutorial settings] Verified " + std::string(row.label) + "=" + std::string(row.value)); return; } - stream.log("[Tutorial settings] Correcting " + std::string(SETTINGS[row].label)); + stream.log("[Tutorial settings] Correcting " + std::string(row.label)); correct_option(context, row, slider_reset); } OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, - "Settings checkpoint: Could not apply " + std::string(SETTINGS[row].label), stream); + "Settings checkpoint: Could not apply " + std::string(row.label), stream); } // Confirms the settings and leaves Options (A A A A B B), back to the overworld. @@ -427,16 +528,20 @@ void reopen_options(VideoStream& stream, ProControllerContext& context, const Tu } // In the saved Options: Autosave is Off on three frames. Options starts -// on Text Speed; Autosave is seven rows below it. +// on Text Speed; Autosave is the layout's rows below it. void check_saved_autosave( - VideoStream& stream, ProControllerContext& context, + VideoStream& stream, ProControllerContext& context, const OptionsLayout& layout, const TutorialOptionsDetector& options_screen, const TutorialOptionPositionDetector& position ){ - for (size_t step = 0; step < AUTOSAVE_ROW; step++){ + size_t autosave_row = 0; + while (autosave_row < layout.rows.size() && layout.rows[autosave_row].label != "autosave"){ + autosave_row++; + } + for (size_t step = 0; step < autosave_row; step++){ pbf_press_dpad(context, DPAD_DOWN, 80ms, 350ms); } context.wait_for_all_requests(); - const ImageRGB32 autosave_label(RESOURCE_PATH() + "PokemonBDSP/Autostory/Options/autosave_label.png"); + const std::optional autosave_label = option_references(layout.rows[autosave_row], layout.label_images).label; for (size_t confirmation = 0; confirmation < 3; confirmation++){ auto check = stream.video().snapshot(); if (!autosave_off_on_screen(check, options_screen, position, autosave_label)){ @@ -453,9 +558,10 @@ void verify_tutorial_settings_once(VideoStream& stream, ProControllerContext& co open_main_menu(stream, context); OptionsScreen screen; open_options(stream, context, screen.options_screen); - for (size_t row = 0; row < SETTING_COUNT; row++){ - set_option(stream, context, row, screen); - if (row + 1 < SETTING_COUNT){ + const OptionsLayout layout = detail::options_layout(story_language()); + for (size_t row = 0; row < layout.rows.size(); row++){ + set_option(stream, context, layout.rows[row], layout.label_images, screen); + if (row + 1 < layout.rows.size()){ pbf_press_dpad(context, DPAD_DOWN, 80ms, 350ms); } } @@ -463,7 +569,7 @@ void verify_tutorial_settings_once(VideoStream& stream, ProControllerContext& co // Reopen the saved Options screen and independently verify Autosave. // No route movement is permitted until this persisted-value check passes. reopen_options(stream, context, screen.options_screen); - check_saved_autosave(stream, context, screen.options_screen, screen.position); + check_saved_autosave(stream, context, layout, screen.options_screen, screen.position); save_options(stream, context, "Autosave verification: Could not return to the overworld."); // Report inferred values explicitly: these are visual matches, // allowing the user to compare our conclusions with the screen. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h index 206237de07..61dd9df88c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Settings.h @@ -9,6 +9,10 @@ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_Settings_H #define PokemonAutomation_PokemonBDSP_AutoStory_Settings_H +#include +#include +#include +#include "CommonFramework/Language.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -24,6 +28,38 @@ namespace PokemonBDSP{ void verify_tutorial_settings(VideoStream& stream, ProControllerContext& context); +namespace detail{ + +// One row of the Options list, as the story sets it. +struct OptionsRow{ + // The reference images' name: