Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory Battle

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattle.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=983 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -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"
Expand Down Expand Up @@ -122,9 +123,11 @@
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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));
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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.
Expand All @@ -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;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
* 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.
*
*/

#include <format>
#include <optional>
#include <string>
#include <utility>
#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"
Expand Down Expand Up @@ -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


Expand All @@ -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<Test_AutoStoryScreenEvents>(item);
}
for (const auto& item : BATTLE_FRAME_CASES){
database.add<Test_AutoStoryBattleFrame>(item);
}
// The same events on recorded console frames.
add_tests_AutoStoryFrameReplay(database);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
Loading