diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 5344517c89..265165e70f 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -385,9 +385,9 @@ jobs: uses: actions/checkout@v7 if: inputs.run-tests with: - # The fork's fixtures: upstream's, the SystemKeyboardDetector and HomeTileReader screenshots and pending FRLG image submissions (Fly landing, party menu, Route 21 battle and Pokemon Mansion 1F and B1F hold frames). + # The fork's fixtures: upstream's, the SystemKeyboardDetector and HomeTileReader screenshots and pending FRLG image submissions (Fly landing, party menu, Route 21 battle and Pokemon Mansion 1F and B1F hold frames, Silph Co. 5F overworld). repository: 'dayfine/CommandLineTests' - ref: 'f68c0b0e6cd1cf2d6d882fb49c3f99c9881ec1f4' + ref: '1ec000796442d7f0ef82551e05bf84f27e1695ef' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp index ac4bfadc70..f46db3a64d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp @@ -20,6 +20,7 @@ #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleHpBarReader.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattlePokemonDetector.h" #include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleScreenDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleTextBoxDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryMovesReader.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalkWatches.h" @@ -122,9 +123,11 @@ BattleScreen read_battle_screen(const ImageViewRGB32& screen, bool confirmed){ return BattleScreen::NONE; } +// The text box by its frame (BattleTextBoxDetector): its blue alone also +// reads on the near-black below a small map (Silph Co. 5F, 2026-11-14). BattleTextScreen read_text_screen(const ImageViewRGB32& screen){ return BattleTextScreen{ - .text_box = BattleDialogDetector(COLOR_RED).detect(screen), + .text_box = BattleTextBoxDetector(COLOR_RED).detect(screen), .hp_box = BattleScreenDetector(COLOR_RED).detect(screen), .arrow = AdvanceBattleDialogDetector(COLOR_RED).detect(screen), .yes_no = battle_yes_no_shows(screen) || yes_no_cursor(screen).has_value(), diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp index 09d5d945a1..2dffe91d5b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.cpp @@ -18,7 +18,7 @@ FrlgScreenObserver::FrlgScreenObserver() : m_dialog(COLOR_RED) , m_choice(COLOR_RED) , m_battle_menu(COLOR_RED) - , m_battle_dialog(COLOR_RED) + , m_battle_text_box(COLOR_RED) {} ScreenEvents FrlgScreenObserver::observe(const VideoSnapshot& frame, WallClock){ @@ -35,7 +35,7 @@ ScreenEvents FrlgScreenObserver::observe(const VideoSnapshot& frame, WallClock){ // A uniform screen has no box or menu to read. return out; } - const bool battle = m_battle_menu.detect(screen) || m_battle_dialog.detect(screen); + const bool battle = m_battle_menu.detect(screen) || m_battle_text_box.detect(screen); out.set(ScreenEvent::BATTLE_STARTED, battle); out.set(ScreenEvent::DIALOG_BOX, !battle && m_dialog.detect(screen)); out.set(ScreenEvent::CHOICE_BOX, !battle && m_choice.detect(screen)); @@ -46,7 +46,7 @@ void FrlgScreenObserver::make_overlays(VideoOverlaySet& items) const{ m_dialog.make_overlays(items); m_choice.make_overlays(items); m_battle_menu.make_overlays(items); - m_battle_dialog.make_overlays(items); + m_battle_text_box.make_overlays(items); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h index 8cf7765d09..a74429a65f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h @@ -13,6 +13,7 @@ #include "CommonTools/ScreenEvents/ScreenEvents.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" +#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_BattleTextBoxDetector.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -22,7 +23,9 @@ namespace PokemonFRLG{ // The shared events from FRLG's detectors: // - DIALOG_BOX: the overworld's white text box (WhiteDialogDetector); // - CHOICE_BOX: a Yes/No or answer box beside it (SelectionDialogDetector); -// - BATTLE_STARTED: the battle menu or a battle's text box; +// - BATTLE_STARTED: the battle menu or a battle's text box, by its frame +// (BattleTextBoxDetector): the box's blue alone also reads on the +// near-black below a small map (Silph Co. 5F, console B, 2026-11-14); // - FADE_BLACK / FADE_WHITE: fade_of_screen(). // Nothing on a dark cave's overworld (dark_cave_screen()), whose black // the battle text box detector reads as a box. @@ -40,7 +43,7 @@ class FrlgScreenObserver : public ScreenEventObserver{ WhiteDialogDetector m_dialog; SelectionDialogDetector m_choice; BattleMenuDetector m_battle_menu; - BattleDialogDetector m_battle_dialog; + BattleTextBoxDetector m_battle_text_box; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp index 55ed120d4d..0fb5a61556 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp @@ -5,7 +5,9 @@ * The adapter on synthetic frames: a uniform screen is a fade and nothing * else, and no frame shows nothing. Frames of real boxes and battles are * the detectors' own image tests (CommandLineTests); a flat grey frame is - * not one of those (the battle text box reads it as a box). + * not one of those (the battle text box reads it as a box). Console frames + * the adapter once misread are replayed here too, from CommandLineTests; + * such a case skips when its image is missing. * */ @@ -13,7 +15,9 @@ #include #include #include +#include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "PokemonFRLG_AutoStoryFrameReplay_Tests.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" @@ -77,6 +81,46 @@ class Test_AutoStoryScreenEvents : public UnitTest{ ScreenEventsCase m_case; }; +struct BattleFrameCase{ + struct Input{ + // The console frame, under CommandLineTests. + std::string image; + }; + + struct Expectation{ + bool battle; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +// Whether the adapter reports BATTLE_STARTED on a console frame. +class Test_AutoStoryBattleFrame : public UnitTest{ +public: + explicit Test_AutoStoryBattleFrame(BattleFrameCase test_case) + : UnitTest(std::format("PokemonFRLG::AutoStoryScreenEvents - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string path = UNIT_TEST_RESOURCE_PATH() + m_case.input.image; + if (!Filesystem::exists(Filesystem::Path(path))){ + return UnitTestResult(UnitTestResult::SKIPPED, std::format("Missing image: {}", path)); + } + FrlgScreenObserver observer; + const ScreenEvents got = observer.observe(VideoSnapshot(ImageRGB32(path), WallClock()), WallClock()); + if (got.has(ScreenEvent::BATTLE_STARTED) != m_case.expectation.battle){ + return std::format("expected battle {}, got {}", m_case.expectation.battle, describe(got)); + } + return true; + } + +private: + BattleFrameCase m_case; +}; + } // namespace @@ -101,10 +145,39 @@ const ScreenEventsCase SCREEN_EVENTS_CASES[] = { }, }; +// Console B's captures. Silph Co. 5F (16.03, 2026-11-14): the floor over +// near-black below the map, which the box's blue alone took for a battle's +// text box before each step. +const BattleFrameCase BATTLE_FRAME_CASES[] = { + { + .name = "Silph Co. 5F, near-black below the map, is no battle", + .input = {"PokemonFRLG/AutoStoryScreenEvents/SilphCo5F_Overworld_False.png"}, + .expectation = {false}, + }, + { + .name = "Pewter's Pokemon Center, black below the room, is no battle", + .input = {"PokemonFRLG/BattleTextBoxDetector/PewterPokemonCenter_BlackBelow_False.png"}, + .expectation = {false}, + }, + { + .name = "a battle's opening on Route 1 is a battle", + .input = {"PokemonFRLG/BattleTextBoxDetector/Route1_Opening_True.png"}, + .expectation = {true}, + }, + { + .name = "a wild Caterpie in Viridian Forest is a battle", + .input = {"PokemonFRLG/BattleTextBoxDetector/ViridianForest_WildCaterpie_True.png"}, + .expectation = {true}, + }, +}; + void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database){ for (const auto& item : SCREEN_EVENTS_CASES){ database.add(item); } + for (const auto& item : BATTLE_FRAME_CASES){ + database.add(item); + } // The same events on recorded console frames. add_tests_AutoStoryFrameReplay(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.h index 39b267b4d7..51d5389d43 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.h @@ -14,7 +14,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Registers the screen-event adapter's unit tests (synthetic frames). +// Registers the screen-event adapter's unit tests (synthetic and console frames). void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database);