Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
510ce32
Merge origin/nav/shared (5e3150565) into frlg/autostory-mvp
dayfine Nov 1, 2026
ff8ef13
FRLG: AutoStory, FireRed from a new game to the Boulder Badge
dayfine Nov 1, 2026
42a6513
FRLG AutoStory: press only A in the new game's intro, B only on the k…
dayfine Nov 1, 2026
7f1ae1a
FRLG AutoStory: the player still faces north after the rival takes hi…
dayfine Nov 1, 2026
7772ed0
FRLG AutoStory: a battle is not over, nor at a move prompt, before it…
dayfine Nov 1, 2026
4ff8a53
FRLG AutoStory: press B through text the battle screens don't know
dayfine Nov 1, 2026
ce19d6f
Merge frlg/walk-interrupt-recount (0d220a584, #119) into frlg/autosto…
dayfine Nov 1, 2026
ce2d77d
FRLG AutoStory: the player faces south after the Pokedex scene
dayfine Nov 1, 2026
c91d4a3
FRLG AutoStory: answer the nurse's YES by timed A presses
dayfine Nov 1, 2026
1d44d6f
FRLG AutoStory: walk north clear of the old man before Route 2
dayfine Nov 1, 2026
a423f0e
FRLG AutoStory: Potion on yellow HP, Antidote only on PSN read twice,…
dayfine Nov 1, 2026
95d92d6
FRLG AutoStory: fight wild Pokemon only inside Viridian Forest
dayfine Nov 1, 2026
08db493
FRLG AutoStory: a battle is over only once START opens; run from wild…
dayfine Nov 1, 2026
ac1873b
FRLG: a battle needs an HP box or the battle menu, not the text box a…
dayfine Nov 1, 2026
35cb587
FRLG AutoStory: no battle without an HP box or the battle menu
dayfine Nov 1, 2026
50b0dad
FRLG AutoStory: forest fights only at full strength; leave the forest…
dayfine Nov 1, 2026
6138b2c
FRLG AutoStory: fight Camper Liam on purpose, from beside him
dayfine Nov 1, 2026
53bf9be
FRLG AutoStory: write each checkpoint as one initializer list
dayfine Nov 1, 2026
c2de4f5
FRLG AutoStory: meet Camper Liam on the way up column 6
dayfine Nov 1, 2026
8788d3b
Merge frlg/walk-interrupt-recount (08829d226, #119) into frlg/autosto…
dayfine Nov 1, 2026
b7f8617
FRLG AutoStory: before a big battle, a Potion if hurt, the nurse only…
dayfine Nov 1, 2026
2d043c9
Merge origin/frlg/autostory-mvp (8788d3bc5, restacked on #119) into f…
dayfine Nov 1, 2026
cfef415
FRLG AutoStory: plan 00.08's gym walks in CI on embedded maps
dayfine Nov 1, 2026
efb05fe
FRLG AutoStory: read HP and status from measured colors; cure PSN and…
dayfine Nov 1, 2026
17b645c
Merge frlg/walk-interrupt-recount (5266c44fe, #119) into frlg/autosto…
dayfine Nov 1, 2026
77a183d
FRLG AutoStory: plan every checkpoint in CI on the compiled-in maps
dayfine Nov 1, 2026
8b2a31e
Merge frlg/walk-interrupt-recount (8ff8665fb, #119) into frlg/autosto…
dayfine Nov 1, 2026
88d8ffd
FRLG AutoStory: let the walker recover stopped legs on story routes
dayfine Nov 1, 2026
fd599b0
Merge nav/story-steps (3d9bf943d: shared story steps, with nav/shared…
dayfine Nov 1, 2026
bac9b9f
FRLG AutoStory: the story table on the shared story steps
dayfine Nov 1, 2026
ad62d91
Merge nav/story-steps (474c2a013: one retry policy) into frlg/story-s…
dayfine Nov 1, 2026
ebe8087
FRLG AutoStory: the shared retry options instead of its own attempts
dayfine Nov 1, 2026
1a90024
Merge frlg/walk-interrupt-recount (efb38a1d5, #119) into frlg/autosto…
dayfine Nov 1, 2026
86604db
Merge nav/story-steps (f1408301a: begin_attempt) into frlg/story-steps
dayfine Nov 1, 2026
a8611fa
Merge frlg/autostory-mvp (1a9002430: #119 merged) into frlg/story-steps
dayfine Nov 1, 2026
d48c063
FRLG AutoStory: run the story table end to end against a fake game
dayfine Nov 1, 2026
ad5d408
FRLG AutoStory: Mart cursor stays on the item bought; screenshots at …
dayfine Nov 1, 2026
1a9acf3
Merge frlg/autostory-mvp (ad5d40885: the Mart cursor stays on the ite…
dayfine Nov 1, 2026
b60d993
FRLG AutoStory: simulate the Viridian Mart with its cursor staying on…
dayfine Nov 1, 2026
c9d9d67
Merge nav/story-steps (03298de07: checks level) into frlg/story-steps
dayfine Nov 1, 2026
7b07480
FRLG AutoStory: hand the shared checks option to the story executor
dayfine Nov 1, 2026
ac0c963
FRLG AutoStory: Checks option; read the Mart row, the bag after shopp…
dayfine Nov 1, 2026
99d0d76
FRLG AutoStory: tests for the Mart cursor, the pocket's rows and the …
dayfine Nov 1, 2026
44742ac
FRLG AutoStory: drop the bag capture test
dayfine Nov 1, 2026
fd32e9b
Merge frlg/autostory-mvp (44742ac63: Checks option, Mart and bag read…
dayfine Nov 1, 2026
f16aeef
Merge frlg/walk-interrupt-recount (35e02c30e) into frlg/autostory-mvp
dayfine Nov 1, 2026
2de8712
Merge frlg/walk-interrupt-recount (4c33feb97, #119) into frlg/autosto…
dayfine Nov 1, 2026
8e0eabe
FRLG AutoStory: name the route log after the story step, from its start
dayfine Nov 1, 2026
1c2d007
Merge nav/story-steps (daf7b8faf: game language) into frlg/story-steps
dayfine Nov 1, 2026
530a5be
FRLG AutoStory: the game's language from the shared options; simulate…
dayfine Nov 1, 2026
6253aaf
FRLG AutoStory: save on entering Viridian Forest (new 00.08); Brock i…
dayfine Nov 1, 2026
ee314f3
Merge frlg/walk-interrupt-recount (04f2e27dd) into frlg/autostory-mvp
dayfine Nov 1, 2026
9f8566c
Merge frlg/walk-interrupt-recount (de84c7d93, #119) into frlg/autosto…
dayfine Nov 1, 2026
2239dab
Merge frlg/walk-interrupt-recount (215de9394) into frlg/autostory-mvp
dayfine Nov 1, 2026
f694e4d
FRLG AutoStory: Viridian Forest straight up the east side, without th…
dayfine Nov 1, 2026
bc95fe3
FRLG AutoStory: read item names in the game's language; unread means …
dayfine Nov 1, 2026
c63cfac
FRLG AutoStory: refuse a save from somewhere other than the start che…
dayfine Nov 1, 2026
3308b51
Merge frlg/walk-interrupt-recount (9c7063941, #119) into frlg/autosto…
dayfine Nov 1, 2026
9767fbe
Merge frlg/story-steps (530a5be33, #123) into frlg/autostory-mvp: the…
dayfine Nov 1, 2026
f3342fa
Merge frlg/walk-interrupt-recount (0f615e858) into frlg/autostory-mvp
dayfine Nov 1, 2026
97454c1
FRLG AutoStory: the shared start and end dropdowns and AutoStory stats
dayfine Nov 1, 2026
f91daf8
FRLG AutoStory: count the run with the shared record_story_stats()
dayfine Nov 1, 2026
811b20e
Merge frlg/walk-interrupt-recount (be72296d4, #119: wall check) into …
dayfine Nov 1, 2026
86b4aec
FRLG AutoStory: the walker's wall check runs with Thorough checks only
dayfine Nov 1, 2026
4ff6105
Merge frlg/walk-interrupt-recount (5a85facdb) into frlg/autostory-mvp
dayfine Nov 1, 2026
d45367e
FRLG AutoStory: include the story engine from Pokemon/AutoStory
dayfine Nov 1, 2026
bd4b162
Merge frlg/walk-interrupt-recount (cc24b589e) into frlg/autostory-mvp
dayfine Nov 1, 2026
583d958
FRLG AutoStory: what code health asks for
dayfine Nov 1, 2026
509176d
Merge frlg/walk-interrupt-recount (04a5881a5) into frlg/autostory-mvp
dayfine Nov 1, 2026
37b375a
FRLG AutoStory: the story's status lines on the video overlay
dayfine Nov 1, 2026
ec55b69
Merge frlg/walk-interrupt-recount (4e9ec1d75, #119: FRLG maps in the …
dayfine Nov 2, 2026
3358b2a
FRLG AutoStory: the wall beside a stop is a TileKind::WALL
dayfine Nov 2, 2026
c8129a4
Merge frlg/walk-interrupt-recount (#119: walk with recovery in its ow…
dayfine Nov 2, 2026
07952b0
FRLG AutoStory: walk story routes with walk_overworld_route_with_reco…
dayfine Nov 2, 2026
769d7a4
Merge origin/frlg/walk-interrupt-recount into frlg/autostory-mvp
dayfine Nov 2, 2026
510aa66
FRLG AutoStory: read bag counts with the digit templates; unread coun…
dayfine Nov 2, 2026
072312b
Merge frlg/walk-interrupt-recount (#118/#119: walker run speed) into …
dayfine Nov 2, 2026
cb3bc03
FRLG AutoStory: 00.10 the Running Shoes, 00.11 a first run
dayfine Nov 2, 2026
a7c85ba
FRLG AutoStory tests: the table has 11 checkpoints
dayfine Nov 2, 2026
d621f7d
Merge frlg/walk-interrupt-recount into frlg/autostory-mvp
dayfine Nov 2, 2026
f4ac51f
FRLG AutoStory: confirm the save, and check a reload's save card
dayfine Nov 2, 2026
c73763d
FRLG AutoStory: pick the rival's first preset name from Oak's list
dayfine Nov 2, 2026
f4bbb71
FRLG AutoStory: set the options by reading them, not by blind presses
dayfine Nov 2, 2026
fff4697
FRLG AutoStory: set BATTLE SCENE to OFF with the options
dayfine Nov 2, 2026
fbb9799
FRLG AutoStory: image tests for the option, save card and Mart list r…
dayfine Nov 2, 2026
38515d3
Merge branch 'frlg/walk-interrupt-recount' into frlg/autostory-mvp
dayfine Nov 3, 2026
d81c007
FRLG AutoStory: reader image tests take the expected result from the …
dayfine Nov 3, 2026
c1dc5bc
FRLG AutoStory: give StoryEnv's start_map a default
dayfine Nov 3, 2026
b0ccc48
FRLG AutoStory: drop 00.11's test run
dayfine Nov 3, 2026
3911b32
Merge branch 'frlg/walk-interrupt-recount' into frlg/autostory-mvp
dayfine Nov 3, 2026
011fb2d
FRLG AutoStory: the table test counts 10 checkpoints without 00.11
dayfine Nov 3, 2026
20dbd3e
FRLG AutoStory: a YES/NO box needs its white, not only the arrow
dayfine Nov 3, 2026
4f68ce0
FRLG AutoStory: advance_text() needs a YES/NO's box too; first box is NO
dayfine Nov 3, 2026
a44b3f1
Merge remote-tracking branch 'origin/frlg/walk-interrupt-recount' int…
dayfine Nov 3, 2026
8b423c9
FRLG AutoStory simulation: fail a leg to a wall that would walk on
dayfine Nov 3, 2026
d6be27d
Merge frlg/walk-interrupt-recount into frlg/autostory-mvp
dayfine Nov 3, 2026
0a739f2
FRLG AutoStory: learn moves, let evolutions finish, protect the party
dayfine Nov 3, 2026
10a4232
Merge frlg/walk-interrupt-recount (a038b853b, #119: recovery from the…
dayfine Nov 3, 2026
f58e54c
FRLG AutoStory tests: register the party tests with the items tests
dayfine Nov 3, 2026
450abed
FRLG AutoStory: read the lead's moves off its summary; attack by name…
dayfine Nov 3, 2026
cc051b9
FRLG AutoStory: read_party_summary() in its own file
dayfine Nov 3, 2026
6ae10fe
FRLG tests: register AutoStory's menu readers in one group
dayfine Nov 3, 2026
ecd7fc6
FRLG AutoStory: attacks by matchup against known trainers; bag counts…
dayfine Nov 3, 2026
af87b22
FRLG AutoStory battle: end on the overworld after RUN in a dark cave
dayfine Nov 3, 2026
6bdc7da
FRLG AutoStory battle: a disabled move, and a move list that never sh…
dayfine Nov 3, 2026
c2a42d6
FRLG AutoStory battle: attacks by matchup in every battle, from pret'…
dayfine Nov 3, 2026
fb4a70f
FRLG AutoStory battle: the HP bar's share, the nurse for yellow HP, a…
dayfine Nov 3, 2026
faa41d4
Merge frlg/walk-interrupt-recount (#119: verify mode from #122) into …
dayfine Nov 3, 2026
c3edf46
FRLG AutoStory: verify mode, the start checkpoint N runs from its save
dayfine Nov 3, 2026
cb51ddf
FRLG AutoStory battle: a Gen 3 damage calculator, the foe out, and a …
dayfine Nov 3, 2026
e19ee3e
FRLG AutoStory battle: no Potion the next hit undoes, and the sim pla…
dayfine Nov 3, 2026
8935c60
FRLG SummaryMovesReader: read the TMs' and HMs' moves, and a move nam…
dayfine Nov 3, 2026
b8a58dd
FRLG AutoStory: read the bag's rows below an item the reader can't name
dayfine Nov 3, 2026
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
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps
Pokemon/Navigation/Pokemon_Navigation_Tests.h PokemonAutomation::Pokemon navigation_test_map_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Overworld/Maps
VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h PokemonAutomation::NintendoSwitch::PokemonFRLG overworld_map_json)
pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/BattleData
VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_battle_json)


# Create binary target
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/* Item List Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <algorithm>
#include <format>
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/Language.h"
#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h"
#include "Tests/ImageUnitTest.h"
#include "Tests/TestUtils.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Tests.h"
#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_DigitReader.h"
#include "VideoGames/PokemonFRLG/Inference/PokemonFRLG_OcrPreprocessing.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_ItemListReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

// Measured on a capture of the Items pocket (console B, 2026-11-01): text
// rows from y 13 to 21, 16 apart; names from x 97, "x" at 198, the count
// to 221.
constexpr double ROW_TOP = 11;
constexpr double ROW_STEP = 16;
constexpr double ROW_HEIGHT = 12;

class ItemNameMatcher : public OCR::SmallDictionaryMatcher{
public:
static constexpr double MAX_LOG10P = -1.40;
static constexpr double MAX_LOG10P_SPREAD = 0.50;

static const ItemNameMatcher& instance(){
static const ItemNameMatcher matcher;
return matcher;
}

std::string read(Logger& logger, Language language, const ImageViewRGB32& image) const{
if (!languages()[language]){
return "";
}
const ImageRGB32 ready = preprocess_for_ocr(image);
const OCR::StringMatchResult result = match_substring_from_image_multifiltered(
&logger, language, ready, DARK_TEXT_FILTERS(),
MAX_LOG10P, MAX_LOG10P_SPREAD, 0.01, 0.50
);
return result.results.empty() ? "" : result.results.begin()->second.token;
}

private:
ItemNameMatcher()
: SmallDictionaryMatcher(dictionary())
{}

static JsonObject dictionary(){
JsonObject english;
for (const auto& [slug, name] : {
std::pair<const char*, const char*>{"potion", "Potion"},
{"antidote", "Antidote"},
{"parlyz-heal", "Parlyz Heal"},
{"poke-ball", "Poke Ball"},
{"cancel", "Cancel"},
}){
JsonArray names;
names.push_back(name);
english[slug] = std::move(names);
}
JsonObject json;
json["eng"] = std::move(english);
return json;
}
};

ImageViewRGB32 game_box(const ImageViewRGB32& screen){
return extract_box_reference(screen, GameSettings::instance().GAME_BOX);
}

}


ImageFloatBox item_list_name_box(int row){
return ImageFloatBox(96.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 72.0 / 240, ROW_HEIGHT / 160);
}
ImageFloatBox bag_item_count_box(int row){
return ImageFloatBox(208.0 / 240, (ROW_TOP + ROW_STEP * row) / 160, 15.0 / 240, ROW_HEIGHT / 160);
}

std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row){
return ItemNameMatcher::instance().read(logger, language, extract_box_reference(game_box(screen), item_list_name_box(row)));
}

std::vector<BagRow> read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen){
std::vector<BagRow> rows;
for (int row = 0; row < ITEM_LIST_ROWS; row++){
const std::string item = read_item_list_name(logger, language, screen, row);
if (item == "cancel"){
break;
}
const ImageViewRGB32 count = extract_box_reference(game_box(screen), bag_item_count_box(row));
// Not Tesseract on each waterfilled digit: the font joins some strokes
// only at a corner, so the 5 and the 3 fell apart into pieces and read
// as nothing (console B, 2026-11-02). The stat boxes' templates are
// the same digits on the same cream.
rows.push_back(BagRow{item, read_digits_waterfill_template(logger, count, DigitTemplateType::StatBox)});
}
return pocket_rows(std::move(rows));
}

std::vector<BagRow> pocket_rows(std::vector<BagRow> reads){
const auto cancel = std::find_if(reads.begin(), reads.end(), [](const BagRow& row){
return row.item == "cancel";
});
reads.erase(cancel, reads.end());
while (!reads.empty() && reads.back().item.empty()){
reads.pop_back();
}
return reads;
}


namespace{

// The language a test image's name ends with: <anything>_<language code>.
Language language_of_test_image(const std::string& image){
const std::vector<std::string> words = parse_words(Filesystem::Path(image).stem().string());
return words.size() < 2 ? Language::None : language_code_to_enum(words.back());
}

// A capture of a bag pocket, read from the top. Its golden file holds each
// row's item and count, one per line.
class Test_BagPocket : public ImageUnitTest{
public:
Test_BagPocket(const std::string& image)
: ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image})
{}

virtual UnitTestResult run_on_images(
Logger& logger, CancellableScope& scope,
const std::vector<ImageRGB32>& images
) const override{
const Language language = language_of_test_image(image_paths()[0]);
if (language == Language::None || language == Language::EndOfList){
return "Error: filename must be <anything>_<language code>.";
}
std::vector<std::string> labels;
std::vector<std::string> values;
const std::vector<BagRow> rows = read_bag_pocket(logger, language, images[0]);
for (size_t c = 0; c < rows.size(); c++){
labels.push_back(std::format("row {} item", c + 1));
labels.push_back(std::format("row {} count", c + 1));
values.push_back(rows[c].item.empty() ? "(unread)" : rows[c].item);
values.push_back(std::to_string(rows[c].count));
}
return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values);
}
};

// A capture of a Mart's BUY list, read from the top to its CANCEL. Its
// golden file holds each row's item, one per line.
class Test_MartList : public ImageUnitTest{
public:
Test_MartList(const std::string& image)
: ImageUnitTest("PokemonFRLG::ItemListReader - " + image, {image})
{}

virtual UnitTestResult run_on_images(
Logger& logger, CancellableScope& scope,
const std::vector<ImageRGB32>& images
) const override{
const Language language = language_of_test_image(image_paths()[0]);
if (language == Language::None || language == Language::EndOfList){
return "Error: filename must be <anything>_<language code>.";
}
std::vector<std::string> labels;
std::vector<std::string> values;
for (int row = 0; row < ITEM_LIST_ROWS; row++){
const std::string item = read_item_list_name(logger, language, images[0], row);
labels.push_back(std::format("row {}", row + 1));
values.push_back(item.empty() ? "(nothing)" : item);
if (item.empty() || item == "cancel"){
break;
}
}
return check_against_golden_file(UNIT_TEST_RESOURCE_PATH() + image_paths()[0], labels, values);
}
};

}

void add_tests_ItemListReader(UnitTestDatabase& database){
// FireRed on console B, 2026-11-02, after the Viridian Mart: the 5 and
// the 3 read as nothing before the digit templates.
database.add<Test_BagPocket>("PokemonFRLG/ItemListReader/ItemsPocket_eng.png");
// Console B, 2026-11-03, the save before Cerulean's rival: a MOON STONE,
// which the reader has no name for, above the PARLYZ HEAL and 15 POTIONs.
// Stopping at it read nothing, and the rival was fought with 0 Potions.
database.add<Test_BagPocket>("PokemonFRLG/ItemListReader/ItemsPocketMoonStone_eng.png");
// The Viridian Mart's BUY list, the same day, the cursor on POTION.
database.add<Test_MartList>("PokemonFRLG/ItemListReader/MartBuyList_eng.png");
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Item List Reader
*
* From: https://github.com/PokemonAutomation/
*
* Reads the item lists of the bag's pockets and of a Mart's BUY menu,
* which the game draws alike: rows 16 pixels apart from y 13, names from
* x 97 (pokefirered: the list window at tile (11, 1), item_X 9). It knows
* the names of the items a new game meets before the Boulder Badge, in
* English only so far: in another language a name is never read.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_ItemListReader_H
#define PokemonAutomation_PokemonFRLG_ItemListReader_H

#include <string>
#include <vector>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/Language.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


// Rows a list shows at once.
constexpr int ITEM_LIST_ROWS = 6;

// Where row `row` (from 0) of a list shows its item's name, and in the bag
// its count, as fractions of the game screen.
ImageFloatBox item_list_name_box(int row);
ImageFloatBox bag_item_count_box(int row);

// The item named in row `row`: a slug such as "potion", "antidote",
// "parlyz-heal", "poke-ball", or "cancel" for the list's last row, in a
// game in `language`; empty if it can't be read, as in a language the
// reader has no names for.
std::string read_item_list_name(Logger& logger, Language language, const ImageViewRGB32& screen, int row);

struct BagRow{
// The item's slug, as read_item_list_name() gives it; empty if its name
// can't be read.
std::string item;
// -1 if the count couldn't be read: the row still holds at least one.
int count = 0;
};

// The rows of the bag's open pocket from the top, as pocket_rows() keeps
// them. The pocket must be scrolled to its top.
std::vector<BagRow> read_bag_pocket(Logger& logger, Language language, const ImageViewRGB32& screen);

// The rows of a pocket from `reads`, each row as read from the top: up to
// the CANCEL (not included). A row whose name can't be read stays, with an
// empty item, so the rows below keep their places: stopping there read
// nothing below a MOON STONE, and the rival was fought with 0 of the bag's
// 15 Potions (console B, 2026-11-03). Unread rows after the last name read
// are dropped. Empty if no name is read, as in a language the reader has
// no names for.
std::vector<BagRow> pocket_rows(std::vector<BagRow> reads);


void add_tests_ItemListReader(UnitTestDatabase& database);



}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Naming Screen Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/ImageTools/FloatPixel.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_NamingScreenDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

// Keyboard fill colors by page (keyboard.pal 13, 14, 15) as channel ratios:
// (123, 172, 197), (213, 156, 115), (148, 189, 106).
const FloatPixel KEYBOARD_COLORS[] = {
{0.250, 0.350, 0.400}, // upper case
{0.440, 0.322, 0.238}, // lower case
{0.334, 0.427, 0.239}, // symbols
};

bool is_keyboard_color(const ImageViewRGB32& image, const FloatPixel& color){
return is_solid(image, color, 0.08, 30);
}

}


// Boxes are fractions of the 240x160 GBA screen inside the game box.
NamingScreenDetector::NamingScreenDetector(Color color)
: m_color(color)
, m_keyboard_left_box(25.0 / 240, 82.0 / 160, 4.0 / 240, 60.0 / 160) // x 25-29, y 82-142
, m_keyboard_right_box(170.0 / 240, 82.0 / 160, 5.0 / 240, 60.0 / 160) // x 170-175, y 82-142
, m_entry_box(168.0 / 240, 50.0 / 160, 6.0 / 240, 12.0 / 160) // x 168-174, y 50-62
{}
void NamingScreenDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_left_box));
items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_right_box));
items.add(m_color, GAME_BOX.inner_to_outer(m_entry_box));
}
bool NamingScreenDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);
ImageViewRGB32 left = extract_box_reference(game_screen, m_keyboard_left_box);
ImageViewRGB32 right = extract_box_reference(game_screen, m_keyboard_right_box);
if (!is_white(extract_box_reference(game_screen, m_entry_box))){
return false;
}
for (const FloatPixel& color : KEYBOARD_COLORS){
if (is_keyboard_color(left, color) && is_keyboard_color(right, color)){
return true;
}
}
return false;
}


}
}
}
Loading
Loading