diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 1262007a8a..e79d72c70a 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -247,9 +247,9 @@ jobs: with: # The fork's fixtures: upstream's plus the PLZA AutoStory frames (Confirm Choices, opening and arrival folders), dayfine/CommandLineTests PR #18, # and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language), - # and the 01.02 choice menu and talk prompt in Italian (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro), and the 03.02b battle frame with no lock-on and Map & Missions card (branch plza/battle-panel). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '848e0b03a03d9cdca580f21f3389486478d52f4d' + ref: '0414d97e16f77d6405d7f456147007ae317b1e72' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 8a8f6e1600..c56d3cd958 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -32,6 +32,7 @@ #include "NintendoSwitch/Inference/NintendoSwitch_CheckOnlineDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_FailedToConnectDetector.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h" #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" @@ -82,6 +83,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ add_tests_ScreenMachine(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); + NintendoSwitch::add_tests_SystemKeyboardDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); NintendoSwitch::PokemonBDSP::add_tests_DialogDetector(ret); diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp new file mode 100644 index 0000000000..b08bee33a4 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp @@ -0,0 +1,280 @@ +/* System Keyboard Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "Tests/ImageUnitTest.h" +#include "NintendoSwitch_SystemKeyboardDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + +namespace{ + +// Centres of the five rows of keys, and of the first column and the spacing +// between columns, as fractions of the screen. +constexpr double KEY_ROW_Y[] = {0.500, 0.593, 0.681, 0.770, 0.858}; +constexpr double KEY_COL_X0 = 0.077; +constexpr double KEY_COL_STEP = 0.075; + +// In the right column, Return spans rows 1-2 and OK rows 3-4. These are the +// gaps between those keys. +constexpr double RIGHT_COLUMN_RETURN_TOP = 0.548; +constexpr double RIGHT_COLUMN_OK_TOP = 0.725; + +// The cursor border and everything else the reader looks at, from the top of the +// digit row to the bottom of the bottom row. +const ImageFloatBox KEYS_AREA(0.0, 0.43, 1.0, 0.49); + +// The cursor border pulses between bright cyan (about 50, 240, 220) and a darker +// teal (about 0, 185, 210), measured on Legends: Z-A. The blue of the OK button +// and of the ABC underline (40, 90, 250) is not green enough to match. +bool is_cursor_pixel(uint32_t pixel){ + const int red = (pixel >> 16) & 0xff; + const int green = (pixel >> 8) & 0xff; + const int blue = pixel & 0xff; + return red < 130 && green > 160 && blue > 170 && green - red > 60; +} + +uint8_t nearest_row(double y){ + uint8_t row = 0; + for (uint8_t r = 1; r < 5; r++){ + if (std::abs(KEY_ROW_Y[r] - y) < std::abs(KEY_ROW_Y[row] - y)){ + row = r; + } + } + return row; +} + +// The key whose cursor border has its centre at (x, y), or nothing if that is +// off the keyboard. +std::optional key_at(double x, double y){ + const long col = std::lround((x - KEY_COL_X0) / KEY_COL_STEP); + if (col < 0 || col > 11){ + return std::nullopt; + } + if (col < 11){ + return SystemKeyboardKey{nearest_row(y), (uint8_t)col}; + } + if (y < RIGHT_COLUMN_RETURN_TOP){ + return SystemKeyboardKey{0, 11}; + } + if (y < RIGHT_COLUMN_OK_TOP){ + return SystemKeyboardKey{1, 11}; + } + return SystemKeyboardKey{3, 11}; +} + +} // namespace + + + +SystemKeyboardDetector::SystemKeyboardDetector(Color color) + : m_color(color) + , m_key_panel_upper(0.15, 0.532, 0.65, 0.036) + , m_key_panel_lower(0.15, 0.715, 0.65, 0.032) + , m_bottom_bar(0.10, 0.935, 0.35, 0.030) + , m_ok_button(0.875, 0.760, 0.045, 0.020) +{} +void SystemKeyboardDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_key_panel_upper); + items.add(m_color, m_key_panel_lower); + items.add(m_color, m_bottom_bar); + items.add(m_color, m_ok_button); +} +bool SystemKeyboardDetector::detect(const ImageViewRGB32& screen){ + // Each strip crosses white keys and the slightly brighter gaps between them, + // which gives a stddev sum of about 11 (measured on BDSP and Legends: Z-A). + const double max_panel_stddev = 20; + const bool panel = + is_white(extract_box_reference(screen, m_key_panel_upper), 500, max_panel_stddev) || + is_white(extract_box_reference(screen, m_key_panel_lower), 500, max_panel_stddev); + if (!panel || !is_white(extract_box_reference(screen, m_bottom_bar))){ + return false; + } + // OK is blue (40, 93, 255), or flat grey (221, 221, 221) while the field is + // empty (disabled). Measured on BDSP and Legends: Z-A. + const ImageStats ok = image_stats(extract_box_reference(screen, m_ok_button)); + return is_solid(ok, {0.103, 0.240, 0.657}) || is_grey(ok, 600, 690); +} + + +std::optional read_system_keyboard_cursor(const ImageViewRGB32& screen){ + // The cursor is a cyan border around one key. Neighbouring keys overlap that border, + // so take the centroid of all cyan pixels and map it to the nearest key. + const ImageViewRGB32 keys = extract_box_reference(screen, KEYS_AREA); + double count = 0, sum_x = 0, sum_y = 0; + for (size_t y = 0; y < keys.height(); y++){ + for (size_t x = 0; x < keys.width(); x++){ + if (is_cursor_pixel(keys.pixel(x, y))){ + count++; + sum_x += (double)x; + sum_y += (double)y; + } + } + } + // The border is about 0.18% of the screen; a few stray pixels are not a cursor. + if (count < 0.0005 * screen.width() * screen.height()){ + return std::nullopt; + } + return key_at( + KEYS_AREA.x + sum_x / count / keys.width() * KEYS_AREA.width, + KEYS_AREA.y + sum_y / count / keys.height() * KEYS_AREA.height + ); +} + +bool system_keyboard_field_has_text(const ImageViewRGB32& screen){ + // Left part of the backspace key, clear of its icon and of the cursor border. + // Light grey (221) with an empty field, dark grey (52) with text. + const ImageStats stats = image_stats(extract_box_reference(screen, ImageFloatBox(0.878, 0.470, 0.008, 0.060))); + return stats.average.sum() < 400; +} + +size_t system_keyboard_text_pixels(const ImageViewRGB32& screen){ + // The field, above its underline, which is white in some games. + const ImageViewRGB32 field = extract_box_reference(screen, ImageFloatBox(0.03, 0.17, 0.87, 0.105)); + size_t count = 0; + for (size_t y = 0; y < field.height(); y++){ + for (size_t x = 0; x < field.width(); x++){ + const uint32_t pixel = field.pixel(x, y); + if (((pixel >> 16) & 0xff) > 190 && ((pixel >> 8) & 0xff) > 190 && (pixel & 0xff) > 190){ + count++; + } + } + } + return count; +} + + + +namespace{ + +// One screenshot and what each function should read from it. +class Test_SystemKeyboardDetector : public ImageUnitTest{ +public: + // `cursor`: the key under the cursor, or nothing for a screen without the keyboard. + Test_SystemKeyboardDetector(const std::string& image, std::optional cursor, bool has_text) + : ImageUnitTest(std::format("NintendoSwitch::SystemKeyboardDetector - {}", image), {image}) + , m_cursor(cursor) + , m_has_text(has_text) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const ImageRGB32& image = images[0]; + const bool keyboard = SystemKeyboardDetector().detect(image); + if (keyboard != m_cursor.has_value()){ + return std::format("detect() returned {}.", keyboard); + } + if (!keyboard){ + return true; + } + const std::optional cursor = read_system_keyboard_cursor(image); + if (cursor != m_cursor){ + return cursor + ? std::format("Read the cursor at ({}, {}).", cursor->row, cursor->col) + : std::format("Read no cursor."); + } + const bool has_text = system_keyboard_field_has_text(image); + if (has_text != m_has_text){ + return std::format("system_keyboard_field_has_text() returned {}.", has_text); + } + // An empty field has no white text pixels; one typed character has many. + const size_t text_pixels = system_keyboard_text_pixels(image); + if ((text_pixels >= 20) != m_has_text){ + return std::format("system_keyboard_text_pixels() returned {}.", text_pixels); + } + return true; + } + +private: + std::optional m_cursor; + bool m_has_text; +}; + +std::string test_image_path(std::string_view image){ + return std::format("NintendoSwitch/SystemKeyboardDetector/{}", image); +} + +// The cursor on keys other than "1". +void add_cursor_tests(UnitTestDatabase& database){ + // Legends: Z-A, English and Spanish prompts. The + // border pulses between bright cyan and a darker teal; T, / and ! are dark. + const std::pair cursors[] = { + {"PLZA-Cursor-T.png", {1, 4}}, + {"PLZA-Cursor-Slash.png", {1, 10}}, + {"PLZA-Cursor-Exclamation.png", {3, 10}}, + {"PLZA-Cursor-0.png", {0, 9}}, + {"PLZA-Cursor-Minus.png", {0, 10}}, + {"PLZA-Cursor-Backspace.png", {0, 11}}, + {"PLZA-Cursor-Return.png", {1, 11}}, + {"PLZA-Cursor-OK.png", {3, 11}}, + {"PLZA-Cursor-Globe.png", {4, 0}}, + {"PLZA-Cursor-NTilde.png", {4, 5}}, + {"PLZA-Cursor-Space.png", {4, 8}}, + }; + for (const auto& [image, cursor] : cursors){ + database.add(test_image_path(image), cursor, false); + } +} + +// Tests whose screen is not captured yet. +void add_planned_tests(UnitTestDatabase& database){ + const SystemKeyboardKey key_1{0, 0}; + // Screens still to be captured: AZERTY needs a console whose system language + // uses it (the layout follows the system, not the game). Each test is added + // once its image is in the test repo. + struct Planned{ + std::string_view image; + std::optional cursor; + bool has_text; + }; + const Planned planned[] = { + {"AZERTY-Empty.png", key_1, false}, + {"PLZA-Korean.png", std::nullopt, false}, + }; + for (const Planned& test : planned){ + const std::string image = test_image_path(test.image); + if (Filesystem::exists(std::format("{}{}", UNIT_TEST_RESOURCE_PATH(), image))){ + database.add(image, test.cursor, test.has_text); + } + } +} + +} // namespace + + +void add_tests_SystemKeyboardDetector(UnitTestDatabase& database){ + const SystemKeyboardKey key_1{0, 0}; + // The OK button is blue with text in the field and grey without. + database.add(test_image_path("BDSP-PlayerName-Empty.png"), key_1, false); + database.add(test_image_path("BDSP-FriendName-Typed.png"), key_1, true); + for (std::string_view language : {"English", "French", "German", "Italian", "Japanese", "Spanish"}){ + database.add(test_image_path(std::format("PLZA-{}-Empty.png", language)), key_1, false); + } + for (std::string_view image : {"BDSP-Dialog.png", "HomeMenu.png", "HomeMenu-OnlineLicensePopup.png", "UserSelect.png"}){ + database.add(test_image_path(image), std::nullopt, false); + } + add_cursor_tests(database); + add_planned_tests(database); +} + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h new file mode 100644 index 0000000000..3a5bbf7f03 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h @@ -0,0 +1,99 @@ +/* System Keyboard Detector + * + * From: https://github.com/PokemonAutomation/ + * + * The Switch's own on-screen keyboard, which games open for names (e.g. the + * player's name in BDSP and in Legends: Z-A): detect it, read the key under its + * cursor, and tell whether its text field is empty. Typing with it is in + * Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h. + * + * Supported: the Latin keyboard (QWERTY; AZERTY shares the key grid but has no + * test screenshot yet). Its layout follows the console's system language, not + * the game's. Measured on 1920x1080 Switch 1 captures of BDSP's and Legends: + * Z-A's name entry, the latter with the game in English, Spanish, German, + * Italian, French and Japanese (all QWERTY on an English console). Not + * supported: the Korean keyboard, whose candidate strip + * moves the keys down (the detector returns false on it), and probably the + * Chinese ones (not tested). Switch 2 is not tested. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_SystemKeyboardDetector_H +#define PokemonAutomation_NintendoSwitch_SystemKeyboardDetector_H + +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +// The white key panel, the white bar below it, and the OK button (blue, or grey +// while the field is empty). Works wherever the cursor is. +class SystemKeyboardDetector : public StaticScreenDetector{ +public: + SystemKeyboardDetector(Color color = COLOR_CYAN); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + // Two strips across the key panel, one over the gap between rows 0 and 1 and + // one over the gap between rows 2 and 3. The cursor's border reaches into at + // most one of them, so the panel is white if either is. + ImageFloatBox m_key_panel_upper; + ImageFloatBox m_key_panel_lower; + ImageFloatBox m_bottom_bar; + ImageFloatBox m_ok_button; +}; + +// Finds SystemKeyboardDetector on the video, checking every 250 ms. +class SystemKeyboardWatcher : public DetectorToFinder{ +public: + SystemKeyboardWatcher(Color color = COLOR_CYAN) + : DetectorToFinder("SystemKeyboardWatcher", std::chrono::milliseconds(250), color) + {} +}; + + +// A key of the keyboard. +// Rows 0-3 are the character rows (0: digits .. 3: "zxcv"), row 4 is the bottom +// row (globe, Shift, ABC, #+=, the accent pages and Space). +// Columns 0-10 are the character columns. Column 11 is the right column, whose +// keys are taller: backspace is (0, 11), Return (1, 11) and OK (3, 11). +// A row-4 key reports the character column nearest its centre (Space: 8). +struct SystemKeyboardKey{ + uint8_t row; + uint8_t col; + + bool operator==(const SystemKeyboardKey&) const = default; +}; + +// The key under the cursor, or nothing if no cursor border is visible. +// The keyboard remembers the cursor between uses, so read it, don't assume it. +std::optional read_system_keyboard_cursor(const ImageViewRGB32& screen); + +// Whether the text field holds any text: the backspace key is dark then and light +// grey while the field is empty. Pressing B on an empty field closes the +// keyboard, so delete only while this is true. +bool system_keyboard_field_has_text(const ImageViewRGB32& screen); + +// The number of white pixels in the text field. Each typed character adds some +// (a "1" adds about 110 at 1920x1080), so comparing two counts tells whether a +// key press reached the field. +size_t system_keyboard_text_pixels(const ImageViewRGB32& screen); + + + +// Register the tests of this file. +void add_tests_SystemKeyboardDetector(UnitTestDatabase& database); + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h index 7048582ea0..1aa290cdc1 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h @@ -8,10 +8,12 @@ #define PokemonAutomation_NintendoSwitch_KeyboardCodeEntry_H #include +#include #include "Controllers/StandardHid/StandardHid_Keyboard.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -19,6 +21,13 @@ namespace FastCodeEntry{ +// The D-pad moves from "source" to "destination" on the on-screen keyboard, +// wrapping around the sides when that is shorter, then ENTER_CHAR. +std::vector keyboard_get_path( + KeyboardEntryPosition source, + KeyboardEntryPosition destination +); + // Automatically select between keyboard or pro controller depending on the // controller type. void keyboard_enter_code( diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp new file mode 100644 index 0000000000..511e36ecad --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp @@ -0,0 +1,249 @@ +/* System Keyboard Typing + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" +#include "NintendoSwitch_SystemKeyboardTyping.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace FastCodeEntry{ + +using namespace std::chrono_literals; + + +namespace{ + +// Waits after each press. They are longer than the code entry delays because +// the next step reads the screen: the cursor animation and the capture latency +// must be over first. +constexpr Milliseconds MOVE_RELEASE = 200ms; +constexpr Milliseconds WRAP_RELEASE = 400ms; // Wrapping around a side animates for longer. +constexpr Milliseconds SETTLE = 300ms; // Before reading the cursor after moving it. +constexpr Milliseconds SHIFT_RELEASE = 250ms; +constexpr Milliseconds KEY_RELEASE = 300ms; + +// A press made while the keyboard is still sliding in is ignored, so the +// cursor is read again after each try until it is on the target. +constexpr size_t MAX_MOVE_TRIES = 10; + +// Reads of the text field after a key press, SETTLE apart, before giving up. +constexpr size_t MAX_FIELD_READS = 3; + +// The fewest white pixels a typed character adds to the field ("." or "'"). +constexpr size_t MIN_CHARACTER_PIXELS = 10; + + +// The key of each character of `text`. Throws UserSetupError, listing every +// character that has no key, before anything is typed. +std::vector text_keys(Logger& logger, const std::string& text, KeyboardLayout layout){ + const std::map& positions = KEYBOARD_POSITIONS(layout); + std::vector keys; + std::string missing; + for (char ch : text){ + // Letters are listed under their uppercase key. + auto iter = positions.find((char)std::toupper((unsigned char)ch)); + if (iter == positions.end()){ + missing += ch; + }else{ + keys.emplace_back(iter->second); + } + } + if (!missing.empty()){ + throw UserSetupError( + logger, + std::format("System keyboard: \"{}\" has characters with no key on the keyboard: \"{}\".", text, missing) + ); + } + return keys; +} + +// How long to hold each button: the hold of the code entry timings for Switch 1. +Milliseconds button_hold(ProControllerContext& context){ + const ConsoleSettings& settings = ConsoleSettings::instance(); + const CodeEntryDelays delays = context->performance_class() == ControllerPerformanceClass::SerialPABotBase_Wired + ? CodeEntryDelays(settings.CODEBOARD_ENTRY_SWITCH1_WIRED) + : CodeEntryDelays(settings.CODEBOARD_ENTRY_SWITCH1_WIRELESS); + return delays.hold; +} + +// The D-pad direction of a move. +DpadPosition move_direction(CodeEntryAction action){ + switch (action){ + case CodeEntryAction::NORM_MOVE_UP: + case CodeEntryAction::WRAP_MOVE_UP: + return DpadPosition::DPAD_UP; + case CodeEntryAction::NORM_MOVE_RIGHT: + case CodeEntryAction::WRAP_MOVE_RIGHT: + return DpadPosition::DPAD_RIGHT; + case CodeEntryAction::NORM_MOVE_DOWN: + case CodeEntryAction::WRAP_MOVE_DOWN: + return DpadPosition::DPAD_DOWN; + case CodeEntryAction::NORM_MOVE_LEFT: + case CodeEntryAction::WRAP_MOVE_LEFT: + return DpadPosition::DPAD_LEFT; + default: + return DpadPosition::DPAD_NONE; + } +} + +// The moves toward `target`. Off the character grid (the right column or the +// bottom row), one step back onto it, after which the cursor is read again. +std::vector path_toward(SystemKeyboardKey cursor, KeyboardEntryPosition target){ + if (cursor.col == 11){ + return {CodeEntryAction::NORM_MOVE_LEFT}; + } + if (cursor.row == 4){ + return {CodeEntryAction::NORM_MOVE_UP}; + } + std::vector path = keyboard_get_path({cursor.row, cursor.col}, target); + std::erase_if(path, [](CodeEntryAction action){ return !is_move(action); }); + return path; +} + +// The moves as letters for the log, e.g. "DLL" or "R*" for a wrap to the right. +std::string path_to_string(const std::vector& path){ + std::string ret; + for (CodeEntryAction action : path){ + switch (move_direction(action)){ + case DpadPosition::DPAD_UP: + ret += 'U'; + break; + case DpadPosition::DPAD_RIGHT: + ret += 'R'; + break; + case DpadPosition::DPAD_DOWN: + ret += 'D'; + break; + case DpadPosition::DPAD_LEFT: + ret += 'L'; + break; + default: + ret += '?'; + break; + } + if (is_wrap(action)){ + ret += '*'; + } + } + return ret; +} + +std::optional read_cursor(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = stream.video().snapshot(); + if (!screen){ + return std::nullopt; + } + return read_system_keyboard_cursor(screen); +} + +[[noreturn]] void throw_cursor_failure( + VideoStream& stream, + std::optional last, KeyboardEntryPosition target, char ch +){ + std::string message = last + ? std::format("the cursor is at ({}, {}), not on '{}' at ({}, {})", last->row, last->col, ch, target.row, target.col) + : std::format("the cursor could not be read while moving to '{}' at ({}, {})", ch, target.row, target.col); + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("System keyboard: {}, after {} tries.", message, MAX_MOVE_TRIES), + stream + ); +} + +void move_cursor( + VideoStream& stream, ProControllerContext& context, Milliseconds hold, + KeyboardEntryPosition target, char ch +){ + std::optional last; + for (size_t attempt = 0; attempt < MAX_MOVE_TRIES; attempt++){ + const std::optional cursor = read_cursor(stream, context); + if (!cursor){ + stream.logger().log(std::format("System keyboard: no cursor seen, try {}.", attempt + 1)); + pbf_wait(context, SETTLE); + continue; + } + last = cursor; + if (cursor->row == target.row && cursor->col == target.col){ + return; + } + const std::vector path = path_toward(*cursor, target); + stream.logger().log(std::format( + "System keyboard: cursor ({}, {}) -> '{}' ({}, {}): {}, try {}.", + cursor->row, cursor->col, ch, target.row, target.col, path_to_string(path), attempt + 1 + )); + for (CodeEntryAction action : path){ + pbf_press_dpad(context, move_direction(action), hold, is_wrap(action) ? WRAP_RELEASE : MOVE_RELEASE); + } + pbf_wait(context, SETTLE); + } + throw_cursor_failure(stream, last, target, ch); +} + +size_t read_text_pixels(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = stream.video().snapshot(); + return screen ? system_keyboard_text_pixels(screen) : 0; +} + +// Types `ch` with the cursor on its key, and checks that the text field grew. +void press_key(VideoStream& stream, ProControllerContext& context, Milliseconds hold, char ch){ + const size_t before = read_text_pixels(stream, context); + if (std::isupper((unsigned char)ch)){ + pbf_press_button(context, BUTTON_LCLICK, hold, SHIFT_RELEASE); + } + pbf_press_button(context, BUTTON_A, hold, KEY_RELEASE); + size_t after = 0; + for (size_t read = 0; read < MAX_FIELD_READS; read++){ + after = read_text_pixels(stream, context); + if (after >= before + MIN_CHARACTER_PIXELS){ + return; + } + pbf_wait(context, SETTLE); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("System keyboard: pressed '{}', but the text field did not change ({} -> {} white pixels).", ch, before, after), + stream + ); +} + +} // namespace + + + +void type_on_system_keyboard( + VideoStream& stream, ProControllerContext& context, + const std::string& text, + KeyboardLayout layout +){ + const std::vector keys = text_keys(stream.logger(), text, layout); + const Milliseconds hold = button_hold(context); + for (size_t c = 0; c < text.size(); c++){ + move_cursor(stream, context, hold, keys[c], text[c]); + press_key(stream, context, hold, text[c]); + } + context.wait_for_all_requests(); +} + + + +} // namespace FastCodeEntry +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h new file mode 100644 index 0000000000..3d2e2dcc2f --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h @@ -0,0 +1,56 @@ +/* System Keyboard Typing + * + * From: https://github.com/PokemonAutomation/ + * + * Types text on the Switch's on-screen keyboard with a Pro Controller, reading + * the cursor from the video before each key. Unlike keyboard_enter_code(), + * which moves blind from an assumed starting key, it starts wherever the + * keyboard left its cursor and corrects moves the keyboard ignored. + * + * Supported keyboards are those of NintendoSwitch_SystemKeyboardDetector.h: the + * Latin keyboard, QWERTY or AZERTY. Console-tested on Switch 1 (2026-11-13): + * the player's name in Legends: Z-A with the game in English, Spanish, German, + * Italian, French and Japanese (QWERTY, English system language), and earlier + * the player's and rival's names in BDSP. AZERTY is not tested. Not + * supported: the Korean and Chinese keyboards. Switch 2 is not tested. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_SystemKeyboardTyping_H +#define PokemonAutomation_NintendoSwitch_SystemKeyboardTyping_H + +#include +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace FastCodeEntry{ + + +// Types `text` on the open keyboard: letters, digits and the symbols on the +// keyboard's first page. An uppercase letter is typed with Shift (left stick +// click), which assumes the keyboard opened with Shift off, as BDSP's and +// Legends: Z-A's do. +// +// Before the first press, throws UserSetupError if `text` has a character with +// no key. While typing, throws OperationFailedException, with a screenshot, if +// the cursor can't be read or doesn't reach a key, or if a key press doesn't +// add to the text field. The check counts the field's white pixels, so it +// catches a dropped press but not a wrong case. +// +// Presses are held for the "Fast Code Entry Timings" hold of Switch 1 with the +// controller's connection type, as keyboard_enter_code() does. The waits after +// them are fixed, since each move is read back from the video. +void type_on_system_keyboard( + VideoStream& stream, ProControllerContext& context, + const std::string& text, + KeyboardLayout layout = KeyboardLayout::QWERTY +); + + +} // namespace FastCodeEntry +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 35b7bf5acc..49315b53f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -25,8 +25,11 @@ #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h" @@ -59,6 +62,9 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryConfirmChoicesReader(database); add_tests_AutoStoryCaughtMarkReader(database); add_tests_AutoStoryDialogDetector(database); + add_tests_AutoStoryIntroScreens(database); + add_tests_AutoStoryLaunch(database); + add_tests_AutoStoryNewGame(database); add_tests_AutoStoryGame(database); add_tests_AutoStoryLines(database); add_tests_AutoStoryObjectiveMarkerReader(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp index 7baab9c8f5..e1cbe67eae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp @@ -11,8 +11,10 @@ #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/OCR/OCR_Routines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryConfirmChoices.h" namespace PokemonAutomation{ @@ -43,6 +45,38 @@ std::optional read_confirm_choices_now( } } +// Fails, having pressed nothing, unless "Confirm Choices" shows the name +// and the language of `choices`. +void check_profile(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (!frame){ + return; + } + const std::string name = read_confirm_choices_name(frame); + if (name != choices.name){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: Confirm Choices shows the name \"{}\", not \"{}\". Nothing was confirmed.", name, choices.name), + console + ); + } + const NewGameLanguageInfo& info = new_game_language_info(choices.language); + if (!OCR::ocr_language_available(info.ocr_language)){ + console.log(std::format("AutoStory intro: Confirm Choices: no OCR for {}; its language is not checked.", info.tag)); + return; + } + const std::string language = read_confirm_choices_language(frame, info.ocr_language); + if (language.find(info.confirm_text) == std::string::npos){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: Confirm Choices shows the language \"{}\", not {}. Nothing was confirmed.", language, info.tag), + console + ); + } + console.log(std::format("AutoStory intro: Confirm Choices shows \"{}\" in {}.", name, info.tag)); +} + } // namespace @@ -51,16 +85,17 @@ size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& con if (!cursor){ throw UserSetupError( console, - "AutoStory: 01.00 starts on the new game's \"Confirm Choices\" screen, with the language, look and name " - "already chosen by hand. It is not on screen; nothing was pressed." + "AutoStory: 01.00's confirm step needs the new game's \"Confirm Choices\" screen, after the language, look " + "and name. It is not on screen; nothing was pressed." ); } console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); return *cursor; } -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ std::optional cursor = require_confirm_choices(console, context); + check_profile(console, context, choices); for (size_t press = 0; press < 6 && cursor; press++){ if (*cursor == CONFIRM_CHOICES_READY_ROW){ console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h index e9c40d6812..ca01ea911e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h @@ -2,8 +2,8 @@ * * From: https://github.com/PokemonAutomation/ * - * 01.00's start: the new game's "Confirm Choices" screen, after the - * language, look and name were chosen by hand. Its reader is in + * The new game's "Confirm Choices" screen, after the language, look and + * name (PokemonLZA_AutoStoryNewGame.h). Its reader is in * Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h. * */ @@ -14,6 +14,7 @@ #include #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -24,14 +25,16 @@ namespace PokemonLZA{ // 2 s with no press. Throws UserSetupError if the screen does not show. size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context); -// 01.00's first step: the new game's language, look and name were chosen -// by hand and "Confirm Choices" is on screen. Checks that screen first -// (require_confirm_choices()): on any other screen throws UserSetupError -// and presses nothing. Then moves the highlight to "Ready!" one DOWN at a -// time, reading it after each, and presses A there: the save's only -// change is this press, on a screen it has read. Throws +// 01.00's step after the intro: "Confirm Choices" is on screen. Checks +// that screen first (require_confirm_choices()): on any other screen +// throws UserSetupError and presses nothing. Then reads the name and the +// language it shows (OCR) and, if either is not `choices`', throws +// OperationFailedException having pressed nothing (the language is not +// checked when its OCR is not installed). Then moves the highlight to +// "Ready!" one DOWN at a time, reading it after each, and presses A there: +// the save's only change is this press, on a screen it has read. Throws // OperationFailedException if the highlight is lost on the way. -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp new file mode 100644 index 0000000000..d29703a693 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -0,0 +1,84 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr Milliseconds HOME_TILE_RELEASE = 500ms; + +// The highlighted HOME tile is PLZA's; false without a frame. +bool highlighted_tile_is_plza(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + return frame && is_home_tile_plza(frame); +} + +} // namespace + + +std::optional find_plza_tile( + const std::function& highlighted_is_plza, + const std::function& move_right +){ + for (size_t tile = 0; tile < HOME_TILES_SEARCHED; tile++){ + if (tile > 0){ + move_right(); + } + if (highlighted_is_plza()){ + return tile; + } + } + return std::nullopt; +} + +void launch_plza_from_home(ConsoleHandle& console, ProControllerContext& context){ + // HOME from the game or from HOME: the cursor on the first tile, the + // running game's when one runs. + go_home(console, context); + const bool first_is_plza = highlighted_tile_is_plza(console, context); + console.log(std::format( + "AutoStory launch: HOME's first tile (the running game, if any) is {}; closing it.", + first_is_plza ? "PLZA" : "another game" + )); + close_game_from_home(console, context); + + pbf_press_button(context, BUTTON_HOME, /*hold=*/160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); + const std::optional tile = find_plza_tile( + [&]{ return highlighted_tile_is_plza(console, context); }, + [&]{ pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, HOME_TILE_RELEASE); } + ); + if (!tile){ + throw UserSetupError( + console, + std::format( + "AutoStory: Pokemon Legends: Z-A is not on HOME's first {} tiles. Play it once so its tile moves to the front.", + HOME_TILES_SEARCHED + ) + ); + } + console.log(std::format("AutoStory launch: launching PLZA, HOME's tile {}.", *tile)); + // Slot 0: the cursor stays on PLZA's tile. + start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h new file mode 100644 index 0000000000..914e7dbc35 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h @@ -0,0 +1,51 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + * The one way AutoStory starts or restarts PLZA from the Switch HOME: for + * a new game, for the latest save and for capture mode. HOME's tiles are + * in last-played order, so the first tile is not always PLZA's (console B, + * 2026-11-15: FireRed's, played last, launched instead). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H + +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// How many of HOME's tiles, from the first, are searched for PLZA's. +constexpr size_t HOME_TILES_SEARCHED = 8; + +// HOME's tile search from the highlighted tile rightward: reads each tile +// with `highlighted_is_plza`, moving one tile right with `move_right` +// between reads, and returns how many moves put PLZA's tile under the +// cursor; nullopt if none of HOME_TILES_SEARCHED tiles is PLZA's. +std::optional find_plza_tile( + const std::function& highlighted_is_plza, + const std::function& move_right +); + +// From the game or HOME: goes HOME, closes the running game whichever it +// is (the first tile, the last played), selects PLZA's tile by its title +// and launches it through the user select, until the game's black screen. +// Logs whether the closed game was PLZA. Throws UserSetupError, having +// launched nothing, if PLZA's tile is not among HOME's first +// HOME_TILES_SEARCHED. +void launch_plza_from_home(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp new file mode 100644 index 0000000000..8181f656e9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp @@ -0,0 +1,122 @@ +/* PokemonLZA AutoStory - Launch Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" +#include "PokemonLZA_AutoStoryLaunch_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +std::string describe(std::optional value){ + return value ? std::format("{}", *value) : std::string("none"); +} + +// HOME as the console showed it, one frame per tile from the first: the +// search reads each frame in turn, a right move showing the next one. +struct TileSearchCase{ + std::string name; + struct Input{ + std::vector files; // Under the test images' PokemonLZA/. + // The last frame repeats past the end (HOME's row ends there). + }; + Input input; + struct Expectation{ + std::optional tile = std::nullopt; + }; + Expectation expectation; +}; + +const TileSearchCase TILE_SEARCH_CASES[] = { + { + // The 01.01 load that launched FireRed (console B, 2026-11-15): + // FireRed played last, Z-A second. + .name = "FireRed first, Z-A second", + .input = {.files = { + "AutoStoryNewGame/2026-11-15/home_firered_first.png", + "AutoStoryNewGame/2026-11-15/home_plza.png", + }}, + .expectation = {.tile = 1}, + }, + { + .name = "Z-A first", + .input = {.files = {"AutoStoryNewGame/2026-11-15/home_plza.png"}}, + .expectation = {.tile = 0}, + }, + { + .name = "no Z-A tile", + .input = {.files = {"AutoStoryNewGame/2026-11-15/home_firered.png"}}, + .expectation = {.tile = std::nullopt}, + }, +}; + +std::vector home_tile_images(const TileSearchCase& test){ + std::vector paths; + for (const std::string& file : test.input.files){ + paths.push_back(std::format("PokemonLZA/{}", file)); + } + return paths; +} + +class Test_HomeTileSearch : public ImageUnitTest{ +public: + explicit Test_HomeTileSearch(const TileSearchCase& test) + : ImageUnitTest(std::format("PokemonLZA::AutoStory - launch: HOME tile search, {}", test.name), home_tile_images(test)) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + size_t shown = 0; + size_t moves = 0; + const std::optional tile = find_plza_tile( + [&]{ + return is_home_tile_plza(images[shown]); + }, + [&]{ + moves++; + if (shown + 1 < images.size()){ + shown++; + } + } + ); + if (tile != m_test.expectation.tile){ + return std::format("Expected PLZA on tile {}, found {}.", describe(m_test.expectation.tile), describe(tile)); + } + const size_t expected_moves = tile ? *tile : HOME_TILES_SEARCHED - 1; + if (moves != expected_moves){ + return std::format("Expected {} right moves, made {}.", expected_moves, moves); + } + return true; + } + +private: + const TileSearchCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryLaunch(UnitTestDatabase& database){ + for (const TileSearchCase& test : TILE_SEARCH_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h new file mode 100644 index 0000000000..717b123506 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h @@ -0,0 +1,25 @@ +/* PokemonLZA AutoStory - Launch Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the launch's tests: HOME's tile search over console frames. +void add_tests_AutoStoryLaunch(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp index 2a10ed02c8..c79330e295 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -43,14 +43,20 @@ void play_checked(PlzaBackend& backend, std::string_view what, Input&& input){ } } +// StoryWalkStyle::HELD: L before leg `index` when it turns after an +// earlier leg. +void recenter_before_held_leg(PlzaBackend& backend, size_t index, const StoryWalkLeg& leg){ + if (index > 0 && leg.turn != 0){ + backend.press(BUTTON_L, /*hold=*/100ms, /*release=*/150ms); + } +} + // StoryWalkStyle::HELD: each leg's stick held at its angle for its time // (a turn-only leg a 150 ms tap); L before each later leg that turns. void run_held_legs(PlzaBackend& backend, const std::vector& legs){ for (size_t index = 0; index < legs.size(); index++){ const StoryWalkLeg& leg = legs[index]; - if (index > 0 && leg.turn != 0){ - backend.press(BUTTON_L, /*hold=*/100ms, /*release=*/150ms); - } + recenter_before_held_leg(backend, index, leg); if (leg.walk > 0ms){ backend.stick(leg.turn, leg.walk, /*release=*/0ms, Pokemon::StoryPace::WALK); }else if (leg.turn != 0){ @@ -96,6 +102,33 @@ Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move){ return Pokemon::outcome_ok(); } +Pokemon::Outcome run_story_move_but_last_walk(PlzaBackend& backend, const StoryMove& move){ + if (move.legs.empty()){ + return Pokemon::outcome_ok(); + } + StoryMove head = move; + if (move.style == StoryWalkStyle::HELD){ + if (move.legs.back().walk == 0ms){ + run_held_legs(backend, move.legs); + return Pokemon::outcome_ok(); + } + head.legs.pop_back(); + run_held_legs(backend, head.legs); + recenter_before_held_leg(backend, head.legs.size(), move.legs.back()); + return Pokemon::outcome_ok(); + } + head.legs.back().walk = 0ms; + return run_story_move(backend, head); +} + +void hold_last_leg(PlzaBackend& backend, const StoryMove& move, Milliseconds slice){ + if (move.style == StoryWalkStyle::HELD && !move.legs.empty()){ + backend.stick(move.legs.back().turn, slice, /*release=*/0ms, Pokemon::StoryPace::WALK); + }else{ + backend.hold(Pokemon::Direction::NORTH, slice, Pokemon::StoryPace::WALK); + } +} + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h index 434c83f5c4..ab7f79abcf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h @@ -63,6 +63,17 @@ struct StoryMove{ // that needs a prompt after the walk fails there instead. Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move); +// `move` as run_story_move() plays it, but for its last leg's walk, which +// the caller holds a slice at a time (hold_last_leg()) until what it walks +// to shows: TURN_THEN_WALK plays the last leg's turn; HELD presses L +// before the last leg when it turns after an earlier one. A HELD last leg +// with no walk is played whole, its turn a tap. +Pokemon::Outcome run_story_move_but_last_walk(PlzaBackend& backend, const StoryMove& move); + +// `slice` of `move`'s last leg's walk: the stick forward after the leg's +// turn (TURN_THEN_WALK), or at the leg's angle (HELD). +void hold_last_leg(PlzaBackend& backend, const StoryMove& move, Milliseconds slice); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp new file mode 100644 index 0000000000..70fd43e58d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp @@ -0,0 +1,448 @@ +/* PokemonLZA AutoStory - New game + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageDiff.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" +#include "PokemonLZA_AutoStoryNewGame.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +using FrameCheck = std::function; + +constexpr std::string_view DUMP_FOLDER = "PokemonLZA/AutoStory/Intro"; + +// From the user select to the language list: about 15 s of logos, with no +// press needed (the console, 2026-11-15, all ten languages). +constexpr Milliseconds LAUNCH_LIMIT = 60000ms; + +// The language list's D-pad taps: each registered at this pace (the +// console, 2026-11-15). +constexpr Milliseconds LANGUAGE_TAP_RELEASE = 600ms; + +// The look picker's stick tilts: one portrait each. +constexpr Milliseconds LOOK_TILT_HOLD = 150ms; +constexpr Milliseconds LOOK_TILT_RELEASE = 500ms; + +// The + presses after the name. One submits the European languages' and +// Japanese's keyboard; the Chinese ones first take one to accept the typed +// text (the button reads "Accept"), then one to submit. Each is checked. +constexpr size_t SUBMIT_PRESSES = 3; +constexpr Milliseconds SUBMIT_WAIT = 5000ms; + +// Capture mode: a frame this far (pixel RMSD) from the last saved one is +// a new screen. +constexpr double CAPTURE_CHANGE = 4; +constexpr Milliseconds CAPTURE_EVERY = 1000ms; + +VideoSnapshot snapshot(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + return console.video().snapshot(); +} + +// Until `check` holds on a frame, up to `timeout`, reading every 250 ms. +bool wait_for_frame(ConsoleHandle& console, ProControllerContext& context, const FrameCheck& check, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + while (true){ + const VideoSnapshot frame = snapshot(console, context); + if (frame && check(frame)){ + return true; + } + if (current_time() >= deadline){ + return false; + } + context.wait_for(250ms); + } +} + +[[noreturn]] void fail(ConsoleHandle& console, const std::string& message){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, std::format("AutoStory intro: {}", message), console); +} + +void press(ProControllerContext& context, IntroKey key, Milliseconds release){ + switch (key){ + case IntroKey::UP: + pbf_press_dpad(context, DPAD_UP, /*hold=*/80ms, release); + break; + case IntroKey::DOWN: + pbf_press_dpad(context, DPAD_DOWN, /*hold=*/80ms, release); + break; + case IntroKey::LEFT: + pbf_press_dpad(context, DPAD_LEFT, /*hold=*/80ms, release); + break; + case IntroKey::RIGHT: + pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, release); + break; + case IntroKey::A: + pbf_press_button(context, BUTTON_A, /*hold=*/80ms, release); + break; + } +} + +// The look picker's presses are left stick tilts (it says "Use the Left +// Stick"; the D-pad does not move it). +void tilt(ProControllerContext& context, IntroKey key){ + switch (key){ + case IntroKey::UP: + pbf_move_left_joystick(context, /*position=*/{0, +1}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); + break; + case IntroKey::DOWN: + pbf_move_left_joystick(context, /*position=*/{0, -1}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); + break; + case IntroKey::LEFT: + pbf_move_left_joystick(context, /*position=*/{-1, 0}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); + break; + case IntroKey::RIGHT: + pbf_move_left_joystick(context, /*position=*/{+1, 0}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); + break; + default: + break; + } +} + +// After the launch, until the language list, pressing nothing (see +// LAUNCH_LIMIT). `recorder` and `language`: capture mode, save each new +// screen on the way. +void wait_for_language_list( + ConsoleHandle& console, ProControllerContext& context, + IntroFrameRecorder* recorder, NewGameLanguage language +){ + const WallClock start = current_time(); + std::optional last_saved; + while (current_time() - start < LAUNCH_LIMIT){ + const VideoSnapshot frame = snapshot(console, context); + if (frame && read_language_list_cursor(frame)){ + console.log("AutoStory intro: the language list shows."); + dump_debug_image(console, std::string(DUMP_FOLDER), "language-list", frame); + return; + } + if (frame && recorder){ + const Milliseconds at = std::chrono::duration_cast(current_time() - start); + const std::optional change = last_saved + ? std::optional(ImageMatch::pixel_RMSD(*last_saved, frame)) + : std::nullopt; + if (recorder->see(at, change)){ + const std::string file = intro_capture_file(language, std::format("{:02}", recorder->saved() - 1)); + frame->save(SCREENSHOTS_PATH() + file); + console.log(std::format("AutoStory capture: {} ({} ms after the launch).", file, at.count())); + last_saved = frame->copy(); + } + } + context.wait_for(250ms); + } + fail(console, std::format("the language list did not show within {} s of the launch.", LAUNCH_LIMIT.count() / 1000)); +} + +// On the language list (it opens on English): one tap at a time to +// `language`, reading the highlight after each, then A, which opens the +// look picker with no confirmation. +void pick_language(ConsoleHandle& console, ProControllerContext& context, NewGameLanguage language){ + const NewGameLanguageInfo& info = new_game_language_info(language); + for (size_t attempt = 0; attempt < 20; attempt++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_language_list_cursor(frame) : std::nullopt; + if (!cursor){ + context.wait_for(250ms); + continue; + } + if (*cursor == info.list_entry){ + console.log(std::format("AutoStory intro: language {} (entry {}): A.", info.tag, info.list_entry)); + press(context, IntroKey::A, 500ms); + return; + } + const std::optional> moves = language_list_moves(*cursor, info.list_entry); + if (!moves || moves->empty()){ + break; + } + press(context, moves->front(), LANGUAGE_TAP_RELEASE); + } + fail(console, std::format("the language list's highlight did not reach {}.", info.tag)); +} + +// The look picker's highlight once settled: two reads in a row agree, +// 150 ms apart, within 2 s. +std::optional read_settled_look(ConsoleHandle& console, ProControllerContext& context){ + std::optional previous; + for (size_t read = 0; read < 14; read++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; + if (cursor && cursor == previous){ + return cursor; + } + previous = cursor; + context.wait_for(150ms); + } + return std::nullopt; +} + +// On the look picker: it opens with no portrait highlighted, and the first +// tilt highlights one that differs from launch to launch (the console, +// 2026-11-15: looks 1, 2, 5, 6, 7 and 8 after a tilt left). So it tilts +// left until a highlight reads, then toward `look`, reading the highlight +// after each tilt, and presses A only once it reads `look` (A opens the +// name keyboard). +void pick_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ + if (!wait_for_frame(console, context, is_look_picker, 20000ms)){ + fail(console, "the look picker did not show within 20 s of the language's A."); + } + const VideoSnapshot picker = snapshot(console, context); + if (picker){ + dump_debug_image(console, std::string(DUMP_FOLDER), "look-picker", picker); + } + size_t unread = 0; + for (size_t attempt = 0; attempt < 24 && unread <= 6; attempt++){ + const std::optional cursor = read_settled_look(console, context); + if (!cursor){ + unread++; + tilt(context, IntroKey::LEFT); + continue; + } + if (*cursor == look){ + console.log(std::format("AutoStory intro: look {}: A.", look)); + press(context, IntroKey::A, 500ms); + return; + } + const std::optional> moves = look_picker_moves(*cursor, look); + if (!moves || moves->empty()){ + break; + } + tilt(context, moves->front()); + } + fail(console, std::format("the look picker's highlight was not read on look {}.", look)); +} + +// Until the name keyboard has shown and finished sliding in (presses +// during that are dropped). +void wait_for_keyboard(ConsoleHandle& console, ProControllerContext& context){ + if (!wait_for_frame(console, context, is_name_keyboard, 20000ms)){ + fail(console, "the name keyboard did not show within 20 s of the look's A."); + } + context.wait_for(1000ms); +} + +// The keyboard's "0/N" counter (12 in the European languages, 6 in +// Japanese, Korean and Chinese): throws UserSetupError, nothing typed, if +// the name is longer. +void check_name_limit(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + const VideoSnapshot frame = snapshot(console, context); + if (frame){ + dump_debug_image(console, std::string(DUMP_FOLDER), "keyboard", frame); + } + const std::optional limit = frame ? read_name_keyboard_limit(frame) : std::nullopt; + if (!limit){ + console.log("AutoStory intro: keyboard: the 0/N counter did not read; the language's limit holds."); + }else if (*limit < choices.name.size()){ + throw UserSetupError(console, std::format( + "AutoStory: the name keyboard takes {} characters; the player name \"{}\" has {}. Nothing was typed.", + *limit, choices.name, choices.name.size() + )); + }else{ + console.log(std::format("AutoStory intro: keyboard: takes {} characters.", *limit)); + } +} + +// Simplified Chinese's keyboard opens in Pinyin, where letters compose +// Chinese; the bottom row's English key, under column 3, switches it to +// letters (Traditional Chinese's opens on letters). Moves the cursor +// there one D-pad tap at a time, reading it after each, then A. +void switch_to_letters(ConsoleHandle& console, ProControllerContext& context){ + constexpr SystemKeyboardKey LETTERS_KEY{.row = 4, .col = 3}; + for (size_t attempt = 0; attempt < 16; attempt++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_system_keyboard_cursor(frame) : std::nullopt; + if (!cursor){ + context.wait_for(300ms); + continue; + } + if (*cursor == LETTERS_KEY){ + console.log("AutoStory intro: keyboard: English (letters) key: A."); + press(context, IntroKey::A, 400ms); + return; + } + if (cursor->col == 11 || cursor->col > LETTERS_KEY.col){ + press(context, IntroKey::LEFT, 300ms); + }else if (cursor->row < LETTERS_KEY.row){ + press(context, IntroKey::DOWN, 300ms); + }else{ + press(context, IntroKey::RIGHT, 300ms); + } + } + fail(console, "the keyboard's cursor did not reach the English (letters) key."); +} + +// After the name: + until Confirm Choices shows, checking the screen after +// each press (see SUBMIT_PRESSES). +void submit_name(ConsoleHandle& console, ProControllerContext& context){ + const FrameCheck confirm_choices = [](const ImageViewRGB32& frame){ + return read_confirm_choices_cursor(frame).has_value(); + }; + for (size_t pressed = 1; pressed <= SUBMIT_PRESSES; pressed++){ + console.log(std::format("AutoStory intro: keyboard: + ({} of at most {}).", pressed, SUBMIT_PRESSES)); + pbf_press_button(context, BUTTON_PLUS, /*hold=*/80ms, /*release=*/500ms); + if (wait_for_frame(console, context, confirm_choices, SUBMIT_WAIT)){ + console.log("AutoStory intro: Confirm Choices shows."); + return; + } + const VideoSnapshot frame = snapshot(console, context); + if (!frame || !is_name_keyboard(frame)){ + break; + } + console.log("AutoStory intro: keyboard: still open after +."); + } + if (!wait_for_frame(console, context, confirm_choices, 15000ms)){ + fail(console, "Confirm Choices did not show after the name's +."); + } +} + +// On the keyboard: checks its counter, types the name with the Switch +// keyboard typer (which reads the cursor before each key and checks each +// press reached the field), then submits it. +void type_name(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + wait_for_keyboard(console, context); + check_name_limit(console, context, choices); + if (choices.language == NewGameLanguage::ChineseSimplified){ + switch_to_letters(console, context); + } + console.log(std::format("AutoStory intro: typing \"{}\".", choices.name)); + FastCodeEntry::type_on_system_keyboard(console, context, choices.name); + submit_name(console, context); +} + +// Capture mode: the screen now as `language`'s `screen`. +void save_capture(ConsoleHandle& console, ProControllerContext& context, NewGameLanguage language, std::string_view screen){ + const VideoSnapshot frame = snapshot(console, context); + const std::string file = intro_capture_file(language, screen); + if (frame){ + frame->save(SCREENSHOTS_PATH() + file); + console.log(std::format("AutoStory capture: {}.", file)); + } +} + +std::optional read_start(ConsoleHandle& console, const ImageViewRGB32& frame){ + if (read_confirm_choices_cursor(frame)){ + return NewGameStart::CONFIRM_CHOICES; + } + if (read_language_list_cursor(frame)){ + return NewGameStart::LANGUAGE_LIST; + } + HomeMenuDetector home(console, COLOR_RED); + if (home.detect_only(frame)){ + return NewGameStart::HOME; + } + return std::nullopt; +} + +} // namespace + + +NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context){ + const WallClock deadline = current_time() + 2000ms; + while (true){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional start = frame ? read_start(console, frame) : std::nullopt; + if (start){ + console.log(std::format("AutoStory intro: starting on screen {} (0 HOME, 1 language list, 2 Confirm Choices).", (int)*start)); + return *start; + } + if (current_time() >= deadline){ + throw UserSetupError( + console, + std::format( + "AutoStory: 01.00 starts a new game (no save) from the Switch HOME (PLZA's tile among the first {}), " + "from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed.", + HOME_TILES_SEARCHED + ) + ); + } + context.wait_for(250ms); + } +} + +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + if (const std::optional problem = new_game_problem(choices)){ + throw UserSetupError(console, *problem); + } + switch (require_new_game_start(console, context)){ + case NewGameStart::CONFIRM_CHOICES: + console.log("AutoStory intro: already on Confirm Choices; its check reads the language and name."); + return; + case NewGameStart::HOME: + launch_plza_from_home(console, context); + wait_for_language_list(console, context, /*recorder=*/nullptr, choices.language); + break; + case NewGameStart::LANGUAGE_LIST: + break; + } + pick_language(console, context, choices.language); + pick_look(console, context, choices.look); + type_name(console, context, choices); +} + + +bool IntroFrameRecorder::see(Milliseconds at, std::optional from_saved){ + if (m_last_saved && at - *m_last_saved < m_every){ + return false; + } + if (from_saved && *from_saved <= m_change){ + return false; + } + m_last_saved = at; + m_saved++; + return true; +} + +std::string intro_capture_file(NewGameLanguage language, std::string_view screen){ + return std::format("{}_{}.png", new_game_language_info(language).tag, screen); +} + +void capture_intro_screens(ConsoleHandle& console, ProControllerContext& context, size_t look){ + for (size_t index = 0; index < 10; index++){ + const NewGameLanguage language = (NewGameLanguage)index; + const NewGameLanguageInfo& info = new_game_language_info(language); + console.log(std::format("AutoStory capture: {}: closing the game and launching it from HOME.", info.tag)); + launch_plza_from_home(console, context); + IntroFrameRecorder recorder(CAPTURE_CHANGE, CAPTURE_EVERY); + wait_for_language_list(console, context, &recorder, language); + save_capture(console, context, language, "language-list"); + pick_language(console, context, language); + if (!wait_for_frame(console, context, is_look_picker, 20000ms)){ + fail(console, "the look picker did not show within 20 s of the language's A."); + } + save_capture(console, context, language, "look-picker"); + pick_look(console, context, look); + wait_for_keyboard(console, context); + save_capture(console, context, language, "keyboard"); + console.log(std::format("AutoStory capture: {}: {} screens before the language list.", info.tag, recorder.saved())); + } + go_home(console, context); + close_game_from_home(console, context); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h new file mode 100644 index 0000000000..002dea846f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h @@ -0,0 +1,93 @@ +/* PokemonLZA AutoStory - New game + * + * From: https://github.com/PokemonAutomation/ + * + * 01.00's steps before "Confirm Choices": launch the game from HOME, pick + * the language, the look and type the name (PokemonLZA_AutoStoryNewGameChoices.h), + * and a developer mode that saves each language's intro screens. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGame_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGame_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The screens a new game (no save) may start on. +enum class NewGameStart{ + HOME, // The Switch's HOME (launch_plza_from_home() closes any game and finds PLZA's tile). + LANGUAGE_LIST, + CONFIRM_CHOICES, // The language, look and name chosen already. +}; + +// The screen now, read over up to 2 s with no press. Throws UserSetupError, +// having pressed nothing, if it is none of NewGameStart's. +NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context); + +// 01.00's first step: from HOME (launch_plza_from_home()) or the language list, plays the language, the look and +// the name of `choices` up to "Confirm Choices"; on "Confirm Choices" it +// presses nothing. Each screen's highlight is read before and after each +// press; the name is typed with the Switch keyboard typer. Throws +// UserSetupError before any press if `choices` cannot be played +// (new_game_problem()) or the keyboard's counter takes fewer characters +// than the name, OperationFailedException (with a screenshot) if a screen +// does not show, its highlight does not reach the choice, or a key press +// does not reach the name's field. +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices); + +// Capture mode's recording of the screens between the launch and the +// language list: a polled frame is saved when it differs from the last +// saved one by more than `change` (pixel RMSD), at most one per `every`. +class IntroFrameRecorder{ +public: + IntroFrameRecorder(double change, Milliseconds every) + : m_change(change) + , m_every(every) + {} + + // Whether to save the frame polled at `at` (since the recording + // began), `from_saved` from the last saved one (none: nothing saved + // yet). Counts it as saved when so. + bool see(Milliseconds at, std::optional from_saved); + + // How many frames were saved. + size_t saved() const{ + return m_saved; + } + +private: + double m_change; + Milliseconds m_every; + std::optional m_last_saved; + size_t m_saved = 0; +}; + +// The file capture mode saves `language`'s screen `screen` to, in the +// Screenshots folder: "_.png". +std::string intro_capture_file(NewGameLanguage language, std::string_view screen); + +// Developer: for each of the 10 languages (Korean too: nothing is typed), +// closes the game, launches it from HOME and saves each distinct screen +// up to the language list as "_NN.png" (NN from 00, in order), then +// "_language-list.png"; picks the language and look `look`, saves +// "_look-picker.png" and "_keyboard.png", and goes back to HOME. +// Nothing is typed or confirmed, so no save is made. +void capture_intro_screens(ConsoleHandle& console, ProControllerContext& context, size_t look); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp new file mode 100644 index 0000000000..45aac4ceaa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp @@ -0,0 +1,132 @@ +/* PokemonLZA AutoStory - New game choices + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The language list's rows per column. +constexpr size_t LANGUAGE_LIST_ROWS = 5; +constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; + +// The look picker: 2 rows of LOOK_COLUMNS portraits. +constexpr size_t LOOK_COLUMNS = 4; +constexpr size_t LOOK_COUNT = 2 * LOOK_COLUMNS; + +// Whether every character of `name` has a key on the name keyboard's +// first page, which the Switch keyboard typer types (letters by their +// capital). +bool on_keyboard(std::string_view name){ + const std::map& keys = KEYBOARD_POSITIONS(KeyboardLayout::QWERTY); + for (const char ch : name){ + if (!keys.contains((char)std::toupper((unsigned char)ch))){ + return false; + } + } + return true; +} + +// The presses from (column, row) `from` to `to` on a grid: across first, +// then up or down. +std::vector grid_moves(size_t from_column, size_t from_row, size_t to_column, size_t to_row){ + std::vector moves; + for (size_t c = from_column; c < to_column; c++){ + moves.push_back(IntroKey::RIGHT); + } + for (size_t c = to_column; c < from_column; c++){ + moves.push_back(IntroKey::LEFT); + } + for (size_t r = from_row; r < to_row; r++){ + moves.push_back(IntroKey::DOWN); + } + for (size_t r = to_row; r < from_row; r++){ + moves.push_back(IntroKey::UP); + } + return moves; +} + +} // namespace + + +const NewGameLanguageInfo& new_game_language_info(NewGameLanguage language){ + static const std::array table{{ + {.tag = "en", .list_entry = 0, .name_limit = 12, .ocr_language = Language::English, .confirm_text = "English"}, + {.tag = "es-ES", .list_entry = 1, .name_limit = 12, .ocr_language = Language::Spanish, .confirm_text = "Espa\xc3\xb1" "a)"}, + {.tag = "es-419", .list_entry = 2, .name_limit = 12, .ocr_language = Language::Spanish, .confirm_text = "Latino"}, + {.tag = "fr", .list_entry = 3, .name_limit = 12, .ocr_language = Language::French, .confirm_text = "Fran"}, + {.tag = "de", .list_entry = 4, .name_limit = 12, .ocr_language = Language::German, .confirm_text = "Deutsch"}, + {.tag = "it", .list_entry = 5, .name_limit = 12, .ocr_language = Language::Italian, .confirm_text = "Italiano"}, + {.tag = "ja", .list_entry = 6, .name_limit = 6, .ocr_language = Language::Japanese, .confirm_text = "\xe6\x97\xa5\xe6\x9c\xac"}, + {.tag = "ko", .list_entry = 7, .name_limit = 6, .ocr_language = Language::Korean, .confirm_text = "\xed\x95\x9c\xea\xb5\xad", .supported = false}, + {.tag = "zh-Hans", .list_entry = 8, .name_limit = 6, .ocr_language = Language::ChineseSimplified, .confirm_text = "\xe7\xae\x80\xe4\xbd\x93"}, + {.tag = "zh-Hant", .list_entry = 9, .name_limit = 6, .ocr_language = Language::ChineseTraditional, .confirm_text = "\xe7\xb9\x81\xe9\xab\x94"}, + }}; + const size_t index = (size_t)language; + return table[index < table.size() ? index : 0]; +} + +std::optional new_game_problem(const NewGameChoices& choices){ + const NewGameLanguageInfo& info = new_game_language_info(choices.language); + if (!info.supported){ + return std::format("AutoStory: Korean ({}) is not supported yet: its name keyboard is Hangul.", info.tag); + } + if (choices.look < 1 || choices.look > LOOK_COUNT){ + return std::format("AutoStory: the player look must be 1 to {}, not {}.", LOOK_COUNT, choices.look); + } + if (choices.name.empty()){ + return std::string("AutoStory: the player name is empty."); + } + if (choices.name.size() > info.name_limit){ + return std::format( + "AutoStory: the player name \"{}\" has {} characters; the game takes at most {} in this language ({}).", + choices.name, choices.name.size(), info.name_limit, info.tag + ); + } + if (!on_keyboard(choices.name)){ + return std::format( + "AutoStory: the player name \"{}\" has a character that is not on the name keyboard's first page " + "(letters, digits and - / : ' , . ? !).", + choices.name + ); + } + return std::nullopt; +} + +std::optional> language_list_moves(size_t from, size_t to){ + if (from >= LANGUAGE_LIST_SIZE || to >= LANGUAGE_LIST_SIZE){ + return std::nullopt; + } + return grid_moves( + from / LANGUAGE_LIST_ROWS, from % LANGUAGE_LIST_ROWS, + to / LANGUAGE_LIST_ROWS, to % LANGUAGE_LIST_ROWS + ); +} + +std::optional> look_picker_moves(size_t from, size_t to){ + if (from < 1 || from > LOOK_COUNT || to < 1 || to > LOOK_COUNT){ + return std::nullopt; + } + return grid_moves( + (from - 1) % LOOK_COLUMNS, (from - 1) / LOOK_COLUMNS, + (to - 1) % LOOK_COLUMNS, (to - 1) / LOOK_COLUMNS + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h new file mode 100644 index 0000000000..9ff781006a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h @@ -0,0 +1,104 @@ +/* PokemonLZA AutoStory - New game choices + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's choices (language, look, name) and the presses each takes + * on its screen, as pure functions. The screens' readers are in + * Detectors/PokemonLZA_AutoStoryIntroScreens.h; the name is typed with the + * Switch keyboard typer (NintendoSwitch_SystemKeyboardTyping.h). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGameChoices_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGameChoices_H + +#include +#include +#include +#include +#include +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The game's 10 languages, in the language list's order: down the left +// column (English, Espanol (Espana), Espanol (Latinoamerica), Francais, +// Deutsch), then down the right one (Italiano, Japanese, Korean, +// Simplified and Traditional Chinese). The cursor starts on English. +enum class NewGameLanguage{ + English, + SpanishSpain, + SpanishLatinAmerica, + French, + German, + Italian, + Japanese, + Korean, + ChineseSimplified, + ChineseTraditional, +}; + +// What the intro needs to know of one language. +struct NewGameLanguageInfo{ + // Short name for logs and capture files: "en", "es-ES", "ja", ... + std::string_view tag; + // Its entry on the language list (the order of NewGameLanguage). + size_t list_entry = 0; + // The name keyboard's character limit: its "0/N" counter (the + // console's frames of 2026-11-15: 12 for English and the other + // European languages, 6 for Japanese, Korean and Chinese). + size_t name_limit = 0; + // The OCR language that reads its name on Confirm Choices. + Language ocr_language = Language::None; + // A part of its name as Confirm Choices shows it ("Deutsch", "Latino"). + std::string_view confirm_text; + // The program can play it (Korean: not yet; its keyboard is Hangul, + // which the Switch keyboard typer does not read). + bool supported = true; +}; + +// `language`'s row of the table above. +const NewGameLanguageInfo& new_game_language_info(NewGameLanguage language); + +// One press on an intro screen. +enum class IntroKey{ + UP, + DOWN, + LEFT, + RIGHT, + A, +}; + +// The new game's choices, from the program's options. +struct NewGameChoices{ + NewGameLanguage language = NewGameLanguage::English; + // 1 to 8: the look picker's portraits, left to right along the top + // row, then the bottom one. + size_t look = 1; + // Letters, digits and the symbols on the name keyboard's first page + // (- / : ' , . ? !), at most the language's name_limit. + std::string name = "Kosmos"; +}; + +// Why `choices` cannot be played, before any press; nullopt when they can. +std::optional new_game_problem(const NewGameChoices& choices); + +// The presses that move the language list's cursor from entry `from` to +// entry `to`: LEFT or RIGHT to the column, then UP or DOWN to the row. +// Nullopt for an entry outside the list. +std::optional> language_list_moves(size_t from, size_t to); + +// The presses (stick tilts) that move the look picker's highlight from +// look `from` to look `to` (1 to 8): LEFT or RIGHT, then UP or DOWN. +// Nullopt for a look outside 1 to 8. +std::optional> look_picker_moves(size_t from, size_t to); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp new file mode 100644 index 0000000000..6914b2eaa3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp @@ -0,0 +1,312 @@ +/* PokemonLZA AutoStory - New game Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryNewGame.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" +#include "PokemonLZA_AutoStoryNewGame_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// Presses as letters: U D L R, A. +std::string press_text(const std::optional>& presses){ + if (!presses){ + return "none"; + } + std::string text; + for (const IntroKey key : *presses){ + switch (key){ + case IntroKey::UP: + text += 'U'; + break; + case IntroKey::DOWN: + text += 'D'; + break; + case IntroKey::LEFT: + text += 'L'; + break; + case IntroKey::RIGHT: + text += 'R'; + break; + case IntroKey::A: + text += 'A'; + break; + } + } + return text; +} + + +// new_game_problem(): whether the program refuses the choices before any +// press. +struct ProblemCase{ + std::string name; + struct Input{ + NewGameChoices choices; + }; + Input input; + struct Expectation{ + bool refused = false; + }; + Expectation expectation; +}; + +const ProblemCase PROBLEM_CASES[] = { + {.name = "the defaults", .input = {.choices = {}}, .expectation = {.refused = false}}, + { + .name = "12 characters in English", + .input = {.choices = {.name = "Abcdefghijkl"}}, + .expectation = {.refused = false}, + }, + { + .name = "13 characters in English", + .input = {.choices = {.name = "Abcdefghijklm"}}, + .expectation = {.refused = true}, + }, + { + .name = "12 characters in German", + .input = {.choices = {.language = NewGameLanguage::German, .name = "Abcdefghijkl"}}, + .expectation = {.refused = false}, + }, + { + .name = "6 characters in Japanese", + .input = {.choices = {.language = NewGameLanguage::Japanese, .name = "Kosmos"}}, + .expectation = {.refused = false}, + }, + { + .name = "7 characters in Japanese", + .input = {.choices = {.language = NewGameLanguage::Japanese, .name = "Kosmoss"}}, + .expectation = {.refused = true}, + }, + { + .name = "7 characters in Traditional Chinese", + .input = {.choices = {.language = NewGameLanguage::ChineseTraditional, .name = "Kosmoss"}}, + .expectation = {.refused = true}, + }, + { + .name = "Korean is not supported", + .input = {.choices = {.language = NewGameLanguage::Korean, .name = "Kosmos"}}, + .expectation = {.refused = true}, + }, + {.name = "an empty name", .input = {.choices = {.name = ""}}, .expectation = {.refused = true}}, + {.name = "a space in the name", .input = {.choices = {.name = "Kos mos"}}, .expectation = {.refused = true}}, + {.name = "digits and the first page's symbols", .input = {.choices = {.name = "a1-/:',.?!"}}, .expectation = {.refused = false}}, + {.name = "an accented letter", .input = {.choices = {.name = "Jos\xc3\xa9"}}, .expectation = {.refused = true}}, + {.name = "a symbol of the second page", .input = {.choices = {.name = "a#"}}, .expectation = {.refused = true}}, + {.name = "look 8", .input = {.choices = {.look = 8}}, .expectation = {.refused = false}}, + {.name = "look 0", .input = {.choices = {.look = 0}}, .expectation = {.refused = true}}, + {.name = "look 9", .input = {.choices = {.look = 9}}, .expectation = {.refused = true}}, +}; + +class Test_NewGameProblem : public UnitTest{ +public: + explicit Test_NewGameProblem(const ProblemCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - new game choices: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional problem = new_game_problem(m_test.input.choices); + if (problem.has_value() != m_test.expectation.refused){ + return std::format( + "Expected {}, got {}.", + m_test.expectation.refused ? "a refusal" : "no problem", + problem ? *problem : std::string("no problem") + ); + } + return true; + } + +private: + const ProblemCase& m_test; +}; + + +// The language list's moves (entries down the left column, then the right +// one) and the look picker's (looks along the top row, then the bottom). +enum class Grid{ + LANGUAGE_LIST, + LOOK_PICKER, +}; + +struct GridCase{ + std::string name; + struct Input{ + Grid grid = Grid::LANGUAGE_LIST; + size_t from = 0; + size_t to = 0; + }; + Input input; + struct Expectation{ + std::string presses; + }; + Expectation expectation; +}; + +const GridCase GRID_CASES[] = { + {.name = "English to Deutsch", .input = {.from = 0, .to = 4}, .expectation = {.presses = "DDDD"}}, + {.name = "English to Italiano", .input = {.from = 0, .to = 5}, .expectation = {.presses = "R"}}, + {.name = "English to Traditional Chinese", .input = {.from = 0, .to = 9}, .expectation = {.presses = "RDDDD"}}, + {.name = "Simplified Chinese to Francais", .input = {.from = 8, .to = 3}, .expectation = {.presses = "L"}}, + {.name = "an entry past the list", .input = {.from = 0, .to = 10}, .expectation = {.presses = "none"}}, + {.name = "look 1 to look 8", .input = {.grid = Grid::LOOK_PICKER, .from = 1, .to = 8}, .expectation = {.presses = "RRRD"}}, + {.name = "look 7 to look 2", .input = {.grid = Grid::LOOK_PICKER, .from = 7, .to = 2}, .expectation = {.presses = "LU"}}, + {.name = "look 0", .input = {.grid = Grid::LOOK_PICKER, .from = 0, .to = 2}, .expectation = {.presses = "none"}}, +}; + +class Test_GridMoves : public UnitTest{ +public: + explicit Test_GridMoves(const GridCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - intro moves: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string presses = press_text(m_test.input.grid == Grid::LANGUAGE_LIST + ? language_list_moves(m_test.input.from, m_test.input.to) + : look_picker_moves(m_test.input.from, m_test.input.to) + ); + if (presses != m_test.expectation.presses){ + return std::format("Expected {}, got {}.", m_test.expectation.presses, presses); + } + return true; + } + +private: + const GridCase& m_test; +}; + + +// Capture mode's recording: change 4, at most one frame a second. Each +// frame is (ms since the launch, RMSD from the last saved; -1: none yet). +struct RecorderCase{ + std::string name; + struct Input{ + std::vector> frames; + }; + Input input; + struct Expectation{ + std::string saved; // One letter per frame: s saved, . not. + }; + Expectation expectation; +}; + +const RecorderCase RECORDER_CASES[] = { + {.name = "the first frame is saved", .input = {.frames = {{0, -1}}}, .expectation = {.saved = "s"}}, + { + .name = "a still screen is saved once", + .input = {.frames = {{0, -1}, {1500, 1}, {3000, 2}}}, + .expectation = {.saved = "s.."}, + }, + { + .name = "each new screen is saved", + .input = {.frames = {{0, -1}, {1500, 30}, {3000, 3}, {4500, 25}}}, + .expectation = {.saved = "ss.s"}, + }, + { + .name = "a change within a second of the last save waits", + .input = {.frames = {{0, -1}, {500, 30}, {1250, 30}}}, + .expectation = {.saved = "s.s"}, + }, +}; + +class Test_IntroRecorder : public UnitTest{ +public: + explicit Test_IntroRecorder(const RecorderCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - capture recording: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + IntroFrameRecorder recorder(/*change=*/4, /*every=*/Milliseconds(1000)); + std::string saved; + for (const auto& [at, change] : m_test.input.frames){ + const std::optional from_saved = change < 0 ? std::nullopt : std::optional(change); + saved += recorder.see(Milliseconds(at), from_saved) ? 's' : '.'; + } + if (saved != m_test.expectation.saved){ + return std::format("Expected {}, got {}.", m_test.expectation.saved, saved); + } + return true; + } + +private: + const RecorderCase& m_test; +}; + + +// Capture mode's file names, which sort each language's screens in order. +struct CaptureFileCase{ + std::string name; + struct Input{ + NewGameLanguage language = NewGameLanguage::English; + std::string screen; + }; + Input input; + struct Expectation{ + std::string file; + }; + Expectation expectation; +}; + +const CaptureFileCase CAPTURE_FILE_CASES[] = { + {.name = "a screen before the list", .input = {.language = NewGameLanguage::German, .screen = "03"}, .expectation = {.file = "de_03.png"}}, + {.name = "Korean is captured", .input = {.language = NewGameLanguage::Korean, .screen = "keyboard"}, .expectation = {.file = "ko_keyboard.png"}}, + { + .name = "Latin American Spanish", + .input = {.language = NewGameLanguage::SpanishLatinAmerica, .screen = "language-list"}, + .expectation = {.file = "es-419_language-list.png"}, + }, +}; + +class Test_CaptureFile : public UnitTest{ +public: + explicit Test_CaptureFile(const CaptureFileCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - capture file: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string file = intro_capture_file(m_test.input.language, m_test.input.screen); + if (file != m_test.expectation.file){ + return std::format("Expected {}, got {}.", m_test.expectation.file, file); + } + return true; + } + +private: + const CaptureFileCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryNewGame(UnitTestDatabase& database){ + for (const ProblemCase& test : PROBLEM_CASES){ + database.add(test); + } + for (const GridCase& test : GRID_CASES){ + database.add(test); + } + for (const RecorderCase& test : RECORDER_CASES){ + database.add(test); + } + for (const CaptureFileCase& test : CAPTURE_FILE_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h new file mode 100644 index 0000000000..8dcb17eb58 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h @@ -0,0 +1,27 @@ +/* PokemonLZA AutoStory - New game Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGame_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGame_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the new game's tests: the choices' checks, the language list's +// and look picker's moves, the name's key presses and capture mode's +// recording and file names. +void add_tests_AutoStoryNewGame(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp index 47c11443c9..c2d1d9cb1e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -6,6 +6,8 @@ #include #include +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -32,15 +34,29 @@ bool shows_control(const ScreenObservation& look){ return look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && !look.events.has(ScreenEvent::DIALOG_BOX); } +// The button for what shows: A on a tutorial card, whose pages B turns +// back, and on text until the card has shown; B on the rest: the map +// app, where A places a pin, and her talk after it (as played by hand, +// 03.02b step 45). +enum class MapTalkPart{BEFORE_CARD, AFTER_CARD}; +Button map_talk_button(const ScreenObservation& look, MapTalkPart part){ + if (look.readings.contains(TUTORIAL_CARD_READING)){ + return BUTTON_A; + } + const bool text = look.events.has(ScreenEvent::DIALOG_BOX) || look.readings.contains(ADVANCE_ARROW_READING); + return text && part == MapTalkPart::BEFORE_CARD ? BUTTON_A : BUTTON_B; +} + } // namespace Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend){ - // Each look presses for 2 s or waits; the looks bound a script whose + // Each look presses for 1 s or waits; the looks bound a script whose // time stands still. const size_t max_looks = (size_t)(MAP_TALK_TIMEOUT / MAP_TALK_POLL) + 1; std::optional start; std::optional control_since; + MapTalkPart part = MapTalkPart::BEFORE_CARD; for (size_t looks = 0; looks < max_looks; looks++){ backend.scope().throw_if_cancelled(); const Pokemon::Observation look = backend.observe(); @@ -58,11 +74,13 @@ Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend){ if (look.when - *start >= MAP_TALK_TIMEOUT){ break; } - backend.press(BUTTON_A, MAP_TALK_HOLD, MAP_TALK_RELEASE); - backend.press(BUTTON_B, MAP_TALK_HOLD, MAP_TALK_RELEASE); + backend.press(map_talk_button(look, part), MAP_TALK_HOLD, MAP_TALK_RELEASE); + if (look.readings.contains(TUTORIAL_CARD_READING)){ + part = MapTalkPart::AFTER_CARD; + } } return Pokemon::outcome_failed("map_talk_timeout", std::format( - "no party bar held {} ms within {} ms of A and B in turn", + "no party bar held {} ms within {} ms of A on the talk and the card, B on the map", MAP_TALK_CONTROL_HOLD.count(), MAP_TALK_TIMEOUT.count() )); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h index a28a29da55..d61f6521b5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * Story steps that press through one particular screen of the story, on - * the engine's backend: Taunie's first map (03.02) and the side street's + * the engine's backend: Taunie's first map (03.02b) and the side street's * ladder (03.03). * */ @@ -19,13 +19,17 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -// Taunie's talk after her battle (03.02), the "Map & Missions" card, the -// first map and the rest of her talk: A then B, a second each, until the -// party bar shows with no text box on looks a second apart. A pages the -// talk and the card; B closes the map, where A would place a pin. The map -// is not looked for: MapDetector needs the Travel Spots icon, which the -// first map lacks (console B, 2026-11-13). No presses once the party bar -// shows. Fails as "map_talk_timeout" after 120 s (by the looks' time). +// Taunie's talk after her battle (03.02b), the "Map & Missions" card, the +// first map and the rest of her talk, one press a second by what shows, +// until the party bar shows with no text box on looks a second apart: a +// tutorial card (TUTORIAL_CARD_READING) and text (a box or the advance +// chevron) before the card get A, anything else B. A pages the card and +// closes it on its last page, where B would turn back (console B +// 2026-11-16: A and B in turn held it on page 1 for 120 s); B closes the +// map, where A would place a pin. The map is not looked for: MapDetector +// needs the Travel Spots icon, which the first map lacks (console B, +// 2026-11-13). No presses once the party bar shows. Fails as +// "map_talk_timeout" after 120 s (by the looks' time). Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend); // Facing the side street's wall (03.03): sidestep right to the ladder diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp index fa455acff6..82cd671c29 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -10,6 +10,7 @@ #include #include #include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" #include "PokemonLZA_AutoStoryWalkScreenChecks.h" namespace PokemonAutomation{ @@ -128,26 +129,31 @@ void finish_walk(PlzaBackend& backend, std::string_view walk){ } Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const StoryMove& move, ScreenEvent end){ - StoryMove head = move; - Milliseconds hold = 0ms; - if (!head.legs.empty()){ - hold = head.legs.back().walk; - head.legs.back().walk = 0ms; - } - const Pokemon::Outcome walked = run_story_move(backend, head); + const Milliseconds hold = move.legs.empty() ? 0ms : move.legs.back().walk; + const Pokemon::Outcome walked = run_story_move_but_last_walk(backend, move); if (!walked.succeeded()){ return walked; } + if (hold == 0ms){ + // A last leg that only turns (to face the clerk): what the walk + // goes to shows once the turn is done, or the walk missed it. + if (backend.observe().events.has(end)){ + backend.log(std::format("[PLZA] {}: the end event after the last turn.", walk)); + return Pokemon::outcome_ok(); + } + return Pokemon::outcome_failed("walk_no_end", std::format("{}: no end event after the last turn", walk)); + } // The slices stop the stick between them for as long as a look takes; // the player barely slows. for (Milliseconds held = 0ms; held < hold;){ // The last slice holds only what is left, so the leg walks its time. const Milliseconds slice = std::min(HOLD_SLICE, hold - held); - backend.hold(Pokemon::Direction::NORTH, slice, Pokemon::StoryPace::WALK); + hold_last_leg(backend, move, slice); held += slice; const Pokemon::Observation look = backend.observe(); if (look.events.has(end)){ backend.log(std::format("[PLZA] {}: the end event after {} ms of the last leg.", walk, held.count())); + backend.log_detail(std::format("[PLZA] {}: ended on: {}", walk, describe_scene_look(look))); return Pokemon::outcome_ok(); } if (look.events.has(ScreenEvent::FADE_BLACK)){ @@ -173,6 +179,19 @@ Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout){ return Pokemon::outcome_failed("no_prompt", std::format("walk_to_prompt: no A prompt in {} ms of walking", timeout.count())); } +bool event_shows_within(PlzaBackend& backend, ScreenEvent event, Milliseconds within){ + for (Milliseconds waited = 0ms; ; waited += PROMPT_POLL){ + backend.scope().throw_if_cancelled(); + if (backend.observe().events.has(event)){ + return true; + } + if (waited >= within){ + return false; + } + backend.wait(PROMPT_POLL); + } +} + void press_through_prompt(PlzaBackend& backend){ for (size_t press = 1; press <= PROMPT_PRESSES; press++){ if (!press_at_prompt(backend)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h index d423c836d0..f86d417c2e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -38,11 +38,12 @@ Pokemon::Outcome check_can_walk(PlzaBackend& backend, std::string_view walk); // shows there. void finish_walk(PlzaBackend& backend, std::string_view walk); -// Walks `move`, holding its last leg in slices of 250 ms until a look -// shows `end` (a fade, or the box of a talk the walk runs into), the -// leg's time as the upper bound. A black fade ends it too: the scene at -// the walk's end takes over. Fails as "walk_no_end" if neither shows -// within it. +// Walks `move`, holding its last leg in slices of 250 ms +// (hold_last_leg()) until a look shows `end` (a fade, the box of a talk +// the walk runs into, or the A prompt of what it walks to), the leg's +// time as the upper bound. A black fade ends it too: the scene at the +// walk's end takes over. A last leg that only turns is looked at once, +// after the turn. Fails as "walk_no_end" if neither shows within it. Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const StoryMove& move, ScreenEvent end); // Walks straight on, 250 ms at a time, until an A prompt shows @@ -51,6 +52,12 @@ Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const S // one. Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout); +// Whether a look shows `event` within `within`, looking every 250 ms and +// pressing nothing: "talk" presses A only on an A prompt +// (INTERACT_PROMPT), "story_battle" fights only on the battle HUD +// (BATTLE_STARTED). +bool event_shows_within(PlzaBackend& backend, ScreenEvent event, Milliseconds within); + // A at the A prompt the player stands at (a door's "A Enter"), then looks // for up to 3 s for a fade or text; while the prompt stays with neither, // A again, 3 times at most. The party bar shows under the prompt, so a diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp new file mode 100644 index 0000000000..e5020e54f8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp @@ -0,0 +1,56 @@ +/* PokemonLZA AutoStory - Battle panel detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryBattlePanelDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The shares of the badge's and the bar's pixels that make the panel. +constexpr double BADGE_SHARE = 0.5; +constexpr double BAR_SHARE = 0.8; + +// An HP bar pixel: its fill (red, yellow or green: channels 90 or more +// apart), or its grey trough (channels within 25, mean 60 to 140). +bool hp_bar_pixel(Color color){ + const int r = color.red(); + const int g = color.green(); + const int b = color.blue(); + const int spread = std::max({r, g, b}) - std::min({r, g, b}); + const int mean = (r + g + b) / 3; + return spread >= 90 || (spread <= 25 && mean >= 60 && mean <= 140); +} + +} // namespace + + +BattlePanelDetector::BattlePanelDetector(Color color) + : m_color(color) + , m_badge(240.0 / 1920, 799.0 / 1080, 80.0 / 1920, 19.0 / 1080) + , m_bar(236.0 / 1920, 882.0 / 1080, 204.0 / 1920, 20.0 / 1080) +{} + +void BattlePanelDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_badge); + items.add(m_color, m_bar); +} + +bool BattlePanelDetector::detect(const ImageViewRGB32& screen){ + return sky_blue_share(screen, m_badge) >= BADGE_SHARE && share_of(screen, m_bar, hp_bar_pixel) >= BAR_SHARE; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h new file mode 100644 index 0000000000..13fb048562 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h @@ -0,0 +1,47 @@ +/* PokemonLZA AutoStory - Battle panel detector + * + * From: https://github.com/PokemonAutomation/ + * + * The player's Pokemon's panel at the bottom left in a battle: its level + * badge ("L. 7") and HP bar. It shows the whole battle, locked on or not; + * the move list and its hints show only while the player is locked on. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryBattlePanelDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryBattlePanelDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The panel's level badge, sky blue (about 140, 210, 235) at x 240-320, +// y 799-818 on 1920x1080, over half its pixels; and its HP bar at x +// 236-440, y 882-902 (left of the "4/24"), over 80% its HP color or its +// grey trough (about 95, 95, 95). Taunie's battle not locked on (03.02b, +// console B 2026-11-16): badge 0.78, bar 0.95; overworld frames: badge +// 0.18 at most, bar 0.20 at most. +class BattlePanelDetector : public StaticScreenDetector{ +public: + explicit BattlePanelDetector(Color color = COLOR_GREEN); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_badge; + ImageFloatBox m_bar; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp index c761cb6921..4296c0c239 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp @@ -28,6 +28,7 @@ #include "PokemonLZA_AutoStoryMainMissionBannerDetector.h" #include "PokemonLZA_AutoStoryMissionCompleteDetector.h" #include "PokemonLZA_AutoStoryPlatformArrivalDetector.h" +#include "PokemonLZA_AutoStoryTutorialCardDetector.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -603,6 +604,48 @@ UnitTestResult check_frame_folder(const FrameFolderCase& test, Logger& logger){ } +struct TutorialCardFrameCase{ + std::string name; + struct Input{ + std::string_view path; // In CommandLineTests/PokemonLZA/. + }; + Input input; + struct Expectation{ + bool card = false; + }; + Expectation expectation; +}; + +const TutorialCardFrameCase TUTORIAL_CARD_FRAME_CASES[] = { + { + // console B, 2026-11-16 (03.02b run 5): the "Map & Missions" card, + // page 1 of 2, over the map app's blue screen, not a dark one. + .name = "the Map & Missions card over the map app (Italian)", + .input = {.path = "AutoStoryScreenEvents/it_0302b_map_missions_card.png"}, + .expectation = {.card = true}, + }, + { + .name = "no card in a battle", + .input = {.path = "AutoStoryScreenEvents/it_0302b_battle_no_lock_on.png"}, + .expectation = {.card = false}, + }, + { + .name = "no card at the A Talk prompt", + .input = {.path = "AutoStoryScreenEvents/it_0102_parla_talk_prompt.png"}, + .expectation = {.card = false}, + }, +}; + +UnitTestResult check_tutorial_card_frame(const TutorialCardFrameCase& test){ + const std::string path = std::format("{}PokemonLZA/{}", UNIT_TEST_RESOURCE_PATH(), test.input.path); + const bool card = tutorial_card_shows(ImageRGB32(path)); + if (card != test.expectation.card){ + return std::format("{}: expected card {}, got {}", test.input.path, test.expectation.card ? "yes" : "no", card ? "yes" : "no"); + } + return true; +} + + class Test_SyntheticFrame : public UnitTest{ public: explicit Test_SyntheticFrame(const SyntheticFrameCase& test) @@ -617,6 +660,20 @@ class Test_SyntheticFrame : public UnitTest{ const SyntheticFrameCase& m_test; }; +class Test_TutorialCardFrame : public UnitTest{ +public: + explicit Test_TutorialCardFrame(const TutorialCardFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStoryDetectors - tutorial card frame: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_tutorial_card_frame(m_test); + } + +private: + const TutorialCardFrameCase& m_test; +}; + class Test_FrameFolder : public UnitTest{ public: explicit Test_FrameFolder(const FrameFolderCase& test) @@ -641,6 +698,9 @@ void add_tests_AutoStoryDetectors(UnitTestDatabase& database){ for (const FrameFolderCase& test : FRAME_FOLDER_CASES){ database.add(test); } + for (const TutorialCardFrameCase& test : TUTORIAL_CARD_FRAME_CASES){ + database.add(test); + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp new file mode 100644 index 0000000000..7773980351 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp @@ -0,0 +1,365 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/Images/ImageFilter.h" +#include "CommonTools/OCR/OCR_Routines.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr size_t LANGUAGE_LIST_ROWS = 5; +constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; +constexpr size_t LOOK_COLUMNS = 4; +constexpr size_t LOOK_COUNT = 2 * LOOK_COLUMNS; + +bool usable(const ImageViewRGB32& frame){ + return frame && frame.width() >= 160 && frame.height() >= 90; +} + +double brightness(const ImageStats& stats){ + return stats.average.sum() / 3; +} + +ImageStats box_stats(const ImageViewRGB32& frame, const ImageFloatBox& box){ + return image_stats(extract_box_reference(frame, box)); +} + +enum class ListBox{ + HIGHLIGHTED, + PLAIN, + OTHER, +}; + +// A strip at the left end of entry `index`'s box, left of its text and +// right of the cursor's arrow. The boxes are 576 x 84 at 1920 x 1080, the +// columns' left edges at x 347 and 996, the rows' tops 108 apart from +// y 342; the strip is 65 x 54 from 38 right of the edge and 15 down. +ImageFloatBox language_box_strip(size_t index){ + const size_t column = index / LANGUAGE_LIST_ROWS; + const size_t row = index % LANGUAGE_LIST_ROWS; + return ImageFloatBox(column == 0 ? 0.2005 : 0.5365, 0.331 + 0.1 * (double)row, 0.034, 0.05); +} + +// The highlighted box is 255 white, flat; the others slate blue, about +// (54, 60-76, 82-107), each channel's spread under 3. +ListBox classify_list_box(const ImageStats& stats){ + if (stats.count == 0){ + return ListBox::OTHER; + } + const FloatPixel& average = stats.average; + const double spread = stats.stddev.sum(); + if (average.r >= 200 && average.g >= 200 && average.b >= 200 && spread <= 30){ + return ListBox::HIGHLIGHTED; + } + const bool slate = + average.r >= 35 && average.r <= 90 && + average.g >= 45 && average.g <= 110 && + average.b >= 65 && average.b <= 140 && + average.b >= average.r + 15; + if (slate && spread <= 20){ + return ListBox::PLAIN; + } + return ListBox::OTHER; +} + +// The dark blue background between the columns (about (9, 24, 56)). +bool column_gap_dark(const ImageViewRGB32& frame){ + const ImageStats gap = box_stats(frame, ImageFloatBox(0.4896, 0.331, 0.0208, 0.447)); + return gap.count > 0 && brightness(gap) < 70; +} + +// The look picker's tiles are 240 x 240 at 1920 x 1080, their left edges +// at x 373, 685, 997 and 1309, their tops at y 324 and 609. +double look_tile_left(size_t look){ + return (373.0 + 312.0 * (double)((look - 1) % LOOK_COLUMNS)) / 1920; +} +double look_tile_top(size_t look){ + return (look <= LOOK_COLUMNS ? 324.0 : 609.0) / 1080; +} + +// Corner `corner` of look `look`'s tile (0 top left, 1 top right, 2 bottom +// left, 3 bottom right): 12 x 12, 10 in from both edges. The highlighted +// look's white card reaches about 12 past the tile on every side, so the +// patches stay on it while it is enlarged. +ImageFloatBox look_corner_patch(size_t look, size_t corner){ + const double dx = (corner % 2 == 0 ? 10.0 : 218.0) / 1920; + const double dy = (corner < 2 ? 10.0 : 218.0) / 1080; + return ImageFloatBox(look_tile_left(look) + dx, look_tile_top(look) + dy, 12.0 / 1920, 12.0 / 1080); +} + +// The face in the middle of look `look`'s tile: 60 x 60 from 90 right of +// its edge and 100 down. +ImageFloatBox look_face_patch(size_t look){ + return ImageFloatBox(look_tile_left(look) + 90.0 / 1920, look_tile_top(look) + 100.0 / 1080, 60.0 / 1920, 60.0 / 1080); +} + +enum class LookCorner{ + WHITE, + DARK, + OTHER, +}; + +// Measured on the console's look pickers (67 frames in English, German +// and Japanese): the highlighted card's corners (240-248, 245-250, +// 246-251), spread under 17; the others slate or, past a tile's rounded +// corner, the background: (21-34, 29-57, 56-91), spread under 32. +LookCorner classify_look_corner(const ImageStats& stats){ + if (stats.count == 0){ + return LookCorner::OTHER; + } + const FloatPixel& average = stats.average; + const double spread = stats.stddev.sum(); + if (average.r >= 200 && average.g >= 200 && average.b >= 200 && spread <= 40){ + return LookCorner::WHITE; + } + if (brightness(stats) < 90 && average.r <= 50 && average.b >= average.r + 20 && spread <= 50){ + return LookCorner::DARK; + } + return LookCorner::OTHER; +} + +// How many of look `look`'s 4 corners are white; nullopt if the tile is +// not a look picker tile: a corner neither white nor dark, or no face in +// its middle (on the same frames brightness 108-196, spread over 117). +std::optional look_white_corners(const ImageViewRGB32& frame, size_t look){ + const ImageStats face = box_stats(frame, look_face_patch(look)); + if (face.count == 0 || brightness(face) < 80 || face.stddev.sum() < 60){ + return std::nullopt; + } + size_t white = 0; + for (size_t corner = 0; corner < 4; corner++){ + switch (classify_look_corner(box_stats(frame, look_corner_patch(look, corner)))){ + case LookCorner::WHITE: + white++; + break; + case LookCorner::DARK: + break; + case LookCorner::OTHER: + return std::nullopt; + } + } + return white; +} + +// The look picker as read from `frame`: whether it shows, and the look +// highlighted, the one with 4 white corners while the other 7 have none. +struct LookPickerReading{ + bool shows = false; + std::optional highlighted; +}; + +LookPickerReading read_look_picker(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return {}; + } + std::optional card; + size_t lit_tiles = 0; + for (size_t look = 1; look <= LOOK_COUNT; look++){ + const std::optional white = look_white_corners(frame, look); + if (!white){ + return {}; + } + if (*white > 0){ + lit_tiles++; + } + if (*white == 4){ + card = look; + } + } + LookPickerReading reading{.shows = true}; + if (lit_tiles == 1 && card){ + reading.highlighted = card; + } + return reading; +} + +// The number at `text[pos]`, moving `pos` past it; nullopt when no digit +// is there. +std::optional read_digits(std::string_view text, size_t& pos){ + const size_t start = pos; + size_t value = 0; + while (pos < text.size() && text[pos] >= '0' && text[pos] <= '9' && pos - start < 4){ + value = value * 10 + (size_t)(text[pos] - '0'); + pos++; + } + if (pos == start){ + return std::nullopt; + } + return value; +} + +void skip_spaces(std::string_view text, size_t& pos){ + while (pos < text.size() && (text[pos] == ' ' || text[pos] == '\n' || text[pos] == '\r')){ + pos++; + } +} + +// The limit N in a counter's text "0/N"; nullopt for any other text. +std::optional parse_counter(std::string_view text){ + size_t pos = 0; + skip_spaces(text, pos); + if (!read_digits(text, pos)){ + return std::nullopt; + } + skip_spaces(text, pos); + if (pos >= text.size() || text[pos] != '/'){ + return std::nullopt; + } + pos++; + skip_spaces(text, pos); + const std::optional limit = read_digits(text, pos); + skip_spaces(text, pos); + if (!limit || *limit == 0 || pos != text.size()){ + return std::nullopt; + } + return limit; +} + +// `box` of `frame` as black text on white for OCR: the pixels with every +// channel at least `min_channel` are the text. +std::string read_light_text(const ImageViewRGB32& frame, const ImageFloatBox& box, Language language, uint8_t min_channel){ + const uint32_t mins = 0xff000000 | ((uint32_t)min_channel << 16) | ((uint32_t)min_channel << 8) | min_channel; + const ImageRGB32 filtered = to_blackwhite_rgb32_range( + extract_box_reference(frame, box), /*in_range_black=*/true, mins, /*maxs=*/0xffffffff + ); + return OCR::ocr_read(language, filtered); +} + +} // namespace + + +// The title line runs y 215-266 at 1920 x 1080, from the highlighted +// tile's left edge; the tile row's cyan border starts at y 277. The text +// is about (10, 212, 224) on (241, 241, 241). +bool is_home_tile_plza(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return false; + } + const ImageRGB32 filtered = to_blackwhite_rgb32_range( + extract_box_reference(frame, ImageFloatBox(0.02, 205.0 / 1080, 0.96, 67.0 / 1080)), + /*in_range_black=*/true, /*mins=*/0xff009696, /*maxs=*/0xff7fffff + ); + std::string letters; + for (const char ch : OCR::ocr_read(Language::English, filtered)){ + if (std::isalnum((unsigned char)ch)){ + letters += (char)std::tolower((unsigned char)ch); + } + } + return letters.ends_with("za"); +} + +std::optional read_language_list_cursor(const ImageViewRGB32& frame){ + if (!usable(frame) || !column_gap_dark(frame)){ + return std::nullopt; + } + std::optional highlighted; + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + switch (classify_list_box(box_stats(frame, language_box_strip(index)))){ + case ListBox::HIGHLIGHTED: + if (highlighted){ + return std::nullopt; + } + highlighted = index; + break; + case ListBox::PLAIN: + break; + case ListBox::OTHER: + return std::nullopt; + } + } + return highlighted; +} + +std::optional read_look_picker_cursor(const ImageViewRGB32& frame){ + return read_look_picker(frame).highlighted; +} + +bool is_look_picker(const ImageViewRGB32& frame){ + return read_look_picker(frame).shows; +} + +// The question area (x 1056-1824, y 54-184 at 1920 x 1080) is dark and +// flat: 27, spread 3 on all ten languages' keyboards; the intro's other +// screens are 46 or brighter there, or busy. The keys' bottom row +// (y 929-950) averages 205-211; elsewhere 160 at most. +bool is_name_keyboard(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return false; + } + const ImageStats question = box_stats(frame, ImageFloatBox(0.55, 0.05, 0.40, 0.12)); + if (question.count == 0 || brightness(question) > 40 || question.stddev.sum() > 15){ + return false; + } + const ImageStats keys = box_stats(frame, ImageFloatBox(0.03, 0.86, 0.80, 0.02)); + return keys.count > 0 && brightness(keys) >= 185; +} + +// The counter is grey (about 128) on the dark question area: with a +// 12-character field ("0/12") at x 1645-1725, y 325-355; with a 6-character +// one ("0/6") at x 1275-1335, y 355-385 (Japanese) or 340-370 (Korean, +// Chinese, whose keyboards are taller). The field's underline runs just +// above each, so each layout gets its own box. +std::optional read_name_keyboard_limit(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return std::nullopt; + } + const ImageFloatBox boxes[] = { + ImageFloatBox(1625.0 / 1920, 312.0 / 1080, 120.0 / 1920, 53.0 / 1080), + ImageFloatBox(1258.0 / 1920, 345.0 / 1080, 115.0 / 1920, 50.0 / 1080), + ImageFloatBox(1258.0 / 1920, 328.0 / 1080, 115.0 / 1920, 50.0 / 1080), + }; + for (const ImageFloatBox& box : boxes){ + const std::optional limit = parse_counter(read_light_text(frame, box, Language::English, /*min_channel=*/90)); + if (limit){ + return limit; + } + } + return std::nullopt; +} + +// The values right of the "Language" and "Name" labels: white, from x 345; +// the language's row y 400-450, the name's 468-522. +std::string read_confirm_choices_name(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return ""; + } + const std::string text = read_light_text( + frame, ImageFloatBox(340.0 / 1920, 468.0 / 1080, 760.0 / 1920, 54.0 / 1080), Language::English, /*min_channel=*/150 + ); + std::string name; + for (const char ch : text){ + if (ch != ' ' && ch != '\n' && ch != '\r'){ + name += ch; + } + } + return name; +} + +std::string read_confirm_choices_language(const ImageViewRGB32& frame, Language language){ + if (!usable(frame)){ + return ""; + } + return read_light_text( + frame, ImageFloatBox(340.0 / 1920, 400.0 / 1080, 760.0 / 1920, 50.0 / 1080), language, /*min_channel=*/150 + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h new file mode 100644 index 0000000000..9bc37d9a69 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h @@ -0,0 +1,69 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + * Readers of the new game's screens before "Confirm Choices" (whose + * highlight is in PokemonLZA_AutoStoryConfirmChoicesReader.h): the + * language list, the look picker and the Switch's name keyboard, and the + * name and language "Confirm Choices" shows. Measured on the console's + * frames in ten languages (2026-11-13). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H + +#include +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// On the Switch HOME, whether the highlighted tile is PLZA: the title the +// HOME prints above the tile row (cyan) ends in "Z-A", read with OCR +// (English; measured on an English system). False for any other tile or +// frame. +bool is_home_tile_plza(const ImageViewRGB32& frame); + +// On "Which language will you play in?", the highlighted entry (numbered +// down the left column, then down the right one): the one white box of +// the 10, the others slate. Nullopt for any other frame, an empty one +// included. +std::optional read_language_list_cursor(const ImageViewRGB32& frame); + +// On the look picker ("LOOKS"), the look (1 to 8) whose portrait is +// highlighted: the one tile whose 4 corners are on the white card. Nullopt +// while none is (the screen opens so), while the card moves, and for any +// other frame. +std::optional read_look_picker_cursor(const ImageViewRGB32& frame); + +// The look picker's 2 x 4 portraits on dark blue, highlighted or not. +bool is_look_picker(const ImageViewRGB32& frame); + +// The Switch's name keyboard: the dark question area on top, the light +// key panel below. Any of its layouts (Latin, Hangul, Chinese). +bool is_name_keyboard(const ImageViewRGB32& frame); + +// The name keyboard's character limit, read with OCR from its "0/N" +// counter right under the text field (it sits further right with a +// 12-character field). Nullopt when no counter reads as one. +std::optional read_name_keyboard_limit(const ImageViewRGB32& frame); + +// The player name "Confirm Choices" shows, read with OCR (English), its +// spaces dropped. Empty when nothing reads. +std::string read_confirm_choices_name(const ImageViewRGB32& frame); + +// The language "Confirm Choices" shows, read with OCR in `language`. +std::string read_confirm_choices_language(const ImageViewRGB32& frame, Language language); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp new file mode 100644 index 0000000000..72dbabac5c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp @@ -0,0 +1,313 @@ +/* PokemonLZA AutoStory - New game intro screens Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "Tests/ImageUnitTest.h" +#include "PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryIntroScreens_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +std::string describe(std::optional value){ + return value ? std::format("{}", *value) : std::string("none"); +} + +// One console frame and what each reader makes of it. +struct FrameCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; + struct Expectation{ + std::optional language_entry = std::nullopt; + bool look_picker = false; + std::optional look = std::nullopt; + bool keyboard = false; + // The counter's limit; nullopt: not checked (the field holds text). + std::optional name_limit = std::nullopt; + bool home_plza = false; + }; + Expectation expectation; +}; + +const FrameCase FRAME_CASES[] = { + {.name = "language list on English", .input = {.file = "AutoStoryLanguageList/0_en.png"}, .expectation = {.language_entry = 0}}, + {.name = "language list on Espanol (Espana)", .input = {.file = "AutoStoryLanguageList/1_es-ES.png"}, .expectation = {.language_entry = 1}}, + {.name = "language list on Espanol (Latinoamerica)", .input = {.file = "AutoStoryLanguageList/2_es-419.png"}, .expectation = {.language_entry = 2}}, + {.name = "language list on Francais", .input = {.file = "AutoStoryLanguageList/3_fr.png"}, .expectation = {.language_entry = 3}}, + {.name = "language list on Deutsch", .input = {.file = "AutoStoryLanguageList/4_de.png"}, .expectation = {.language_entry = 4}}, + {.name = "language list on Italiano", .input = {.file = "AutoStoryLanguageList/5_it.png"}, .expectation = {.language_entry = 5}}, + {.name = "language list on Japanese", .input = {.file = "AutoStoryLanguageList/6_ja.png"}, .expectation = {.language_entry = 6}}, + {.name = "language list on Korean", .input = {.file = "AutoStoryLanguageList/7_ko.png"}, .expectation = {.language_entry = 7}}, + {.name = "language list on Simplified Chinese", .input = {.file = "AutoStoryLanguageList/8_zh-Hans.png"}, .expectation = {.language_entry = 8}}, + {.name = "language list on Traditional Chinese", .input = {.file = "AutoStoryLanguageList/9_zh-Hant.png"}, .expectation = {.language_entry = 9}}, + {.name = "look picker as it opens", .input = {.file = "AutoStoryLookPicker/English_1_0.png"}, .expectation = {.look_picker = true}}, + {.name = "look picker on look 3", .input = {.file = "AutoStoryLookPicker/English_2_3.png"}, .expectation = {.look_picker = true, .look = 3}}, + {.name = "look picker on look 7", .input = {.file = "AutoStoryLookPicker/German_2_7.png"}, .expectation = {.look_picker = true, .look = 7}}, + {.name = "look picker on look 6 in Japanese", .input = {.file = "AutoStoryLookPicker/Japanese_2_6.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "keyboard in German", .input = {.file = "AutoStoryNameKeyboard/de_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Spanish (Spain)", .input = {.file = "AutoStoryNameKeyboard/es-ES_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Latin American Spanish", .input = {.file = "AutoStoryNameKeyboard/es-419_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in French", .input = {.file = "AutoStoryNameKeyboard/fr_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Italian", .input = {.file = "AutoStoryNameKeyboard/it_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Japanese", .input = {.file = "AutoStoryNameKeyboard/ja_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Korean", .input = {.file = "AutoStoryNameKeyboard/ko_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Simplified Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hans_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Traditional Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hant_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "Confirm Choices is none of them", .input = {.file = "AutoStoryConfirmChoices/German_0.png"}, .expectation = {}}, + // The console's frames of 2026-11-15, one launch per language. + {.name = "2026-11-15: the language list opens on English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_langlist.png"}, .expectation = {.language_entry = 0}}, + {.name = "2026-11-15: the language list on Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_langsel.png"}, .expectation = {.language_entry = 1}}, + {.name = "2026-11-15: the language list on Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_langsel.png"}, .expectation = {.language_entry = 2}}, + {.name = "2026-11-15: the language list on Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_langsel.png"}, .expectation = {.language_entry = 3}}, + {.name = "2026-11-15: the language list on Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_langsel.png"}, .expectation = {.language_entry = 4}}, + {.name = "2026-11-15: the language list on Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_langsel.png"}, .expectation = {.language_entry = 5}}, + {.name = "2026-11-15: the language list on Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_langsel.png"}, .expectation = {.language_entry = 6}}, + {.name = "2026-11-15: the language list on Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_langsel.png"}, .expectation = {.language_entry = 7}}, + {.name = "2026-11-15: the language list on Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_langsel.png"}, .expectation = {.language_entry = 8}}, + {.name = "2026-11-15: the language list on Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_langsel.png"}, .expectation = {.language_entry = 9}}, + {.name = "2026-11-15: the look picker before the stick moves", .input = {.file = "AutoStoryNewGame/2026-11-15/en_look.png"}, .expectation = {.look_picker = true}}, + {.name = "2026-11-15: the look picker after the first tilt in English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_look_hl.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "2026-11-15: the look picker after the first tilt in Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_look_hl.png"}, .expectation = {.look_picker = true, .look = 5}}, + {.name = "2026-11-15: the look picker after the first tilt in Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_look_hl.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "2026-11-15: the look picker after the first tilt in Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_look_hl.png"}, .expectation = {.look_picker = true, .look = 5}}, + {.name = "2026-11-15: the look picker after the first tilt in Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_look_hl.png"}, .expectation = {.look_picker = true, .look = 7}}, + {.name = "2026-11-15: the look picker after the first tilt in Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_look_hl.png"}, .expectation = {.look_picker = true, .look = 2}}, + {.name = "2026-11-15: the look picker after the first tilt in Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_look_hl.png"}, .expectation = {.look_picker = true, .look = 8}}, + {.name = "2026-11-15: the keyboard in English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: Simplified Chinese keeps the keyboard after the first +", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_plus0.png"}, .expectation = {.keyboard = true, .name_limit = std::nullopt}}, + // HOME's tiles in last-played order: FireRed first, Z-A second. + {.name = "2026-11-15: HOME on FireRed's tile", .input = {.file = "AutoStoryNewGame/2026-11-15/home_firered.png"}, .expectation = {}}, + {.name = "2026-11-15: HOME on Z-A's tile", .input = {.file = "AutoStoryNewGame/2026-11-15/home_plza.png"}, .expectation = {.home_plza = true}}, +}; + +class Test_IntroScreenFrame : public ImageUnitTest{ +public: + explicit Test_IntroScreenFrame(const FrameCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + const FrameCase::Expectation& expected = m_test.expectation; + const std::optional entry = read_language_list_cursor(frame); + if (entry != expected.language_entry){ + return std::format("Language list: expected entry {}, read {}.", describe(expected.language_entry), describe(entry)); + } + if (is_look_picker(frame) != expected.look_picker){ + return std::format("Look picker: expected {}, read {}.", expected.look_picker, !expected.look_picker); + } + const std::optional look = read_look_picker_cursor(frame); + if (look != expected.look){ + return std::format("Look picker: expected look {}, read {}.", describe(expected.look), describe(look)); + } + if (is_name_keyboard(frame) != expected.keyboard){ + return std::format("Name keyboard: expected {}, read {}.", expected.keyboard, !expected.keyboard); + } + if (expected.keyboard && expected.name_limit){ + const std::optional limit = read_name_keyboard_limit(frame); + if (limit != expected.name_limit){ + return std::format("Name keyboard: expected a limit of {}, read {}.", describe(expected.name_limit), describe(limit)); + } + } + if (is_home_tile_plza(frame) != expected.home_plza){ + return std::format("HOME tile: expected PLZA {}, read {}.", expected.home_plza, !expected.home_plza); + } + return true; + } + +private: + const FrameCase& m_test; +}; + + +// Confirm Choices' name and language, read with OCR. The console's frames +// were taken with the name "q". +class Test_ConfirmChoicesProfile : public ImageUnitTest{ +public: + Test_ConfirmChoicesProfile() + : ImageUnitTest( + "PokemonLZA::AutoStory - intro screens: Confirm Choices shows the name and language", + {"PokemonLZA/AutoStoryConfirmChoices/English_0.png"} + ) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const std::string name = read_confirm_choices_name(images[0]); + if (name != "q"){ + return std::format("Expected the name \"q\", read \"{}\".", name); + } + const std::string language = read_confirm_choices_language(images[0], Language::English); + if (language.find("English") == std::string::npos){ + return std::format("Expected the language \"English\", read \"{}\".", language); + } + return true; + } +}; + + +// The name keyboard as the Switch's keyboard typer (type_on_system_keyboard()) +// reads it when it opens: the cursor on "1". Every language the program +// types in (Korean is not one). +struct SystemKeyboardCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; +}; + +const SystemKeyboardCase SYSTEM_KEYBOARD_CASES[] = { + {.name = "English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_kb.png"}}, + {.name = "Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_kb.png"}}, + {.name = "Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_kb.png"}}, + {.name = "Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_kb.png"}}, + {.name = "Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_kb.png"}}, + {.name = "Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_kb.png"}}, + {.name = "Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_kb.png"}}, + {.name = "Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_kb.png"}}, + {.name = "Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_kb.png"}}, +}; + +class Test_SystemKeyboardOnNameKeyboard : public ImageUnitTest{ +public: + explicit Test_SystemKeyboardOnNameKeyboard(const SystemKeyboardCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: the system keyboard reader in {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + if (!SystemKeyboardDetector().detect(frame)){ + return std::string("The system keyboard was not detected."); + } + const std::optional cursor = read_system_keyboard_cursor(frame); + if (cursor != SystemKeyboardKey{.row = 0, .col = 0}){ + return std::format( + "Expected the cursor on \"1\" (0, 0), read {}.", + cursor ? std::format("({}, {})", cursor->row, cursor->col) : std::string("none") + ); + } + return true; + } +}; + + +// Confirm Choices after the name "1" was typed and submitted (the console's +// frames of 2026-11-15): its highlight, the name, and for the languages +// English OCR reads, a part of the language's name. +struct ConfirmCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; + struct Expectation{ + std::string name; + std::optional language; + }; + Expectation expectation; +}; + +const ConfirmCase CONFIRM_CASES[] = { + {.name = "English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_confirm.png"}, .expectation = {.name = "1", .language = "English"}}, + {.name = "Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_confirm.png"}, .expectation = {.name = "1", .language = "Espa"}}, + {.name = "Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_confirm.png"}, .expectation = {.name = "1", .language = "Latino"}}, + {.name = "Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_confirm.png"}, .expectation = {.name = "1", .language = "Fran"}}, + {.name = "Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_confirm.png"}, .expectation = {.name = "1", .language = "Deutsch"}}, + {.name = "Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_confirm.png"}, .expectation = {.name = "1", .language = "Italiano"}}, + {.name = "Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "German, one + after the name", .input = {.file = "AutoStoryNewGame/2026-11-15/de_plus0.png"}, .expectation = {.name = "1", .language = "Deutsch"}}, + {.name = "Traditional Chinese, two + after the name", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_plus1.png"}, .expectation = {.name = "1", .language = std::nullopt}}, +}; + +class Test_ConfirmChoicesFrame : public ImageUnitTest{ +public: + explicit Test_ConfirmChoicesFrame(const ConfirmCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: Confirm Choices in {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + if (!read_confirm_choices_cursor(frame)){ + return std::string("Confirm Choices' highlight did not read."); + } + if (is_name_keyboard(frame)){ + return std::string("Read as the name keyboard."); + } + const std::string name = read_confirm_choices_name(frame); + if (name != m_test.expectation.name){ + return std::format("Expected the name \"{}\", read \"{}\".", m_test.expectation.name, name); + } + if (m_test.expectation.language){ + const std::string language = read_confirm_choices_language(frame, Language::English); + if (language.find(*m_test.expectation.language) == std::string::npos){ + return std::format("Expected the language to have \"{}\", read \"{}\".", *m_test.expectation.language, language); + } + } + return true; + } + +private: + const ConfirmCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryIntroScreens(UnitTestDatabase& database){ + for (const FrameCase& test : FRAME_CASES){ + database.add(test); + } + database.add(); + for (const SystemKeyboardCase& test : SYSTEM_KEYBOARD_CASES){ + database.add(test); + } + for (const ConfirmCase& test : CONFIRM_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h new file mode 100644 index 0000000000..803a8cb509 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h @@ -0,0 +1,27 @@ +/* PokemonLZA AutoStory - New game intro screens Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the intro screen readers' tests on the console's frames +// (PokemonLZA/AutoStoryLanguageList/, AutoStoryLookPicker/, +// AutoStoryNameKeyboard/ and AutoStoryConfirmChoices/ in the test images). +void add_tests_AutoStoryIntroScreens(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 23ca46fd4e..c5e556db15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -14,7 +15,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Pokemon_Strings.h" -#include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" +#include "Actions/PokemonLZA_AutoStoryNewGame.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStory.h" @@ -32,8 +33,9 @@ AutoStory_Descriptor::AutoStory_Descriptor() std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", "Play the main story of Pokemon Legends: Z-A. Prototype: from a new game to the end of Main Mission 01, picking Chikorita. " - "Start a new game and pick its language, look and name by hand: checkpoint 01.00 starts on the Confirm Choices screen that follows. " - "It checks that screen, presses nothing anywhere else, and picks Ready!. Later checkpoints load the latest save first, unless that is turned off.", + "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen (its tile among the first 8; a running game is closed), " + "from the language list, or from Confirm Choices, with the language, look and name below. " + "Later checkpoints load the latest save first, unless that is turned off.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, @@ -68,12 +70,40 @@ void check_checkpoint_range(ConsoleHandle& console, size_t first, size_t last, s } } +// The game language dropdown's entries, in the language list's order. +const EnumDropdownDatabase& new_game_language_database(){ + static const EnumDropdownDatabase database{ + {NewGameLanguage::English, "en", "English"}, + {NewGameLanguage::SpanishSpain, "es-ES", "Espa\xc3\xb1ol (Espa\xc3\xb1" "a)"}, + {NewGameLanguage::SpanishLatinAmerica, "es-419", "Espa\xc3\xb1ol (Latinoam\xc3\xa9rica)"}, + {NewGameLanguage::French, "fr", "Fran\xc3\xa7" "ais"}, + {NewGameLanguage::German, "de", "Deutsch"}, + {NewGameLanguage::Italian, "it", "Italiano"}, + {NewGameLanguage::Japanese, "ja", "Japanese"}, + {NewGameLanguage::Korean, "ko", "Korean (not supported yet)"}, + {NewGameLanguage::ChineseSimplified, "zh-Hans", "Chinese (Simplified)"}, + {NewGameLanguage::ChineseTraditional, "zh-Hant", "Chinese (Traditional)"}, + }; + return database; +} + +// Throws UserSetupError, before any press, if a run from `first_row` plays +// a new game that `choices` cannot. +void check_new_game_choices(ConsoleHandle& console, const StoryCheckpoint& first_row, const NewGameChoices& choices){ + if (!story_row_starts_without_save(first_row)){ + return; + } + if (const std::optional problem = new_game_problem(choices)){ + throw UserSetupError(console, *problem); + } +} + // Connects the controller for a run from `first_row`. 01.00 starts on a // screen that proves the save is fresh, so it is checked before any press, // the connect press included. void connect_controller(ConsoleHandle& console, ProControllerContext& context, const StoryCheckpoint& first_row){ if (story_row_starts_without_save(first_row)){ - require_confirm_choices(console, context); + require_new_game_start(console, context); } require_player(console, context, BUTTON_L); } @@ -83,6 +113,25 @@ void connect_controller(ConsoleHandle& console, ProControllerContext& context, c AutoStory::AutoStory() : RANGE("Checkpoints", checkpoint_database()) + , GAME_LANGUAGE( + "Game Language:
01.00 picks it on the new game's language list.", + new_game_language_database(), + LockMode::LOCK_WHILE_RUNNING, + NewGameLanguage::English + ) + , PLAYER_LOOK( + "Player Look:
01.00 picks it on the look picker: 1 to 4 along the top row, 5 to 8 along the bottom.", + LockMode::LOCK_WHILE_RUNNING, + 1, 1, 8 + ) + , PLAYER_NAME( + /*is_password=*/false, "Player Name:
Letters, digits and - / : ' , . ? ! (the keyboard's first page); at most 12 characters, 6 in Japanese and Chinese.", + LockMode::LOCK_WHILE_RUNNING, /*default_value=*/"Kosmos", /*placeholder_text=*/"Kosmos" + ) + , CAPTURE_INTRO_SCREENS( + "Developer: capture intro screens:
A separate collection mode, not a capture during a run: it ignores Game Language and, for each of the ten languages in turn (English first), closes the game, launches it from HOME and saves its screens up to the name keyboard to the Screenshots folder. Nothing is typed, so no save is made.", + LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false + ) , ATTEMPTS_PER_CHECKPOINT( "Attempts per Checkpoint:
A failed checkpoint that started from a save reloads it and tries again, up to this many times in all.", LockMode::LOCK_WHILE_RUNNING, @@ -102,6 +151,10 @@ AutoStory::AutoStory() }) { PA_ADD_OPTION(RANGE); + PA_ADD_OPTION(GAME_LANGUAGE); + PA_ADD_OPTION(PLAYER_LOOK); + PA_ADD_OPTION(PLAYER_NAME); + PA_ADD_OPTION(CAPTURE_INTRO_SCREENS); PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); PA_ADD_OPTION(LOAD_SAVE_FIRST); PA_ADD_OPTION(BATTLE_AI); @@ -110,14 +163,21 @@ AutoStory::AutoStory() } void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + if (CAPTURE_INTRO_SCREENS){ + require_player(env.console, context, BUTTON_L); + capture_intro_screens(env.console, context, PLAYER_LOOK); + return; + } + const NewGameChoices new_game{.language = GAME_LANGUAGE, .look = PLAYER_LOOK, .name = PLAYER_NAME}; const StoryData& story_data = builtin_story_data(); const std::vector& rows = story_data.checkpoints; const size_t first = RANGE.start_index(); const size_t last = RANGE.end_index(); check_checkpoint_range(env.console, first, last, rows.size()); + check_new_game_choices(env.console, rows[first], new_game); connect_controller(env.console, context, rows[first]); - StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI}; + StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI, .new_game = new_game}; PlzaConsoleBackend backend(story); AutosaveSightings sightings; const StoryGame game = make_plza_story_game(story, story_data, sightings); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index f140022d0f..8da8039099 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -12,12 +12,15 @@ #define PokemonAutomation_PokemonLZA_AutoStory_H #include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" +#include "Common/Cpp/Options/StringOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -42,6 +45,10 @@ class AutoStory : public SingleSwitchProgramInstance{ private: Pokemon::StoryRangeOptions RANGE; + EnumDropdownOption GAME_LANGUAGE; + SimpleIntegerOption PLAYER_LOOK; + StringOption PLAYER_NAME; + BooleanCheckBoxOption CAPTURE_INTRO_SCREENS; SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; BooleanCheckBoxOption LOAD_SAVE_FIRST; BattleAIOption BATTLE_AI; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index 4fe02f79e5..771b80ad3d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -23,6 +23,7 @@ #include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h" @@ -42,6 +43,8 @@ struct StoryEnv{ SingleSwitchProgramEnvironment& env; ProControllerContext& context; BattleAIOption& battle_ai; + // 01.00's new game: the language, look and name to pick. + NewGameChoices new_game = {}; }; // The engine's backend for PLZA's pose. diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index d9fb3e1b9a..188596b30e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -18,17 +19,21 @@ #include "CommonFramework/Exceptions/OperationFailedException.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h" +#include "VideoGames/PokemonLZA/PokemonLZA_Settings.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_MenuNavigation.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h" #include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStorySceneMachine.h" +#include "PokemonLZA_AutoStoryTable.h" #include "PokemonLZA_AutoStoryGame.h" namespace PokemonAutomation{ @@ -49,6 +54,10 @@ using Handler = Pokemon::StoryActionHandler; namespace{ +// After a reload reaches the overworld, before the first look: the wait +// reset_game_from_home() takes by default. +constexpr Milliseconds RELOAD_SETTLE = 1000ms; + StoryActionSpec game_spec(std::string name, std::vector args = {}){ return StoryActionSpec{.kind = StoryStepKind::GAME, .name = std::move(name), .args = std::move(args)}; @@ -77,6 +86,7 @@ StoryActionSpec console_only(StoryActionSpec spec){ // The GAME actions that run only on a console. std::vector console_specs(){ return { + console_only(game_spec("new_game_intro")), console_only(game_spec("confirm_new_game")), console_only(game_spec("run_to_gate", { optional_ms("timeout_ms", 8000, "running this long with no A prompt fails the step"), @@ -110,7 +120,7 @@ std::vector make_specs(){ }, StoryArgSpec{ .key = "end", .type = StoryArgType::WORD, .required = false, .fallback = std::nullopt, - .why = "\"fade_white\", \"fade_black\" or \"dialog\": the last leg is held until it shows, its ms the bound", + .why = "\"fade_white\", \"fade_black\", \"dialog\" or \"prompt\" (an A prompt): the last leg is held until it shows, its ms the bound", }, flag("held", "hold the stick at each leg's angle (L only before a later turning leg), not tap-and-forward"), optional_int("wait_ms", "wait this long before looking for free control: NPCs moving off"), @@ -145,32 +155,38 @@ std::vector make_specs(){ } -// The game onto its latest save by reset_game_from_home(). Fails as -// "launch_failed". +// The game onto its latest save: PLZA launched by launch_plza_from_home() +// (its own tile, whichever game ran), then reset_game_from_home()'s title +// and load. Fails as "launch_failed". Outcome reload_latest_save(StoryEnv& env){ - go_home(env.env.console, env.context); - if (!reset_game_from_home(env.env, env.env.console, env.context, /*backup_save=*/false)){ + ConsoleHandle& console = env.env.console; + launch_plza_from_home(console, env.context); + const bool loaded = + openedgame_to_gamemenu(console, env.context, GameSettings::instance().START_GAME_WAIT) && + gamemenu_to_ingame(console, env.context, GameSettings::instance().ENTER_GAME_WAIT0); + if (!loaded){ return Pokemon::outcome_failed("launch_failed", "the game did not reach the overworld after the reload"); } + env.context.wait_for(RELOAD_SETTLE); return Pokemon::outcome_ok(); } -// "confirm_new_game" on the console `env`; none: fails as console_only. -// An OperationFailedException becomes a failed Outcome, so the run can -// report it. -Handler confirm_handler(StoryEnv* env){ +// 01.00's new game step `name` on the console `env`, running `step`; +// none: fails as console_only. An OperationFailedException becomes a +// failed Outcome, so the run can report it. +Handler new_game_handler(StoryEnv* env, std::string name, std::function step){ if (env == nullptr){ - return [](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ - return Pokemon::outcome_failed(std::string(Pokemon::CONSOLE_ONLY), "confirm_new_game runs only on a console"); + return [name](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ + return Pokemon::outcome_failed(std::string(Pokemon::CONSOLE_ONLY), name + " runs only on a console"); }; } - return [env](Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + return [env, name, step](Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ try{ - confirm_new_game_choices(env->env.console, env->context); + step(*env); }catch (OperationFailedException& e){ - backend.log(std::format("[PLZA] confirm_new_game failed: {}", e.message())); - return Pokemon::outcome_failed("confirm_new_game_failed", e.message()); + backend.log(std::format("[PLZA] {} failed: {}", name, e.message())); + return Pokemon::outcome_failed(name + "_failed", e.message()); } return Pokemon::outcome_ok(); }; @@ -457,8 +473,8 @@ Outcome walk_step(Pokemon::StoryBackend& backend, const StoryActionCal } -// "mash_to_move_hints": A through the scenes (a choice takes its top -// row, the advance chevron its text) until the player has control: the +// "mash_to_move_hints": through the scenes (B at a text box, A at a +// choice's top row and the advance chevron) until the player has control: the // controls hint or the party bar held a second, an A prompt ("A Talk") // held a second past "min_length_ms" (01.02's battle area: only the // prompt to Ryon, and A there restarts his talk), or a main mission's @@ -510,7 +526,8 @@ Outcome text_to_choice_step(Pokemon::StoryBackend& backend, const Stor } -// A step's scene ("scene" "a"): A through its text until the party bar +// A step's scene ("scene" "a"): B through its text (A at a choice; B +// cannot talk again once the text ends) until the party bar // holds a second, 120 s at most; a cutscene with no text and no HUD is // waited out. Fails as "scene_never_started" when the HUD shows 45 s with // no text, choice, battle or cutscene: the player is not at the scene's @@ -537,8 +554,12 @@ Outcome battle_start_step(Pokemon::StoryBackend& backend, const StoryA return run_scene_machine(backend, "story_battle_start", config, 90s); } -// "story_battle": the battle on screen, by the backend's battle code. +// "story_battle": the backend's battle code, on the battle HUD within 10 s; +// else "battle_never_started" (03.02b looked 2 min on the overworld, 2026-11-16). Outcome battle_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + if (!event_shows_within(backend, ScreenEvent::BATTLE_STARTED, 10s)){ + return Pokemon::outcome_failed("battle_never_started", "no battle HUD within 10 s"); + } return backend.battle(); } @@ -568,18 +589,31 @@ Outcome pokedex_step(Pokemon::StoryBackend& backend, const StoryAction } -// After A at what the player faces, how long "talk" waits for its text -// box, and how often it looks. +// How long "talk" looks for its A prompt before A, how long it waits for +// its scene to start after A, and how often it looks. +constexpr Milliseconds TALK_PROMPT_WAIT(1000); constexpr Milliseconds TALK_WAIT(5000); constexpr Milliseconds TALK_POLL(250); -// "talk": A at what the player faces, then a text box within TALK_WAIT; -// fails as "talk_no_text" without one. +// "talk": on the A prompt of what the player faces, A, then its scene +// under way (scene_under_way(): Taunie's opens on a card, 03.02b) on two +// looks in a row within TALK_WAIT, not one look of the press itself. No +// prompt within TALK_PROMPT_WAIT: nothing pressed, "talk_no_prompt" (the +// walk stopped short, 03.02, 2026-11-16); nothing after A: "talk_no_scene". Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + if (!event_shows_within(backend, ScreenEvent::INTERACT_PROMPT, TALK_PROMPT_WAIT)){ + return Pokemon::outcome_failed( + "talk_no_prompt", std::format("no A prompt within {} ms: not at what the talk is for", TALK_PROMPT_WAIT.count()) + ); + } backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); + size_t scene_looks = 0; for (Milliseconds waited(0); ; waited += TALK_POLL){ backend.scope().throw_if_cancelled(); - if (backend.observe().events.has(ScreenEvent::DIALOG_BOX)){ + const Pokemon::Observation look = backend.observe(); + scene_looks = scene_under_way(look) ? scene_looks + 1 : 0; + if (scene_looks >= 2){ + backend.log_detail(std::format("[PLZA] talk: started {} ms after A: {}", waited.count(), describe_scene_look(look))); return Pokemon::outcome_ok(); } if (waited >= TALK_WAIT){ @@ -587,7 +621,7 @@ Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCal } backend.wait(TALK_POLL); } - return Pokemon::outcome_failed("talk_no_text", std::format("no text box within {} ms of A", TALK_WAIT.count())); + return Pokemon::outcome_failed("talk_no_scene", std::format("nothing started within {} ms of A: the HUD stayed", TALK_WAIT.count())); } @@ -677,8 +711,15 @@ const std::map& step_functions(){ // The handler of each of plza_story_specs(), by name. Handler plza_handler(StoryEnv* env, const StoryActionSpec& spec){ + if (spec.name == "new_game_intro"){ + return new_game_handler(env, spec.name, [](StoryEnv& story){ + play_new_game_intro(story.env.console, story.context, story.new_game); + }); + } if (spec.name == "confirm_new_game"){ - return confirm_handler(env); + return new_game_handler(env, spec.name, [](StoryEnv& story){ + confirm_new_game_choices(story.env.console, story.context, story.new_game); + }); } if (spec.name == "run_to_gate"){ return gate_run_handler(env); @@ -739,9 +780,14 @@ std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpo } const std::string* word = std::get_if(&end->second); if (word == nullptr || !walk_end_event(*word)){ - errors.push_back(std::format("{} {}: \"end\" must be \"fade_white\", \"fade_black\" or \"dialog\"", checkpoint.id, step.name)); + errors.push_back(std::format( + "{} {}: \"end\" must be \"fade_white\", \"fade_black\", \"dialog\" or \"prompt\"", checkpoint.id, step.name + )); } } + for (const std::string& error : story_row_lead_in_errors(checkpoint)){ + errors.push_back(std::format("{} {}", checkpoint.id, error)); + } return errors; } @@ -755,6 +801,9 @@ std::optional walk_end_event(std::string_view end){ if (end == "dialog"){ return ScreenEvent::DIALOG_BOX; } + if (end == "prompt"){ + return ScreenEvent::INTERACT_PROMPT; + } return std::nullopt; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 6195399ff1..a920f00bee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -37,20 +37,25 @@ namespace PokemonLZA{ // Every action a PLZA checkpoint may name, GAME actions but for "talk": // -// "confirm_new_game" console_only: 01.00's first step, on the new -// game's "Confirm Choices" (confirm_new_game_choices()) +// "new_game_intro" console_only: 01.00's first step, from HOME or +// the language list to "Confirm Choices" +// (play_new_game_intro()) +// "confirm_new_game" console_only: on the new game's "Confirm +// Choices" (confirm_new_game_choices()) // "opening_to_platform" the opening cutscene until the autosave badge // has shown and the station platform holds // "wait_for_platform" the station platform holds: a start check // "walk" args "legs", [[turn, ms], ...] as // story_walk_move() reads them, "held", // "wait_ms", and "end", -// "fade_white", "fade_black" or "dialog"; +// "fade_white", "fade_black", "dialog" or +// "prompt" (an A prompt); // walked once the screen shows free control // (check_can_walk()), until its end event if it // has one (walk_until()), else until its legs // have run (finish_walk()) -// "mash_to_move_hints" A through scenes until the player has control +// "mash_to_move_hints" B through scenes' text (A at a choice) until +// the player has control // (run_scene_machine()): 01.01's arrival; args // "min_length_ms", no quiet failure before it, // "quiet_ms", "quiet_is_control" and @@ -62,15 +67,23 @@ namespace PokemonLZA{ // "choose_0", "choose_1" that row of the choice box on screen (0 the // top), by the D-pad from the highlighted row, // then A -// "talk" (TALK) A at what the player faces, then its text box -// "a" (MASH, "scene") A through a scene until control; it must +// "talk" (TALK) on the A prompt of what the player faces +// (none: nothing pressed, "talk_no_prompt"), +// A, then its scene under way +// (scene_under_way(): text, a subtitle, a +// card, a fade or a textless cutscene) +// "a" (MASH, "scene") B through a scene's text (A at a choice) +// until control; it must // start within 45 s // "story_battle_start" A through the talk before a story battle and // the battle tutorial's cards until the battle // HUD (run_scene_machine()) -// "story_battle" the battle, by the backend's battle() -// "talk_through_map_screen" A and B in turn through Taunie's talk -// and the first map (03.02) +// "story_battle" the battle, by the backend's battle(), on +// the battle HUD within 10 s, else +// "battle_never_started"; right after +// "story_battle_start" (the lint) +// "talk_through_map_screen" A on Taunie's talk and the Map & +// Missions card, B on the first map (03.02b) // "climb_ladder" the side street's ladder (03.03) // "talk_to_pokedex_screen" B through the nurse's talk and the // Pokedex app (03.04) @@ -90,11 +103,13 @@ namespace PokemonLZA{ const std::vector& plza_story_specs(); // What is wrong with `checkpoint` for PLZA's engine -// (StoryActionRegistry::lint), then with a walk's "end". +// (StoryActionRegistry::lint), then with a walk's "end", then a talk not +// right after a step that ends on its A prompt (a walk to "prompt", or +// "walk_to_prompt"): a talk never presses A blind. std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpoint); -// The event a walk's "end" arg names: "fade_white", "fade_black" or -// "dialog". None for any other word. +// The event a walk's "end" arg names: "fade_white", "fade_black", +// "dialog" or "prompt" (INTERACT_PROMPT). None for any other word. std::optional walk_end_event(std::string_view end); // PLZA as a StoryGame on the console `env`, which must outlive it, as must diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index 23652e3de2..8c0755ab30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -70,8 +70,8 @@ const StoryDataCase STORY_DATA_CASES[] = { "01.00:new_game:autosave 01.01:from_save:unverified 01.02:from_save:unverified 01.03:from_save:unverified " "02.01:from_save:unverified 02.02:from_save:unverified 02.03:from_save:unverified 02.04:from_save:unverified " "02.05:from_save:unverified 02.06:from_save:autosave 02.07:from_save:unverified " - "03.01:from_save:unverified 03.02:from_save 03.03:from_save:autosave 03.04:from_save " - "03.05:from_save:autosave 03.06:from_save 03.07:from_save:autosave 03.08:from_save:autosave 03.08b:from_save " + "03.01:from_save:unverified 03.02:from_save:autosave 03.02b:from_save 03.03:from_save:autosave 03.04:from_save:autosave " + "03.05:from_save:autosave 03.06:from_save:autosave 03.07:from_save:autosave 03.08:from_save:autosave 03.08b:from_save " "03.09:from_save:unverified " "03.10:from_save:autosave 03.11:from_save:unverified" }, @@ -103,6 +103,8 @@ UnitTestResult check_story_data(const StoryDataCase& test){ struct LintCase{ std::string name; struct Input{ + // The steps before `step` in its checkpoint. + std::vector before = {}; StoryStep step; }; Input input; @@ -126,13 +128,105 @@ const LintCase LINT_CASES[] = { .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { {"legs", std::vector{{.turn = 0, .walk = Milliseconds(4500)}}}, {"end", std::string("sideways")}, }}}, - .expectation = {.errors = "01.01 w: \"end\" must be \"fade_white\", \"fade_black\" or \"dialog\""}, + .expectation = {.errors = "01.01 w: \"end\" must be \"fade_white\", \"fade_black\", \"dialog\" or \"prompt\""}, }, { - .name = "a talk with no action passes", - .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, + .name = "a walk to an A prompt passes", + .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, {"end", std::string("prompt")}, + }}}, + .expectation = {.errors = ""}, + }, + { + .name = "a talk after a walk to its A prompt passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, {"end", std::string("prompt")}, + }}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + .name = "a talk after walk_to_prompt passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + // console B, 2026-11-16: 03.02's timed walk to Taunie stopped + // short of her, and the talk's A found no one. + .name = "a talk after a timed walk fails", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, + }}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .expectation = {.errors = "01.01 t: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)"}, + }, + { + .name = "a story battle after story_battle_start passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "s", .why = "", .action = "story_battle_start", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::GAME, .name = "b", .why = "", .action = "story_battle", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + // console B, 2026-11-16 (03.02b run 2): the battle ran right after + // the talk, with no battle on screen. + .name = "a story battle right after a talk fails", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::GAME, .name = "b", .why = "", .action = "story_battle", .args = {}}, + }, + .expectation = {.errors = "01.01 b: a story battle must follow story_battle_start, which ends on the battle HUD"}, + }, + { + .name = "a scene after a talk passes", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s", .why = "", .action = "a", .args = {}}, + }, .expectation = {.errors = ""}, }, + { + // console B, 2026-11-16: 03.04's talk_to_pokedex_screen played the + // nurse's wrap-up and Taunie's scene to control, and the scene step + // after it waited 45 s on the party bar for a scene already played. + .name = "a scene after talk_to_pokedex_screen fails", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "p", .why = "", .action = "talk_to_pokedex_screen", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s", .why = "", .action = "a", .args = {}}, + }, + .expectation = {.errors = "01.01 s: a scene must follow what starts it, not talk_to_pokedex_screen, which plays its scenes through to control"}, + }, + { + .name = "a scene after a scene fails", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + {.kind = Pokemon::StoryStepKind::MASH, .name = "s1", .why = "", .action = "a", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s2", .why = "", .action = "a", .args = {}}, + }, + .expectation = {.errors = "01.01 s2: a scene must follow what starts it, not a, which plays its scenes through to control"}, + }, + { + .name = "a checkpoint's first step cannot be a talk", + .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, + .expectation = {.errors = "01.01 t: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)"}, + }, { .name = "an action PLZA does not have fails", .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "m", .why = "", .action = "choose_7", .args = {}}}, @@ -144,6 +238,7 @@ UnitTestResult check_lint(const LintCase& test){ StoryCheckpoint checkpoint; checkpoint.id = "01.01"; checkpoint.title = "Test"; + checkpoint.steps = test.input.before; checkpoint.steps.push_back(test.input.step); const std::string got = joined(plza_story_lint(checkpoint), "; "); if (got != test.expectation.errors){ @@ -250,13 +345,18 @@ struct RunCase{ const RunCase RUN_CASES[] = { { - .name = "01.00 stops at Confirm Choices off a console", + .name = "01.00 stops at the new game off a console", .input = {.checkpoint = "01.00", .first_step = 0, .looks = {CUTSCENE}}, + .expectation = {.verdict = "failed at new_game: console_only", .inputs = ""}, + }, + { + .name = "01.00 stops at Confirm Choices off a console", + .input = {.checkpoint = "01.00", .first_step = 1, .looks = {CUTSCENE}}, .expectation = {.verdict = "failed at confirm: console_only", .inputs = ""}, }, { .name = "01.00's opening ends on the platform after the autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {CUTSCENE, PLATFORM, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {CUTSCENE, PLATFORM, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = { .verdict = "done", .inputs = "wait 300ms, wait 300ms, wait 300ms, wait 300ms, wait 300ms", @@ -265,12 +365,12 @@ const RunCase RUN_CASES[] = { }, { .name = "01.00's opening presses A once for the text waiting for it", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {TEXT_FOR_A, TEXT_FOR_A, AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {TEXT_FOR_A, TEXT_FOR_A, AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = {.verdict = "done", .inputs = "press A, wait 300ms, wait 300ms, wait 300ms, wait 300ms"}, }, { .name = "01.00's opening fails with no autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {PLATFORM}}, .expectation = {.verdict = "failed at opening: platform_not_seen"}, }, { @@ -375,7 +475,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, press A, wait 250ms, wait 250ms, wait 500ms, wait 500ms, wait 250ms, wait 500ms", + .inputs = "press B, wait 250ms, wait 250ms, press B, wait 250ms, wait 250ms, wait 500ms, wait 500ms, wait 250ms, wait 500ms", .line = "[PLZA mash_to_move_hints] done on fade_settled.", }, }, @@ -396,7 +496,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, wait 500ms, wait 250ms, press A, wait 500ms", + .inputs = "press B, wait 250ms, wait 250ms, wait 500ms, wait 250ms, press B, wait 500ms", .line = "[PLZA mash_to_move_hints] the mission banner did not show (the detector may have missed it).", }, }, @@ -415,7 +515,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, wait 250ms, wait 250ms", + .inputs = "press B, wait 250ms, wait 250ms, wait 250ms, wait 250ms", .line = "[PLZA mash_to_move_hints] done on controls_hint.", }, }, @@ -429,7 +529,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms", + .inputs = "press B, wait 250ms, wait 250ms", .line = "[PLZA mash_to_move_hints] done on controls_hint.", }, }, @@ -443,12 +543,12 @@ const RunCase RUN_CASES[] = { }, { .name = "01.00's autosave badge is logged in the step it shows in", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {CUTSCENE, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {CUTSCENE, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 0.0s in opening"}, }, { .name = "01.00 ends on its autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = {.verdict = "done", .line = "[Save] 01.00: the game autosaved (seen)"}, }, { @@ -496,22 +596,42 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[Save] 01.02: not saved (save unverified)"}, }, { - .name = "01.03 walks to Chikorita: a turn left, then 750 ms", - .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = {look(/*events=*/{}, {CONTROLS_HINT_READING})}}, + .name = "01.03 walks to Chikorita: a turn left, then on to its A prompt", + .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(5, look(/*events=*/{}, {CONTROLS_HINT_READING})), {A_PROMPT} + )}, .expectation = { .verdict = "done", - .inputs = "wait 250ms, press L, stick -70deg 150ms walk, release 100ms, press L, hold north 750ms walk", + .inputs = "wait 250ms, press L, stick -70deg 150ms walk, release 100ms, press L, hold north 250ms walk, hold north 250ms walk", + .line = "[PLZA] approach_starter: the end event after 500 ms of the last leg.", }, }, { - .name = "01.03's talk to the starter: A, then the text box", - .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {CUTSCENE, DIALOG}}, + .name = "01.03's walk to Chikorita fails with no A prompt in its 750 ms", + .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = {look(/*events=*/{}, {CONTROLS_HINT_READING})}}, + .expectation = {.verdict = "failed at approach_starter: walk_no_end"}, + }, + { + .name = "01.03's talk to the starter: A at its prompt, then the text box", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, DIALOG}}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { - .name = "01.03's talk fails when no text box shows", - .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {CUTSCENE}}, - .expectation = {.verdict = "failed at talk_to_starter: talk_no_text"}, + .name = "01.03's talk fails when nothing starts after A: the prompt stays", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT}}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, + }, + { + // console B, 2026-11-16 (03.02b run 2): the talk counted as + // started 0.4 s after A, and no battle followed. + .name = "a talk does not start on one moving look that the party bar follows", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, CUTSCENE, party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, + }, + { + .name = "a talk fails when the party bar stays after A", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, }, { .name = "01.03's battle start: A through the talk and the tutorial card, done on the battle HUD", @@ -531,6 +651,13 @@ const RunCase RUN_CASES[] = { .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {BATTLE_HUD}}, .expectation = {.verdict = "done", .inputs = "battle"}, }, + { + // console B, 2026-11-16 (03.02b run 2): the battle code looked for + // a battle for 2 min on the overworld. + .name = "a story battle with no battle HUD in 10 s fails as battle_never_started, the battle code not run", + .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at andi_battle: battle_never_started", .inputs = repeated("wait 250ms", 40)}, + }, { .name = "01.03's battle fails as the backend's battle does", .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {BATTLE_HUD}, @@ -548,7 +675,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, press A, wait 250ms", + .inputs = "press B, press A, wait 250ms", .line = "[Save] 01.03: not saved (save unverified)", }, }, @@ -561,11 +688,11 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "02.01's scene after Brigitte: A at the text, done on the party bar held a second, not saved", + .name = "02.01's scene after Brigitte: B at the text, done on the party bar held a second, not saved", .input = {.checkpoint = "02.01", .first_step = 3, .looks = { look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), party_bar(Milliseconds(500)), party_bar(Milliseconds(1600)), }}, - .expectation = {.verdict = "done", .inputs = "press A, wait 250ms", .line = "[Save] 02.01: not saved (save unverified)"}, + .expectation = {.verdict = "done", .inputs = "press B, wait 250ms", .line = "[Save] 02.01: not saved (save unverified)"}, }, { // console B, 2026-11-13: 02.02 after the Brigitte battle walked @@ -594,7 +721,24 @@ const RunCase RUN_CASES[] = { A_PROMPT, BLACK_FADE, look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(1000)), party_bar(Milliseconds(1500)), party_bar(Milliseconds(2600)), }}, - .expectation = {.verdict = "done", .inputs = "press A, wait 250ms, press A, wait 250ms"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms, press B, wait 250ms"}, + }, + { + .name = "02.04's walk to the clerk: along the counter, then the turn to her A prompt", + .input = {.checkpoint = "02.04", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(6, party_bar(Milliseconds(0))), {A_PROMPT} + )}, + .expectation = { + .verdict = "done", + .inputs = "wait 250ms, press L, stick -5deg 150ms walk, release 100ms, press L, hold north 2500ms walk, " + "press L, stick -85deg 150ms walk, release 100ms, press L", + .line = "[PLZA] to_front_counter: the end event after the last turn.", + }, + }, + { + .name = "02.04's walk to the clerk fails with no A prompt after its last turn", + .input = {.checkpoint = "02.04", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at to_front_counter: walk_no_end"}, }, { .name = "02.05's elevator: A through its line to the floor choice", @@ -618,10 +762,17 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 500ms", + .inputs = "press B, wait 500ms", .line = "[PLZA mash_to_move_hints] done: quiet, taken as control.", }, }, + { + .name = "02.06 holds the stick at 45 degrees to the bed's A prompt", + .input = {.checkpoint = "02.06", .first_step = 0, .steps = 1, .looks = { + party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), A_PROMPT, + }}, + .expectation = {.verdict = "done", .inputs = "wait 250ms, stick 45deg 250ms walk, stick 45deg 250ms walk"}, + }, { .name = "02.06 with no autosave badge seen is not saved", .input = {.checkpoint = "02.06", .first_step = 4, .looks = { @@ -649,31 +800,148 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 1.0s in wake_up"}, }, { - .name = "03.02's map talk: A and B in turn, done on the party bar held a second", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b walks on to the plaza scene's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(4, party_bar(Milliseconds(0))), {A_PROMPT} + )}, + .expectation = { + .verdict = "done", + .inputs = "wait 250ms, hold north 250ms walk, hold north 250ms walk", + .line = "[PLZA] to_plaza_scene_prompt: the end event after 500 ms of the last leg.", + }, + }, + { + .name = "03.02b's walk to the plaza scene fails with no A prompt within its bound", + .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at to_plaza_scene_prompt: walk_no_end"}, + }, + { + // console B, 2026-11-16 (run 3): the first prompt from the reload + // spot starts a scene (a fade, the Smart Rotom card, a fade) that + // hands control back at the arch, Taunie a few steps ahead. + .name = "03.02b's plaza scene: A at its prompt, through the fades, done on the party bar held a second", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + A_PROMPT, BLACK_FADE, + look({ScreenEvent::SCREEN_STILL}, /*readings=*/{}, Milliseconds(1000)), + look({ScreenEvent::FADE_BLACK}, /*readings=*/{}, Milliseconds(11200)), + party_bar(Milliseconds(11800)), party_bar(Milliseconds(12900)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA mash_to_move_hints] done on can_move."}, + }, + { + .name = "03.02b walks on from the arch to Taunie's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 2, .steps = 1, .looks = {party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), A_PROMPT}}, + .expectation = {.verdict = "done", .inputs = "hold north 250ms walk, hold north 250ms walk"}, + }, + { + // console B, 2026-11-16: the walk stopped short of Taunie, under + // the Quartiere Verde arch, and the talk's A found no one. + .name = "03.02b's talk presses nothing without Taunie's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = { + .verdict = "failed at talk_to_taunie: talk_no_prompt", + .inputs = "wait 250ms, wait 250ms, wait 250ms, wait 250ms", + }, + }, + { + // console B, 2026-11-16: A at Taunie dimmed the screen into a + // "Smart Rotom" card, with no text box: her talk had started. + .name = "03.02b's talk to Taunie starts on a tutorial card with no text box", + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = { + A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {TUTORIAL_CARD_READING}), + }}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + }, + { + .name = "03.02b's talk to Taunie starts on a subtitle: the advance chevron with no text box", + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = { + A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {ADVANCE_ARROW_READING}), + }}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + }, + { + .name = "03.02b's talk to Taunie starts on a fade", + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {A_PROMPT, BLACK_FADE}}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + }, + { + .name = "03.02b's talk to Taunie starts on a textless cutscene: the screen moving with no HUD", + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {A_PROMPT, CUTSCENE}}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + }, + { + .name = "03.02b's battle start: A through Taunie's subtitles and the card, done on the battle HUD", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + look(/*events=*/{}, {ADVANCE_ARROW_READING}, Milliseconds(0)), + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(500)), + look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(1000)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, + }, + { + // console B, 2026-11-16 (run 3): the scene before Taunie handed + // control back with no battle, and the battle start waited 90 s. + .name = "a battle start that ends in control, the party bar held 5 s, fails at once", + // The fade's wait takes the first look after it: the party bar's + // 5 s run from the look after that. + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + look({ScreenEvent::FADE_BLACK}, /*readings=*/{}, Milliseconds(0)), + party_bar(Milliseconds(1000)), party_bar(Milliseconds(1000)), party_bar(Milliseconds(3000)), party_bar(Milliseconds(6100)), + }}, + .expectation = {.verdict = "failed at taunie_battle_start: scene_ended_in_control"}, + }, + { + .name = "a battle start goes on through the party bar between the talk's lines", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), + party_bar(Milliseconds(1000)), party_bar(Milliseconds(4000)), + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(5000)), + party_bar(Milliseconds(6000)), + look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(9000)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, + }, + { + .name = "03.02b's map talk: A on the text, B on the map, done on the party bar held a second", + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { DIALOG, look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, .expectation = { .verdict = "done", - .inputs = "press A, press B, press A, press B, wait 250ms", + .inputs = "press A, press B, wait 250ms", .line = "[PLZA] talk_through_map_screen: the party bar held: back in the overworld", }, }, { - .name = "03.02's map talk goes on through the party bar under a text box", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b's map talk goes on through the party bar under a text box", + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, - .expectation = {.verdict = "done", .inputs = "press A, press B, press A, press B, wait 250ms"}, + .expectation = {.verdict = "done", .inputs = "press A, press A, wait 250ms"}, + }, + { + // console B, 2026-11-16 (03.02b run 5): the "Map & Missions" card + // (2 pages) over the map app. A turns its pages and closes it on + // the last; B turns back, so A and B in turn held it on page 1 + // for 120 s. Then B closes the map and goes through her talk. + .name = "03.02b's map talk pages the Map & Missions card with A only, then B on the map and her talk", + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(0)), + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(1000)), + look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(3000)), + party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), + }}, + .expectation = {.verdict = "done", .inputs = "press A, press A, press B, press B, wait 250ms"}, }, { - .name = "03.02's map talk fails with no party bar in 120 s", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b's map talk fails with no party bar in 120 s", + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(121000)), }}, - .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press A, press B"}, + .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press B"}, }, { .name = "03.03 climbs the ladder: sidestep right, face it, A, then up to the top", @@ -693,13 +961,13 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .inputs = "press B, press B, wait 250ms"}, }, { - .name = "03.06's run to the gate needs a console", - .input = {.checkpoint = "03.06", .first_step = 4, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .name = "03.07's run to the gate needs a console", + .input = {.checkpoint = "03.07", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = {.verdict = "failed at to_zone_1_gate: console_only", .inputs = ""}, }, { .name = "03.07's tutorial catch needs a console", - .input = {.checkpoint = "03.07", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .input = {.checkpoint = "03.07", .first_step = 2, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = {.verdict = "failed at catch_fletchling: console_only", .inputs = ""}, }, { @@ -863,7 +1131,8 @@ UnitTestResult check_load(const LoadCase& test, CancellableScope& scope){ // Two rows: "01.01" waits for the platform, "01.02" runs to a choice. -// 01.01's autosave shows when a look has both the platform and the badge. +// 01.01's autosave shows when a look has both the platform and the badge; +// its platform wait then needs two platform looks without the badge. struct ChainCase{ std::string name; struct Input{ @@ -885,7 +1154,7 @@ const Observation PLATFORM_SAVING = look({}, {PLATFORM_READING, AUTOSA const ChainCase CHAIN_CASES[] = { { .name = "autosave seen and the start check does not fail: on without a reload", - .input = {.reload_always = {}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .input = {.reload_always = {}, .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 0}, }, { @@ -896,7 +1165,7 @@ const ChainCase CHAIN_CASES[] = { { .name = "autosave seen and the start check fails: reloads the start", .input = {.reload_always = {}, .looks = { - PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0), + PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0), }}, .expectation = {.verdict = "done", .reloads = 1}, }, @@ -907,7 +1176,7 @@ const ChainCase CHAIN_CASES[] = { }, { .name = "reload always, autosave seen: reloads the start", - .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 1}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index a78939b5b4..8d7c9ae8fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -35,7 +35,7 @@ enum class SceneScreen{ FADE_BLACK, // wait until it lifts FADE_WHITE, // wait until it lifts CHOICE, // terminal: the choice box, with stop_at_choice - DIALOG, // the text button: a box (A: its choice's top row too), or the advance chevron + DIALOG, // a box or the advance chevron: dialog_button() MISSION_COMPLETE, // A: a main mission's "COMPLETE" card TUTORIAL_CARD, // A: a tutorial card (only A turns its pages) MISSION_BANNER, // terminal: a main mission's banner, on a second look @@ -48,6 +48,7 @@ enum class SceneScreen{ HINT_SHOWING, // wait: the controls hint, not held a second yet TALK_PROMPT, // terminal: an A prompt ("A Talk") on the overworld, held a second, past min_length PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length + ENDED_IN_CONTROL, // terminal, failing: with stop_at_battle or stop_at_choice, the party bar held CONTROL_INSTEAD_HOLD with nothing busy AWAITING_SCENE, // wait, no press: with start_window, the HUD up and no scene yet NEVER_STARTED, // terminal, failing: with start_window, the HUD up and no scene for that long QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length @@ -105,6 +106,9 @@ class SceneTimeline{ std::optional m_party_bar_since; std::optional m_hint_since; std::optional m_prompt_since; + // With stop_at_battle or stop_at_choice: since when the party bar + // shows with nothing busy. + std::optional m_control_since; // A scene is under way or has been (scene_under_way()). bool m_scene_seen = false; // The looks in a row with the mission banner. @@ -132,6 +136,12 @@ constexpr Milliseconds PARTY_BAR_HOLD = 1000ms; // Ryon, no party bar and no controls hint; A there restarts his talk // (console B, 2026-11-15, Italian: 3 min of it). constexpr Milliseconds PROMPT_HOLD = 1000ms; +// With stop_at_battle or stop_at_choice, the party bar showing this long +// with nothing busy is the scene over with no battle or choice: it shows +// for a moment between a talk's lines, but 03.02b's scene before Taunie +// handed control back and the battle start waited 90 s for a battle +// (console B, 2026-11-16). +constexpr Milliseconds CONTROL_INSTEAD_HOLD = 5000ms; // How long the screen stays free of text, fades and the banner after the // last of end_after_black_fades' fades before the scene counts as over: // the player can move 5 s after 01.01's third fade at the latest. @@ -188,22 +198,6 @@ bool hud_shows(const ScreenObservation& look){ look.events.has(ScreenEvent::INTERACT_PROMPT); } -// A scene is under way: text, a choice or a battle, or, with no HUD up, a -// fade or a moving screen. A cutscene can play a minute with no text: -// 02.02's street scene moved 41 s with no HUD after its black fade -// (console B, 2026-11-15). A step that plays a scene (start_window) does -// not end on the HUD before one is: the HUD up for start_window with no -// scene is the player away from its trigger. -bool scene_under_way(const ScreenObservation& look){ - if (scene_shows(look)){ - return true; - } - if (hud_shows(look)){ - return false; - } - return fade_shows(look) || !look.events.has(ScreenEvent::SCREEN_STILL); -} - // Whether the party bar and the A prompt are control for `config`: not in // a machine that stops at a choice or a battle, whose talk shows them // between its lines (and whose blind A may start that talk). @@ -216,6 +210,22 @@ bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservat return party_bar_is_control(config) && look.events.has(ScreenEvent::INTERACT_PROMPT); } +// The button DIALOG presses on `look`: A on a choice (its top row); B on a +// text box in a machine that ends in control; else config.text_button. B +// turns a line like A, but on a box that is closing it does nothing, where +// A lands on the A prompt the talk leaves and starts it again: 03.05's +// nurse ("your Pokemon is already in great shape", 110 s of it, console B +// 2026-11-16). +Button dialog_button(const SceneMachineConfig& config, const ScreenObservation& look){ + if (look.events.has(ScreenEvent::CHOICE_BOX)){ + return BUTTON_A; + } + if (party_bar_is_control(config) && look.events.has(ScreenEvent::DIALOG_BOX)){ + return BUTTON_B; + } + return config.text_button; +} + constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::BATTLE, SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, SceneScreen::CHOICE, SceneScreen::DIALOG, @@ -224,8 +234,8 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, - SceneScreen::AWAITING_SCENE, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, - SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, + SceneScreen::ENDED_IN_CONTROL, SceneScreen::AWAITING_SCENE, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, + SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; // Starts `since` when `shows` starts, clears it when it stops. @@ -258,6 +268,7 @@ std::string_view scene_screen_name(SceneScreen screen){ {SceneScreen::HINT_SHOWING, "hint_showing"}, {SceneScreen::TALK_PROMPT, "talk_prompt"}, {SceneScreen::PROMPT_SHOWING, "prompt_showing"}, + {SceneScreen::ENDED_IN_CONTROL, "ended_in_control"}, {SceneScreen::AWAITING_SCENE, "awaiting_scene"}, {SceneScreen::NEVER_STARTED, "never_started"}, {SceneScreen::QUIET_END, "quiet_end"}, @@ -278,10 +289,10 @@ bool scene_screen_terminal(SceneScreen screen){ return screen == SceneScreen::BATTLE || screen == SceneScreen::CHOICE || screen == SceneScreen::MISSION_BANNER || screen == SceneScreen::CAN_MOVE || screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::TALK_PROMPT || screen == SceneScreen::FADE_SETTLED || - screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END; + screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END || screen == SceneScreen::ENDED_IN_CONTROL; } -// Whether this state's step presses (DIALOG the config's text button, +// Whether this state's step presses (DIALOG dialog_button(), // BLIND_PRESS its blind button, MISSION_COMPLETE, TUTORIAL_CARD and // BANNER_PRESS A); the others wait. bool scene_screen_presses(SceneScreen screen){ @@ -407,6 +418,9 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (fades_settled(look.when)){ return SceneScreen::FADE_SETTLED; } + if (m_control_since && look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && look.when - *m_control_since >= CONTROL_INSTEAD_HOLD){ + return SceneScreen::ENDED_IN_CONTROL; + } if (m_config.start_window && !m_scene_seen && hud_shows(look)){ const bool past_window = look.when - m_start >= *m_config.start_window; return past_window ? SceneScreen::NEVER_STARTED : SceneScreen::AWAITING_SCENE; @@ -455,6 +469,8 @@ void SceneTimeline::record(const ScreenObservation& look){ const bool box = look.events.has(ScreenEvent::DIALOG_BOX); const bool party_bar = party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE); track_since(party_bar && !box, look.when, m_party_bar_since); + const bool control_instead = !party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && !busy(look); + track_since(control_instead, look.when, m_control_since); track_since(look.readings.contains(CONTROLS_HINT_READING) && !box, look.when, m_hint_since); track_since(control_prompt_shows(m_config, look) && !box, look.when, m_prompt_since); m_banner_looks = look.readings.contains(MISSION_BANNER_READING) && !box ? m_banner_looks + 1 : 0; @@ -485,6 +501,7 @@ std::string describe_look(const ScreenObservation& look){ const std::pair readings[] = { {CONTROLS_HINT_READING, "controls hint"}, {ADVANCE_ARROW_READING, "advance arrow"}, {MISSION_BANNER_READING, "mission banner"}, {MISSION_COMPLETE_READING, "mission complete"}, + {TUTORIAL_CARD_READING, "tutorial card"}, }; std::string text; const auto add = [&text](std::string_view name){ @@ -644,8 +661,7 @@ class SceneRunner{ public: SceneRunner(PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, WallClock start) : m_backend(backend) - , m_text_button(config.text_button) - , m_blind_button(config.blind_button) + , m_config(config) , m_timeline(config, start) , m_log(backend, label, start) {} @@ -671,20 +687,20 @@ class SceneRunner{ return; } if (scene_screen_presses(screen)){ - m_backend.press(button_of(screen), /*hold=*/160ms, /*release=*/240ms); + m_backend.press(button_of(screen, look), /*hold=*/160ms, /*release=*/240ms); return; } wait(screen); } private: - // The button `screen`'s step presses. - Button button_of(SceneScreen screen) const{ + // The button `screen`'s step presses on `look`. + Button button_of(SceneScreen screen, const ScreenObservation& look) const{ switch (screen){ case SceneScreen::DIALOG: - return m_text_button; + return dialog_button(m_config, look); case SceneScreen::BLIND_PRESS: - return m_blind_button; + return m_config.blind_button; default: return BUTTON_A; } @@ -730,8 +746,7 @@ class SceneRunner{ } PlzaBackend& m_backend; - Button m_text_button; - Button m_blind_button; + SceneMachineConfig m_config; SceneTimeline m_timeline; SceneLog m_log; }; @@ -827,6 +842,12 @@ Pokemon::Outcome scene_outcome( label, config.start_window ? config.start_window->count() : 0, expected )); } + if (result.terminal == scene_screen_name(SceneScreen::ENDED_IN_CONTROL)){ + return Pokemon::outcome_failed("scene_ended_in_control", std::format( + "{}: the scene ended in control, the party bar up {} ms with nothing busy (expecting {}).", + label, CONTROL_INSTEAD_HOLD.count(), expected + )); + } if (result.terminal == scene_screen_name(SceneScreen::QUIET_END) && config.quiet_is_control){ backend.log(std::format("[PLZA {}] done: quiet, taken as control.", label)); return Pokemon::outcome_ok(); @@ -849,6 +870,20 @@ Pokemon::Outcome scene_outcome( } // namespace +std::string describe_scene_look(const ScreenObservation& look){ + return describe_look(look); +} + +bool scene_under_way(const ScreenObservation& look){ + if (scene_shows(look) || look.readings.contains(TUTORIAL_CARD_READING)){ + return true; + } + if (hud_shows(look)){ + return false; + } + return fade_shows(look) || !look.events.has(ScreenEvent::SCREEN_STILL); +} + Pokemon::Outcome run_scene_machine( PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, Milliseconds timeout ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 78b278cd01..a672da0bff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -6,10 +6,13 @@ * states (CommonTools/ScreenMachine) that match on what the backend * observed, so they run on the console and on a scripted backend alike: * every look picks one state, the state takes one step, and each change of - * state or of the look's events is logged (repeats are summed up). A text box (with or without a - * choice, whose top row A takes) or the advance chevron - * (ADVANCE_ARROW_READING) gets A. The player has control when the party - * bar (PLAYER_CAN_MOVE) or, in the tutorial, which has no party bar, the + * state or of the look's events is logged (repeats are summed up). A + * choice gets A (its top row); a text box gets B in a machine that ends + * in control (B turns a line like A, but cannot talk again once the box + * closes: A at the closing box restarted 03.05's nurse's talk), else the + * text button, as does the advance chevron (ADVANCE_ARROW_READING). The + * player has control when the party bar (PLAYER_CAN_MOVE) or, in the + * tutorial, which has no party bar, the * controls hint (CONTROLS_HINT_READING) holds a second, or an A prompt * (INTERACT_PROMPT, "A Talk") holds a second past min_length (01.02's * battle area shows only the prompt to Ryon; A there restarts his talk, @@ -32,8 +35,10 @@ #define PokemonAutomation_PokemonLZA_AutoStorySceneMachine_H #include +#include #include #include "Common/Cpp/Time.h" +#include "CommonTools/ScreenMachine/ScreenObservation.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" #include "PokemonLZA_AutoStoryBackend.h" @@ -66,8 +71,10 @@ struct SceneMachineConfig{ bool stop_at_choice = false; // Ends at the battle HUD (BATTLE_STARTED), before anything else. bool stop_at_battle = false; - // The button that advances text: B where an A could land on a choice - // that shows the moment the text ends. + // The button that advances text in a machine that stops at a choice + // or a battle, and the advance chevron with no box: B where an A could + // land on a choice that shows the moment the text ends. A text box in + // any other machine gets B, a choice A. Button text_button = BUTTON_A; // The quiet end is control, not a failure: Hotel Z's lobby, halls and // rooms show no party bar or prompt (02.04-02.06, console B @@ -95,6 +102,22 @@ struct SceneMachineConfig{ std::optional end_after_black_fades = std::nullopt; }; +// A scene is under way on `look`: text (a box, or a subtitle's advance +// chevron), a choice, a battle or a tutorial card, or, with no HUD up (the +// party bar, the controls hint, an A prompt), a fade or a moving screen. +// A cutscene can play a minute with no text: 02.02's street scene moved +// 41 s with no HUD after its black fade (console B, 2026-11-15). A step +// that plays a scene (start_window) does not end on the HUD before one +// is: the HUD up for start_window with no scene is the player away from +// its trigger. "talk" takes it for its talk having started: Taunie's +// (03.02b) opens on a dimmed "Smart Rotom" card with no text box (console +// B, 2026-11-16). +bool scene_under_way(const ScreenObservation& look); + +// "text box, advance arrow": `look`'s events and readings, as the scene +// machine logs them; "nothing" for none. +std::string describe_scene_look(const ScreenObservation& look); + // Logs where the step should end ("[PLZA label] start, expecting the // controls hint, ..."), then presses through scenes (a tutorial card, // TUTORIAL_CARD_READING, gets A) until the controls hint or the party bar has diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index 8f42fa569c..1e329cf85d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -270,7 +270,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "failed: scene_quiet", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: quiet_end at 60.0s: still", .states = "scene_moving, dialog, scene_still, quiet_end", }, @@ -286,7 +287,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "failed: scene_quiet", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 5: quiet_end at 23.0s: still", .states = "dialog, scene_still, fade_white, scene_still, quiet_end", }, @@ -317,7 +319,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: controls_hint at 9.0s: still, controls hint", .states = "hint_showing, dialog, hint_showing, controls_hint", }, @@ -374,7 +377,8 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .a_presses = 2, + .a_presses = 0, + .b_presses = 2, .line = "[PLZA test] screen 6: mission_banner at 12.0s: still, mission banner", .states = "dialog, scene_moving, banner_showing, dialog, banner_showing, mission_banner", }, @@ -408,7 +412,7 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 0, .states = "scene_still, hint_showing, controls_hint"}, }, { - .name = "01.01's arrival: A at the text and at the choice, none in the flyover, done on the controls hint", + .name = "01.01's arrival: B at the text, none in the flyover, done on the controls hint", .input = {.looks = { look_at(0ms, DIALOG), look_at(1000ms), @@ -419,7 +423,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/24500ms, NOTHING, {CONTROLS_HINT_READING}), look_at(/*at=*/25100ms, NOTHING, {CONTROLS_HINT_READING}), }}, - .expectation = {.verdict = "done", .a_presses = 2, .line = "[PLZA test] done on controls_hint."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 2, .line = "[PLZA test] done on controls_hint."}, }, { .name = "the mission banner ends the scene, which then waits for it to go", @@ -430,7 +434,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/1000ms, NOTHING, {MISSION_BANNER_READING}), look_at(1250ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] the mission banner has gone after 250 ms."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] the mission banner has gone after 250 ms."}, }, { // Two looks end the scene, 40 more are the 10 s wait. @@ -447,7 +451,7 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] the mission banner still shows after 3 A presses; going on."}, }, { - .name = "01.03's end: A at the text and the mission complete card, done on the next banner", + .name = "01.03's end: B at the text, A at the mission complete card, done on the next banner", .input = {.looks = { look_at(0ms, DIALOG), look_at(/*at=*/500ms, NOTHING, {MISSION_COMPLETE_READING}), @@ -457,7 +461,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/2250ms, NOTHING, {MISSION_BANNER_READING}), look_at(2500ms), }}, - .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] done on mission_banner."}, + .expectation = {.verdict = "done", .a_presses = 2, .b_presses = 1, .line = "[PLZA test] done on mission_banner."}, }, { .name = "a mission complete card that A does not get past fails as scene_stuck", @@ -482,7 +486,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/17250ms, NOTHING, {MISSION_BANNER_READING}), look_at(17500ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] screen 1: fade_white at 0.0s: white fade"}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] screen 1: fade_white at 0.0s: white fade"}, }, { .name = "a machine that stops at choices ends on the choice box, after the text before it", @@ -549,7 +553,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: can_move at 1.9s: party bar", .states = "party_bar, dialog, party_bar, can_move", }, @@ -594,16 +599,17 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .states = "scene_moving, dialog, scene_still, party_bar, can_move", }, }, { - .name = "after Brigitte: A at the text, done on the party bar held a second", + .name = "after Brigitte: B at the text, done on the party bar held a second", .input = {.looks = { look_at(0ms, DIALOG), look_at(500ms, DIALOG), look_at(1000ms, PARTY), look_at(1500ms, PARTY), look_at(2100ms, PARTY), }}, - .expectation = {.verdict = "done", .a_presses = 2, .line = "[PLZA test] done on can_move."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 2, .line = "[PLZA test] done on can_move."}, }, { // console B, 2026-11-15: blind A at the prompt restarted Ryon's @@ -612,7 +618,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = battle_area_talk_prompt(), .config = battle_area_config()}, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] done on talk_prompt.", .states = "dialog, scene_moving, prompt_showing, talk_prompt", }, @@ -626,7 +633,7 @@ const RunCase RUN_CASES[] = { { .name = "Hotel Z's room: the quiet end is control", .input = {.looks = {look_at(0ms, DIALOG), look_at(1000ms), look_at(4100ms, STILL)}, .config = quiet_room_config()}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] done: quiet, taken as control."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] done: quiet, taken as control."}, }, { // console B, 2026-11-15: 02.02's street scene moved 41 s with no @@ -660,14 +667,14 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "failed: scene_quiet", .a_presses = 0}, }, { - .name = "a box that A does not get past fails as scene_stuck", + .name = "a box that B does not get past fails as scene_stuck", .input = {.looks = {look_at(0ms, DIALOG)}}, - .expectation = {.verdict = "failed: scene_stuck", .a_presses = 400}, + .expectation = {.verdict = "failed: scene_stuck", .a_presses = 0, .b_presses = 400}, }, { .name = "past 360 s it fails as scene_timeout", .input = {.looks = {look_at(0ms, DIALOG), look_at(361000ms, DIALOG)}}, - .expectation = {.verdict = "failed: scene_timeout", .a_presses = 1}, + .expectation = {.verdict = "failed: scene_timeout", .a_presses = 0, .b_presses = 1}, }, { .name = "a minute of blind A in a still cutscene is summed up every 30 s", @@ -686,7 +693,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = arrival_with_three_fades(), .config = three_fades_config()}, .expectation = { .verdict = "done", - .a_presses = 4, + .a_presses = 0, + .b_presses = 4, .states = "dialog, scene_moving, fade_black, dialog, fade_white, dialog, fade_black, banner_showing, " "fade_black, scene_moving, fade_settled", .overlay = std::vector{ @@ -707,7 +715,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = arrival_banner_until_a(), .config = three_fades_config()}, .expectation = { .verdict = "done", - .a_presses = 3, + .a_presses = 1, + .b_presses = 2, .line = "[PLZA test] done on fade_settled.", .states = "dialog, fade_black, dialog, fade_black, banner_showing, banner_press, scene_moving, fade_black, " "scene_moving, fade_settled", @@ -716,7 +725,7 @@ const RunCase RUN_CASES[] = { { .name = "with end_after_black_fades, a banner that 3 A presses 1 s apart do not clear fails as scene_stuck", .input = {.looks = arrival_banner_stays(), .config = three_fades_config()}, - .expectation = {.verdict = "failed: scene_stuck", .a_presses = 5}, + .expectation = {.verdict = "failed: scene_stuck", .a_presses = 3, .b_presses = 2}, }, { .name = "the trace logs each new state", @@ -726,7 +735,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/800ms, NOTHING, {MISSION_BANNER_READING}), look_at(1000ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] screen 3: mission_banner at 0.8s: mission banner"}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] screen 3: mission_banner at 0.8s: mission banner"}, }, }; @@ -802,6 +811,158 @@ class RunTest : public UnitTest{ }; +// 03.05's nurse as a closed loop, on the screens of the console run's log +// (console B 2026-11-16): her greeting, a black fade (the heal), her last +// lines, then her box closing over one look and the A prompt to her at +// the counter. A at the closing box or at the prompt talks to her again +// ("Your Pokemon is already in great shape!", one line); B there does +// nothing. +class NurseCounter : public Pokemon::FakeStoryBackend{ +public: + explicit NurseCounter(CancellableScope& scope) + : FakeStoryBackend({}, scope) + {} + + // The talks started after the heal's. + size_t talks_again() const{ + return m_talks_again; + } + + virtual void press(Button button, Milliseconds hold, Milliseconds release) override{ + FakeStoryBackend::press(button, hold, release); + m_now += hold + release; + switch (m_phase){ + case Phase::GREETING: + case Phase::LAST_LINES: + case Phase::AGAIN: + m_lines--; + if (m_lines == 0 && m_phase == Phase::GREETING){ + m_phase = Phase::HEAL_FADE; + m_fade_until = m_now + 3000ms; + }else if (m_lines == 0){ + m_phase = Phase::CLOSING; + } + return; + case Phase::CLOSING: + case Phase::AT_PROMPT: + if (button == BUTTON_A){ + m_phase = Phase::AGAIN; + m_lines = 1; + m_talks_again++; + } + return; + case Phase::HEAL_FADE: + return; + } + } + virtual void wait(Milliseconds duration) override{ + FakeStoryBackend::wait(duration); + m_now += duration; + } + virtual Pokemon::Observation observe() override{ + Pokemon::Observation look; + look.when = WallClock::min() + m_now; + if (m_phase == Phase::HEAL_FADE && m_now >= m_fade_until){ + m_phase = Phase::LAST_LINES; + m_lines = 2; + } + switch (m_phase){ + case Phase::HEAL_FADE: + look.events.set(ScreenEvent::FADE_BLACK, true); + return look; + case Phase::GREETING: + case Phase::LAST_LINES: + case Phase::AGAIN: + look.events.set(ScreenEvent::DIALOG_BOX, true); + look.readings[std::string(ADVANCE_ARROW_READING)] = 1; + return look; + case Phase::CLOSING: + look.events.set(ScreenEvent::DIALOG_BOX, true); + m_phase = Phase::AT_PROMPT; + return look; + case Phase::AT_PROMPT: + look.events.set(ScreenEvent::INTERACT_PROMPT, true); + return look; + } + return look; + } + +private: + enum class Phase{GREETING, HEAL_FADE, LAST_LINES, CLOSING, AT_PROMPT, AGAIN}; + + Milliseconds m_now = 0ms; + Phase m_phase = Phase::GREETING; + size_t m_lines = 5; + Milliseconds m_fade_until = 0ms; + size_t m_talks_again = 0; +}; + +// Scene machines at 03.05's nurse (NurseCounter), on the screens as they +// follow from its presses. +struct NurseCase{ + std::string name; + struct Input{ + SceneMachineConfig config; + }; + Input input; + struct Expectation{ + // "done", or "failed: ". + std::string verdict; + // The run's last line. + std::string end; + // The talks started after the heal's. + size_t talks_again = 0; + }; + Expectation expectation; +}; + +const NurseCase NURSE_CASES[] = { + { + // console B 2026-11-16: A at the closing box talked to her again + // for 110 s, until the 120 s timeout. + .name = "03.05's heal_party (scene): done on her A prompt, no talk again", + .input = {.config = scene_step_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on talk_prompt.", .talks_again = 0}, + }, + { + .name = "mash_to_move_hints at a talk's end: done on the A prompt, no talk again", + .input = {.config = arrival_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on talk_prompt.", .talks_again = 0}, + }, +}; + +UnitTestResult check_nurse(const NurseCase& test, CancellableScope& scope){ + NurseCounter backend(scope); + const Pokemon::Outcome outcome = run_scene_machine(backend, "test", test.input.config, 120s); + const std::string verdict = outcome.succeeded() ? "done" : std::format("failed: {}", outcome.failure); + if (verdict != test.expectation.verdict){ + return std::format("expected \"{}\", got \"{}\"; log:\n{}", test.expectation.verdict, verdict, joined(backend.lines(), "\n")); + } + if (backend.talks_again() != test.expectation.talks_again){ + return std::format( + "expected {} talks after the heal's, got {}: {}", test.expectation.talks_again, backend.talks_again(), joined(backend.inputs(), ", ") + ); + } + if (backend.lines().empty() || backend.lines().back() != test.expectation.end){ + return std::format("expected the run to end with \"{}\"; log:\n{}", test.expectation.end, joined(backend.lines(), "\n")); + } + return true; +} + +class NurseTest : public UnitTest{ +public: + explicit NurseTest(const NurseCase& test) + : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine closed loop - {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ + return check_nurse(m_test, scope); + } +private: + const NurseCase& m_test; +}; + + } // namespace @@ -809,6 +970,9 @@ void add_tests_AutoStorySceneMachine(UnitTestDatabase& database){ for (const RunCase& test : RUN_CASES){ database.add(test); } + for (const NurseCase& test : NURSE_CASES){ + database.add(test); + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp index c7b494f91a..e937df20a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp @@ -34,6 +34,7 @@ PlzaScreenObserver::PlzaScreenObserver() , m_choice_arrow(COLOR_YELLOW, nullptr, SelectionArrowType::RIGHT, dialog_choice_box()) , m_interact(COLOR_RED, ButtonType::ButtonA, INTERACT_PROMPT_BOX) , m_battle_hint(COLOR_CYAN, ButtonType::ButtonA, BATTLE_HINT_BOX) + , m_battle_panel(COLOR_GREEN) , m_party(COLOR_WHITE) {} @@ -53,7 +54,7 @@ ScreenEvents PlzaScreenObserver::read(const ImageViewRGB32& screen){ out.set(ScreenEvent::DIALOG_BOX, box); out.set(ScreenEvent::CHOICE_BOX, m_choice_arrow.detect(screen)); out.set(ScreenEvent::INTERACT_PROMPT, !box && m_interact.detect(screen)); - out.set(ScreenEvent::BATTLE_STARTED, m_battle_hint.detect(screen)); + out.set(ScreenEvent::BATTLE_STARTED, m_battle_hint.detect(screen) || m_battle_panel.detect(screen)); out.set(ScreenEvent::PLAYER_CAN_MOVE, !box && m_party.detect(screen)); return out; } @@ -63,6 +64,7 @@ void PlzaScreenObserver::make_overlays(VideoOverlaySet& items) const{ m_choice_arrow.make_overlays(items); m_interact.make_overlays(items); m_battle_hint.make_overlays(items); + m_battle_panel.make_overlays(items); m_party.make_overlays(items); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h index 9f10dfbc2c..2ab436e3cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h @@ -15,6 +15,7 @@ #include "VideoGames/PokemonLZA/Inference/PokemonLZA_ButtonDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector.h" namespace PokemonAutomation{ @@ -35,8 +36,11 @@ namespace PokemonLZA{ // (OverworldPartySelectionDetector), with no box. Hotel Z's lobby, // halls and rooms do not show it; // - BATTLE_STARTED: the battle HUD's hints at the bottom centre ("X A: -// Select Move"), read by their A icon. Story battles show no Run -// prompt, so RunFromBattleDetector misses them. +// Select Move"), read by their A icon, or the player's Pokemon's panel +// at the bottom left (BattlePanelDetector): the hints show only while +// the player is locked on, and Taunie's battle (03.02b) ran 70 s with +// none (console B, 2026-11-16). Story battles show no Run prompt, so +// RunFromBattleDetector misses them. // A fading screen has no box to read. class PlzaScreenObserver : public ScreenEventObserver{ public: @@ -54,6 +58,7 @@ class PlzaScreenObserver : public ScreenEventObserver{ SelectionArrowDetector m_choice_arrow; ButtonDetector m_interact; ButtonDetector m_battle_hint; + BattlePanelDetector m_battle_panel; OverworldPartySelectionDetector m_party; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp index f45b0f4b00..6598c58189 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp @@ -84,6 +84,50 @@ const FrameCase FRAME_CASES[] = { }, }; +struct BattleFrameCase{ + std::string name; + struct Input{ + std::string_view path; // In CommandLineTests/PokemonLZA/. + }; + Input input; + struct Expectation{ + bool battle = false; + }; + Expectation expectation; +}; + +const BattleFrameCase BATTLE_FRAME_CASES[] = { + { + // console B, 2026-11-16 (03.02b run 4): Taunie's Totodile + // attacking, the player not locked on, so no move list or its + // hints; only Chikorita's panel at the bottom left shows the + // battle. story_battle_start waited 90 s for it. + .name = "a battle with the player not locked on: the panel, no move hints", + .input = {.path = "AutoStoryScreenEvents/it_0302b_battle_no_lock_on.png"}, + .expectation = {.battle = true}, + }, + { + .name = "no battle at the A Talk prompt on the Italian game", + .input = {.path = "AutoStoryScreenEvents/it_0102_parla_talk_prompt.png"}, + .expectation = {.battle = false}, + }, + { + .name = "no battle at an A prompt while the player is held", + .input = {.path = "AutoStoryScreenEvents/za2_m3v_s1.png"}, + .expectation = {.battle = false}, + }, +}; + +UnitTestResult check_battle_frame(const BattleFrameCase& test){ + const std::string path = std::format("{}PokemonLZA/{}", UNIT_TEST_RESOURCE_PATH(), test.input.path); + PlzaScreenObserver observer; + const bool battle = observer.read(ImageRGB32(path)).has(ScreenEvent::BATTLE_STARTED); + if (battle != test.expectation.battle){ + return std::format("{}: expected battle {}, got {}", test.input.path, test.expectation.battle ? "yes" : "no", battle ? "yes" : "no"); + } + return true; +} + struct FolderCase{ std::string name; struct Input{ @@ -158,6 +202,20 @@ class Test_Frame : public UnitTest{ const FrameCase& m_test; }; +class Test_BattleFrame : public UnitTest{ +public: + explicit Test_BattleFrame(const BattleFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStoryScreenEvents - battle frame: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_battle_frame(m_test); + } + +private: + const BattleFrameCase& m_test; +}; + class Test_Folder : public UnitTest{ public: explicit Test_Folder(const FolderCase& test) @@ -179,6 +237,9 @@ void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database){ for (const FrameCase& test : FRAME_CASES){ database.add(test); } + for (const BattleFrameCase& test : BATTLE_FRAME_CASES){ + database.add(test); + } for (const FolderCase& test : FOLDER_CASES){ database.add(test); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index a0ac9d043e..f8ac14d8b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -4,6 +4,9 @@ * */ +#include +#include +#include #include "PokemonLZA_AutoStoryTable.h" namespace PokemonAutomation{ @@ -16,7 +19,56 @@ bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row){ return false; } const Pokemon::StoryStep& first = row.steps.front(); - return first.kind == Pokemon::StoryStepKind::GAME && first.action == "confirm_new_game"; + return first.kind == Pokemon::StoryStepKind::GAME && (first.action == "new_game_intro" || first.action == "confirm_new_game"); +} + +namespace{ + +// Whether `step` ends on an A prompt: a walk to "prompt", or +// walk_to_prompt. +bool ends_on_prompt(const Pokemon::StoryStep& step){ + if (step.action == "walk_to_prompt"){ + return true; + } + const auto end = step.args.find("end"); + if (step.action != "walk" || end == step.args.end()){ + return false; + } + const std::string* word = std::get_if(&end->second); + return word != nullptr && *word == "prompt"; +} + +// Whether `step` presses through its scenes until control: a scene that +// needs nothing from the player to start plays inside it. +bool plays_to_control(const Pokemon::StoryStep& step){ + return step.kind == Pokemon::StoryStepKind::MASH + || step.action == "mash_to_move_hints" + || step.action == "talk_to_pokedex_screen" + || step.action == "talk_through_map_screen"; +} + +} // namespace + +std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row){ + std::vector errors; + for (size_t index = 0; index < row.steps.size(); index++){ + const Pokemon::StoryStep& step = row.steps[index]; + const Pokemon::StoryStep* before = index == 0 ? nullptr : &row.steps[index - 1]; + if (step.kind == Pokemon::StoryStepKind::TALK && (before == nullptr || !ends_on_prompt(*before))){ + errors.push_back(std::format( + "{}: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)", step.name + )); + } + if (step.action == "story_battle" && (before == nullptr || before->action != "story_battle_start")){ + errors.push_back(std::format("{}: a story battle must follow story_battle_start, which ends on the battle HUD", step.name)); + } + if (step.kind == Pokemon::StoryStepKind::MASH && before != nullptr && plays_to_control(*before)){ + errors.push_back(std::format( + "{}: a scene must follow what starts it, not {}, which plays its scenes through to control", step.name, before->action + )); + } + } + return errors; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index 58337eaf08..8a40f4ba64 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -18,6 +18,8 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryTable_H #define PokemonAutomation_PokemonLZA_AutoStoryTable_H +#include +#include #include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" @@ -30,11 +32,27 @@ namespace PokemonLZA{ // execution marks (Pokemon_StoryRowExecution.h). using StoryData = Pokemon::StoryData; -// Whether `row` starts with no save to load: it starts on the new game's -// "Confirm Choices" screen, the language, look and name chosen by hand -// (its first step is the GAME action "confirm_new_game"): 01.00. +// Whether `row` starts with no save to load: it starts a new game (its +// first step is the GAME action "new_game_intro", or "confirm_new_game" +// on "Confirm Choices"): 01.00. bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); +// ": " for each step of `row` that does not come right after +// the step it needs (console B, 2026-11-16): +// - a TALK after a step that ends on an A prompt (a "walk" to "end" +// "prompt", or "walk_to_prompt"): a timed walk can stop short of who +// the talk is for (03.02); +// - a "story_battle" after "story_battle_start", which presses through +// the talk and cards to the battle HUD: the battle code run on the +// overworld looks for a battle for 2 min (03.02b); +// - a scene ("a", MASH) after what starts it (a walk, a talk, a choice, +// a battle), not after a step that presses through its scenes until +// control (a scene, "mash_to_move_hints", "talk_to_pokedex_screen", +// "talk_through_map_screen"): a scene that follows with nothing to +// start it plays inside that step, and the scene step then waits 45 s +// on the party bar for it (03.04's after_pokedex). +std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json index 07a5ccae00..43033888a4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json @@ -3,12 +3,18 @@ "game": "plza", "checkpoint": { "id": "01.00", - "title": "New game from Confirm Choices to the station platform", + "title": "New game to the station platform", "events": [ + { + "id": "new_game", + "kind": "game_action", + "why": "from HOME (the game closed, no save) launch the selected tile, then the language list, the look picker and the name keyboard with the panel's choices; on Confirm Choices already, nothing", + "action": "new_game_intro" + }, { "id": "confirm", "kind": "game_action", - "why": "the language, look and name were chosen by hand and Confirm Choices shows (so the save is fresh): check that screen with no press (anything else is a setup error), then DOWN to Ready!, reading the highlight after each, and A", + "why": "Confirm Choices shows (so the save is fresh): check that screen with no press (anything else is a setup error) and that it shows the panel's name and language, then DOWN to Ready!, reading the highlight after each, and A", "action": "confirm_new_game" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json index 72db6c34c8..6de9af2b28 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json @@ -11,10 +11,11 @@ { "id": "approach_starter", "kind": "game_action", - "why": "walk up to Chikorita, the starter the run picks (the only walk recorded: console B, 2026-11-08), to its \"A Talk\" prompt", + "why": "walk up to Chikorita, the starter the run picks (the only walk recorded: console B, 2026-11-08), to its \"A Talk\" prompt not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[-70, 750]] + "legs": [[-70, 750]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json index b29b1ffd4d..446fb92528 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json @@ -11,9 +11,9 @@ { "id": "to_front_counter", "kind": "game_action", - "why": "step 26: along the counter to the clerk's \"A Talk\". 2.25 s was one step short. Measured 2026-11-08 on console B, walk not run.", + "why": "step 26: along the counter to the clerk's \"A Talk\". 2.25 s was one step short. Measured 2026-11-08 on console B, walk not run. Ends on the A prompt after the turn, or fails. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[-5, 2500], [-85, 0]]} + "args": {"legs": [[-5, 2500], [-85, 0]], "end": "prompt"} }, { "id": "talk_to_clerk", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json index 2996652502..23f0990b2c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json @@ -11,9 +11,9 @@ { "id": "to_lobby_elevator", "kind": "game_action", - "why": "step 28: to the elevator's \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run.", + "why": "step 28: to the elevator's \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run: 2 s; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[0, 2000]]} + "args": {"legs": [[0, 3000]], "end": "prompt"} }, { "id": "take_elevator_up", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json index 1992801f66..f953f4c022 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json @@ -11,9 +11,9 @@ { "id": "to_bed", "kind": "game_action", - "why": "step 31: to the bed's \"A Rest\". 1.5 s explored, 1 s enough. Measured 2026-11-08 on console B, walk not run.", + "why": "step 31: to the bed's \"A Rest\". 1.5 s explored, 1 s enough. Measured 2026-11-08 on console B, walk not run. On until the prompt, 1.5 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[45, 1000]], "held": true} + "args": {"legs": [[45, 1500]], "held": true, "end": "prompt"} }, { "id": "rest", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json index f7ce2c2d71..b072167084 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json @@ -27,10 +27,11 @@ { "id": "to_2f_elevator", "kind": "game_action", - "why": "step 37: down the 2F hallway to \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run.", + "why": "step 37: down the 2F hallway to \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run: 2 s; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[-15, 2000]] + "legs": [[-15, 3000]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json index 72feac8078..959508c7ae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json @@ -3,7 +3,7 @@ "game": "plza", "checkpoint": { "id": "03.02", - "title": "Out of Hotel Z, battle Taunie", + "title": "Out of Hotel Z", "start": { "place": "HotelZ" }, @@ -23,50 +23,14 @@ "why": "steps 40-41: A Leave at the door (a scene step ends at once on its prompt), the Main Menu tutorial card", "action": "mash_to_move_hints", "args": {"press_a_first": true} - }, - { - "id": "to_taunie_at_gate", - "kind": "game_action", - "why": "step 41: to Taunie at the gate, \"A Talk Taunie\". Measured 2026-11-08 on console B, walk not run.", - "action": "walk", - "args": { - "legs": [[0, 3000]] - } - }, - { - "id": "talk_to_taunie", - "kind": "talk", - "why": "step 42: A at Taunie" - }, - { - "id": "battle_totodile", - "kind": "game_action", - "why": "steps 42-43: A through her talk and challenge (no A hint, a subtitle with no text box), then beat Totodile, until \"We're not done just yet!\"", - "action": "story_battle" - }, - { - "id": "battle_tepig", - "kind": "game_action", - "why": "step 44: A through the Type Matchups tutorial (3 pages) and Tepig's send-out, then beat Tepig, until Taunie's speech", - "action": "story_battle" - }, - { - "id": "after_taunie_battle", - "kind": "game_action", - "why": "step 45: Taunie's talk and the Map & Missions card with A, the map closed with B, her talk with B", - "action": "talk_through_map_screen" - }, - { - "id": "taunie_runs_off", - "kind": "game_action", - "why": "step 45: the Main Missions card (A turns its pages; a scene step only waits on it), Taunie runs off (console B, 2026-11-10)", - "action": "mash_to_move_hints" } ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: the game does not autosave at its end (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends outside Hotel Z at the autosave seen in leave_hotel_z, after the Main Menu card (console B, 2026-11-16: badge at 116 s in the step), so a checkpoint starts where that save reloads; 03.02b goes on to Taunie." } }, - "execution": {} + "execution": { + "save": "autosave" + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json new file mode 100644 index 0000000000..e9dfb18bb4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json @@ -0,0 +1,92 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "03.02b", + "title": "Battle Taunie", + "start": { + "place": "LumioseCity" + }, + "events": [ + { + "id": "to_plaza_scene_prompt", + "kind": "game_action", + "why": "step 41: on from the reload spot outside Hotel Z to the first A prompt, which starts a scene, not Taunie's talk: it was 3.25 s ahead on all three 03.02b runs (console B, 2026-11-16). The 2026-11-08 recording's 3 s leg from the live exit stopped short of Taunie at the Quartiere Verde arch. 8 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", + "action": "walk", + "args": { + "legs": [ + [ + 0, + 8000 + ] + ], + "end": "prompt" + } + }, + { + "id": "plaza_scene", + "kind": "game_action", + "why": "step 41: A at that prompt starts a scene: a black fade, the dimmed Smart Rotom card, a second black fade, then control at the Quartiere Verde arch with Taunie a few steps ahead inside it (console B, 2026-11-16, run 3: control 12 s after A)", + "action": "mash_to_move_hints", + "args": { + "press_a_first": true + } + }, + { + "id": "to_taunie", + "kind": "game_action", + "why": "step 42: straight on through the arch to Taunie's \"A Talk\" (run 3's frame: she stands a few steps ahead, facing the player), 8 s at most", + "action": "walk_to_prompt", + "args": { + "timeout_ms": 8000 + } + }, + { + "id": "talk_to_taunie", + "kind": "talk", + "why": "step 42: A at Taunie's prompt" + }, + { + "id": "taunie_battle_start", + "kind": "game_action", + "why": "steps 42-43: A through her talk and challenge (no A hint, subtitles with no text box, the Smart Rotom card) until the battle HUD (console B, 2026-11-16: the talk opened on the card; the battle code run straight after it looked 2 min for a battle on the overworld)", + "action": "story_battle_start" + }, + { + "id": "battle_totodile", + "kind": "game_action", + "why": "step 43: beat Totodile, until \"We're not done just yet!\"", + "action": "story_battle" + }, + { + "id": "tepig_battle_start", + "kind": "game_action", + "why": "step 44: A through \"We're not done just yet!\", the Type Matchups tutorial (3 pages) and Tepig's send-out until the battle HUD", + "action": "story_battle_start" + }, + { + "id": "battle_tepig", + "kind": "game_action", + "why": "step 44: beat Tepig, until Taunie's speech", + "action": "story_battle" + }, + { + "id": "after_taunie_battle", + "kind": "game_action", + "why": "step 45: Taunie's talk and the Map & Missions card with A, the map closed with B, her talk with B", + "action": "talk_through_map_screen" + }, + { + "id": "taunie_runs_off", + "kind": "game_action", + "why": "step 45: the Main Missions card (A turns its pages; a scene step only waits on it), Taunie runs off (console B, 2026-11-10)", + "action": "mash_to_move_hints" + } + ], + "metadata": { + "phase": "testing", + "source": "console B recording, 2026-11-08/09: played step by step from a new game; split from 03.02 at the autosave outside Hotel Z (console B, 2026-11-16), so a checkpoint starts where that save reloads. Starts outside Hotel Z after the Main Menu card; nothing reads that spot yet, so its start is unchecked. No save: the game does not autosave at its end (2026-11-15 save review)." + } + }, + "execution": {} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json index 837d27c2ce..f6465a01dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json @@ -11,10 +11,11 @@ { "id": "into_pokemon_center", "kind": "game_action", - "why": "step 53: into the Pokemon Center, to the nurse's \"A Talk\". The last turn (\"right\") had no angle recorded: 90 is a guess. Measured 2026-11-08 on console B, walk not run.", + "why": "step 53: into the Pokemon Center, to the nurse's \"A Talk\". The last turn (\"right\") had no angle recorded: 90 is a guess. Measured 2026-11-08 on console B, walk not run. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[0, 3000], [20, 2000], [-90, 2000], [90, 0]] + "legs": [[0, 3000], [20, 2000], [-90, 2000], [90, 0]], + "end": "prompt" } }, { @@ -25,22 +26,17 @@ { "id": "pokedex_app", "kind": "game_action", - "why": "step 54: the Pokedex app (\"Ready!\"), Chikorita's entry, B on its screen", + "why": "steps 54-55: the Pokedex app (\"Ready!\"), Chikorita's entry, B on its screen, then the nurse's wrap-up and Taunie's scene outside, until control outside the Center. Nothing starts step 55's scene, so it plays inside this step: console B 2026-11-16 saw its text, two black fades and the autosave badge, then the party bar outside the Center, and a scene step after it waited 45 s on the party bar.", "action": "talk_to_pokedex_screen" - }, - { - "id": "after_pokedex", - "kind": "scene", - "why": "step 55: the nurse's wrap-up, Taunie outside", - "action": "a" } ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: no autosave at its end was seen in a run log (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends outside the Pokemon Center, in control, on the game's autosave: console B 2026-11-16 logged the autosave badge after Taunie's scene's last black fade, then the party bar outside the Center." } }, "execution": { - "reload_when_chained": "always" + "reload_when_chained": "always", + "save": "autosave" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json index 22c57540b5..b70f662047 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json @@ -6,16 +6,17 @@ "title": "Heal at the Pokemon Center", "start": { "place": "LumioseCity", - "spot": "PokemonCenter" + "spot": "PokemonCenterDoor" }, "events": [ { "id": "back_to_nurse", "kind": "game_action", - "why": "back to the nurse after 03.04's scene: turn right and walk into the counter, which faces her (user, console B, 2026-11-13); the counter stops the walk, so 2 s is safe.", + "why": "UNVERIFIED, NEEDS CONSOLE: from 03.04's end outside the Pokemon Center (console B 2026-11-16) back in to the nurse. These legs are from inside the Center (turn right, walk into the counter that faces her; user, console B, 2026-11-13) and do not reach her from outside; the walk in from the door is not measured. not planned: Lumiose has no tile grid to plan a route target on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[90, 2000]] + "legs": [[90, 3000]], + "end": "prompt" } }, { @@ -32,7 +33,7 @@ ], "metadata": { "phase": "testing", - "source": "added 2026-11-13 so Main Mission 03 has a backup save to retry from; no console recording of its steps: every step is unverified and needs console. Autosave: the heal's save was seen in a run log (2026-11-15 save review)." + "source": "added 2026-11-13 so Main Mission 03 has a backup save to retry from; no console recording of its steps: every step is unverified and needs console. It is not in the 2026-11-08 recording (03.04 is steps 53-55, 03.06 starts at step 56), and 03.04 now ends on the game's autosave outside the Center (console B 2026-11-16), which may already give Main Mission 03 the save to retry from: whether the heal is still needed is the user's call. Autosave: the heal's save was seen in a run log (2026-11-15 save review)." } }, "execution": { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json index 28234db3c9..8f10ebd082 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json @@ -3,7 +3,7 @@ "game": "plza", "checkpoint": { "id": "03.06", - "title": "To Wild Zone 1", + "title": "To the Wild Zones card", "start": { "place": "LumioseCity", "spot": "PokemonCenter" @@ -12,7 +12,7 @@ { "id": "out_of_pokemon_center", "kind": "game_action", - "why": "UNVERIFIED, NEEDS CONSOLE: from the nurse's counter after 03.05's heal back to where 03.04's scene left the player, facing as it did, so the legs below (measured from there) still hold. Reverses 03.05's back_to_nurse (right, then into the counter): turn around, walk back 1.5 s (that walk is under 2 s; the time back is a guess), then right to face as the scene left the player.", + "why": "UNVERIFIED, NEEDS CONSOLE: from the nurse's counter after 03.05's heal, out of the Center to where 03.04's scene left the player (outside, by the door; console B 2026-11-16), facing as it did, so the legs below (step 56, recorded right after 03.04's scene) still hold. These legs only reverse an in-Center walk to the counter and do not leave the Center; the way out is not measured. not planned: Lumiose has no tile grid to plan a route target on.", "action": "walk", "args": { "legs": [[180, 1500], [90, 0]] @@ -41,28 +41,14 @@ "kind": "scene", "why": "step 57: Taunie on wild zones, the Wild Zones card", "action": "a" - }, - { - "id": "to_zone_1_gate", - "kind": "game_action", - "why": "step 58, after Taunie's scene: runs straight on to Wild Zone 1's gate until its A prompt, by upstream's run_towards_gate_with_A_button (user, 2026-11-15: try it before plza/autostory's gate-pillar steering). Replaces the timed 4.3 s walk (22 units at ~5.1 units/s, measured 2026-11-08 on console B), so 8 s of running is ample.", - "action": "run_to_gate", - "args": { - "timeout_ms": 8000 - } - }, - { - "id": "enter_zone_1", - "kind": "game_action", - "why": "step 58: A Enter at the gate (a scene step ends at once on its prompt), Taunie, the Throwing Poke Balls card", - "action": "mash_to_move_hints", - "args": {"press_a_first": true} } ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: no autosave at its end was seen in a run log (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends on the autosave in wild_zones_tutorial, its last step (console B, 2026-11-16: badge at 41.4 s), so a checkpoint starts where that save reloads; 03.07 goes on into Wild Zone 1. The menu save of plza/autostory is dropped." } }, - "execution": {} + "execution": { + "save": "autosave" + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json index 464d2c79f8..f1ad0f34a8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json @@ -3,11 +3,28 @@ "game": "plza", "checkpoint": { "id": "03.07", - "title": "Wild Zone 1: first catches", + "title": "Into Wild Zone 1: first catches", "start": { - "place": "WildZone1" + "place": "LumioseCity", + "spot": "WildZone1Gate" }, "events": [ + { + "id": "to_zone_1_gate", + "kind": "game_action", + "why": "step 58, after Taunie's scene: runs straight on to Wild Zone 1's gate until its A prompt, by upstream's run_towards_gate_with_A_button (user, 2026-11-15: try it before plza/autostory's gate-pillar steering). Replaces the timed 4.3 s walk (22 units at ~5.1 units/s, measured 2026-11-08 on console B), so 8 s of running is ample.", + "action": "run_to_gate", + "args": { + "timeout_ms": 8000 + } + }, + { + "id": "enter_zone_1", + "kind": "game_action", + "why": "step 58: A Enter at the gate (a scene step ends at once on its prompt), Taunie, the Throwing Poke Balls card", + "action": "mash_to_move_hints", + "args": {"press_a_first": true} + }, { "id": "catch_fletchling", "kind": "game_action", @@ -29,7 +46,7 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. Autosave: the game's autosave at after_catches, its last step, was seen in four run logs (console B, 2026-11-13); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Starts outside Wild Zone 1's gate, where 03.06's autosave in wild_zones_tutorial reloads (console B, 2026-11-16: 03.07 reloaded there and threw outside the zone when it began at catch_fletchling). Autosave: the game's autosave at after_catches, its last step, was seen in four run logs (console B, 2026-11-13); the menu save of plza/autostory is dropped." } }, "execution": { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json index e09f1abeb7..5b6982b35c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json @@ -17,13 +17,7 @@ { "id": "research_lab_gate", "kind": "scene", - "why": "step 63: Taunie at the lab gate; with five species registered she goes on", - "action": "a" - }, - { - "id": "five_registered", - "kind": "scene", - "why": "step 65: Taunie's scene at the lab gate after 5/5", + "why": "steps 63-65: Taunie at the lab gate; with five species registered she goes on to her scene after 5/5, until control. One scene step: nothing starts the 5/5 part, so a scene step for it would wait 45 s on the party bar, as 03.04's after_pokedex did (console B 2026-11-16). UNVERIFIED, NEEDS CONSOLE: no control between the two parts was checked.", "action": "a" }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json index 19ba7b0406..0ac58d0bf9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json @@ -11,15 +11,16 @@ { "id": "to_lab_elevator", "kind": "game_action", - "why": "step 66: to the elevator's \"A Take Elevator\". Measured 2026-11-09 on console B, walk not run.", + "why": "step 66: to the elevator's \"A Take Elevator\". Measured 2026-11-09 on console B, walk not run: 1 s; on until the prompt, 1.5 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { "legs": [ [ 0, - 1000 + 1500 ] - ] + ], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h index 34a85d5547..3a537beeb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h @@ -25,6 +25,13 @@ bool reset_game_to_gamemenu( ConsoleHandle& console, ProControllerContext& context ); +// From the game menu screen (where "Press A" is displayed to enter the game), +// mash A to enter the game and wait until the black screen is gone. +bool gamemenu_to_ingame( + VideoStream& stream, ProControllerContext& context, + Milliseconds enter_game_timeout +); + // From Switch Home menu, start game and wait until the player character // appears in game. // post_wait_time: how many ticks to wait after the black screen diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 4730da7efe..2095e12c13 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1379,6 +1379,8 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp @@ -1430,6 +1432,8 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.cpp Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.h + Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp + Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.h Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.cpp @@ -2322,10 +2326,20 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -2334,6 +2348,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp @@ -2354,6 +2370,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp