Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2871e3e
AutoStory: shared StoryLog and StoryRangeOptions (prep for #114, #312…
dayfine Nov 10, 2026
1ddd9aa
Merge autostory/r3-shared-stats (run report) into autostory/story-ran…
dayfine Nov 10, 2026
25331e3
AutoStory: move story_checkpoint_database() to AutoStorySelect
dayfine Nov 10, 2026
824117c
AutoStory: table-driven story_checkpoint_database() test
dayfine Nov 10, 2026
348ed17
AutoStory: describe checkpoint database entries without touching the …
dayfine Nov 10, 2026
495c7c1
Merge branch 'autostory/r3-shared-stats' into autostory/story-range-o…
dayfine Nov 10, 2026
8e82c9f
Merge autostory/r3-shared-stats into autostory/story-range-options
dayfine Nov 10, 2026
c7eae8a
Story range options: build test messages with std::format
dayfine Nov 10, 2026
9ea62b9
PokemonSV AutoStory: shared checkpoint range options and log lines
dayfine Nov 12, 2026
2b966b3
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 12, 2026
a59977a
Merge origin/autostory/story-range-options into sv/autostory-shared-s…
dayfine Nov 12, 2026
f49d02b
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 12, 2026
ae48485
Merge origin/autostory/story-range-options into sv/autostory-shared-s…
dayfine Nov 12, 2026
3429101
Merge sv/autostory-shared-story-options (#320) into autostory/story-r…
dayfine Nov 13, 2026
2fc9ada
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 13, 2026
ec64003
Merge branch 'autostory/r3-shared-stats' into autostory/story-range-o…
dayfine Nov 13, 2026
036d1d3
Merge remote-tracking branch 'origin/autostory/r3-shared-stats' into …
dayfine Nov 13, 2026
d24b86d
SV AutoStory: drop the log header include, now in the .cpp files via #45
dayfine Nov 13, 2026
35242c8
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 13, 2026
be8c044
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 13, 2026
62ec604
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 13, 2026
7ff24df
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 13, 2026
eacc561
Merge autostory/r3-shared-stats into autostory/story-range-options
dayfine Nov 14, 2026
8c2155f
Merge autostory/r3-shared-stats into autostory/story-range-options: a…
dayfine Nov 14, 2026
002a6eb
Merge autostory/r3-shared-stats into autostory/story-range-options
dayfine Nov 14, 2026
274bbda
Merge autostory/r3-shared-stats into autostory/story-range-options
dayfine Nov 14, 2026
cc6ed14
Merge origin/autostory/r3-shared-stats into autostory/story-range-opt…
dayfine Nov 15, 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
17 changes: 17 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PokemonAutomation_Pokemon_AutoStorySelect_H

#include <memory>
#include <span>
#include <string>
#include <vector>
#include "CommonTools/Options/StringSelectOption.h"
Expand Down Expand Up @@ -40,6 +41,22 @@ StringSelectDatabase make_story_select_database(
}


// The start/end dropdown database of a story's checkpoints, given by their
// labels in order ("00.09 Pewter Gym: Camper Liam, then Brock"), slugged
// by their index, as make_story_select_database() slugs SV's. A game whose
// story is in sections (BDSP's segments 00 and 01) passes them joined: a
// section's entry i is then story_index(true, i, first of the section).
// The program keeps it in a function-local static: the options hold a
// reference.
inline StringSelectDatabase story_checkpoint_database(std::span<const std::string> labels){

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not directly related here: but what if there are multiple orders, e.g. in FRLG for different starter choice? would that work with here?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for FRLG's starter choice. The starter doesn't change the order of checkpoints: every starter goes through the same story beats. Only what happens inside some of them changes, such as which ball to walk to and the rival's team. Today FRLG has one table (story_checkpoints()) and assumes Squirtle (TODO at PokemonFRLG_AutoStory.cpp:457). A starter option would feed into those events and battle data, as SV's STARTERCHOICE does, and this dropdown stays as it is.

It would break for a game whose order really branches, with different checkpoints per choice. The slugs are list indices, so a saved "12" would point at a different checkpoint in another order. The database is also a function-local static, so it can't follow an option change. The smallest fix is to keep one list with every branch's checkpoints and skip the ones that don't apply at run time, the way FRLG already joins or skips handoff rows. If we ever need several real lists, slug by checkpoint id ("01.05") instead of index, so saved settings stay valid. That isn't a one-liner, so I haven't done it here.

StringSelectDatabase database;
for (size_t c = 0; c < labels.size(); c++){
database.add_entry(StringSelectEntry(std::to_string(c), labels[c]));
}
return database;
}


// The index in the whole story list of entry `index_in_section` of the
// tutorial or the main story, whose first entry is `first_main_story_index`.
// NOTE: a section ends where the user must step in (e.g. level up the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
*/

#include <format>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -103,6 +104,66 @@
const AutoStorySelectScenario m_scenario;
};

// (slug, label) entries as [0 "label", ...].
std::string describe_entries(const std::vector<std::pair<std::string, std::string>>& entries){
std::string text;
for (const auto& [slug, label] : entries){
text += std::format("{}{} \"{}\"", text.empty() ? "" : ", ", slug, label);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a StrJoin function that avoid repeated append?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Common/Cpp/Strings (StringTools, Unicode) has no join helper, and nothing else in the repo has one. C++23 std::views::join_with would do it, but older libc++ (the Mac CI's Xcode) doesn't have it yet, so I left this loop as it is. It's a small test-only helper. A shared join in StringTools would be its own PR.

}
return std::format("[{}]", text);
}

// A game's checkpoint labels, in story order.
struct StoryCheckpointDatabaseInput{
std::string name;
std::vector<std::string> labels;
};

// The (slug, label) entries: one per label, in order, slugged by its index.
struct StoryCheckpointDatabaseExpectation{
std::vector<std::pair<std::string, std::string>> entries;
};

// story_checkpoint_database() over a game's labels and the entries it must make.
struct StoryCheckpointDatabaseCase{
StoryCheckpointDatabaseInput input;
StoryCheckpointDatabaseExpectation expectation;
};

class Test_StoryCheckpointDatabase : public UnitTest{

Check failure on line 133 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

test-case: construct each UnitTest from one case struct with name, input and expectation fields (input and expectation structs, the name outside the input); register a named table of designated cases in a range-for
public:
Test_StoryCheckpointDatabase(StoryCheckpointDatabaseCase test_case)
: UnitTest(std::format("Pokemon::AutoStorySelectDatabase - {}", test_case.input.name))
, m_case(std::move(test_case))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const StringSelectDatabase database = story_checkpoint_database(m_case.input.labels);
std::vector<std::pair<std::string, std::string>> got;
for (const StringSelectEntry& entry : database.case_list()){
got.emplace_back(entry.slug, entry.display_name);
}
if (got != m_case.expectation.entries){
return std::format("Expected {}, got {}", describe_entries(m_case.expectation.entries), describe_entries(got));
}
return true;
}

private:
const StoryCheckpointDatabaseCase m_case;
};

const StoryCheckpointDatabaseCase STORY_CHECKPOINT_DATABASE_CASES[] = {
{
.input = {.name = "checkpoint labels slugged by index", .labels = {"00.01 Pallet Town", "00.02 Oak's lab"}},
.expectation = {.entries = {{"0", "00.01 Pallet Town"}, {"1", "00.02 Oak's lab"}}},
},
{
.input = {.name = "no checkpoints, no entries", .labels = {}},
.expectation = {.entries = {}},
},
};

void add_index_tests(UnitTestDatabase& database){
const AutoStoryIndexScenario scenarios[] = {
{
Expand Down Expand Up @@ -134,7 +195,7 @@
}
}

void add_select_database_tests(UnitTestDatabase& database){

Check warning on line 198 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::add_select_database_tests( UnitTestDatabase & database): function_lines=28 (advisory above 25, limit 50)
const AutoStorySelectScenario select_scenarios[] = {
{
.name = "the tutorial dropdown",
Expand All @@ -158,6 +219,9 @@
for (const AutoStorySelectScenario& scenario : select_scenarios){
database.add<Test_AutoStorySelectDatabase>(scenario);
}
for (const StoryCheckpointDatabaseCase& test_case : STORY_CHECKPOINT_DATABASE_CASES){
database.add<Test_StoryCheckpointDatabase>(test_case);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define PokemonAutomation_Pokemon_AutoStory_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h"
#include "Pokemon_AutoStorySelect_Tests.h"
#include "Pokemon_StoryLog_Tests.h"

Expand All @@ -23,6 +24,7 @@ namespace Pokemon{
inline void add_tests_AutoStory(UnitTestDatabase& database){
add_tests_AutoStorySelect(database);
add_tests_StoryLog(database);
add_tests_StoryRangeOptions(database);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Story Range Options
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <utility>
#include "Pokemon_StoryRangeOptions.h"

namespace PokemonAutomation{
namespace Pokemon{


StoryRangeOptions::StoryRangeOptions(std::string label, const StringSelectDatabase& checkpoints, LockMode end_lock)
: GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING)
, START_CHECKPOINT(
"<b>Start checkpoint:</b><br>The program starts from this checkpoint's save.",
checkpoints,
LockMode::LOCK_WHILE_RUNNING,
0
)
, END_CHECKPOINT(
"<b>End checkpoint:</b><br>The program stops after this checkpoint.",
checkpoints,
end_lock,
checkpoints.size() == 0 ? 0 : checkpoints.size() - 1
)
{
PA_ADD_OPTION(START_CHECKPOINT);
PA_ADD_OPTION(END_CHECKPOINT);
}

size_t StoryRangeOptions::start_index() const{
return START_CHECKPOINT.index();
}

size_t StoryRangeOptions::end_index() const{
return END_CHECKPOINT.index();
}

std::string StoryRangeOptions::check_validity() const{
if (start_index() > end_index()){
return "The start checkpoint comes after the end checkpoint.";
}
return GroupOption::check_validity();
}



} // namespace Pokemon
} // namespace PokemonAutomation
53 changes: 53 additions & 0 deletions SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Story Range Options
*
* From: https://github.com/PokemonAutomation/
*
* The start and end checkpoint dropdowns of an AutoStory program, over one
* list of the story's checkpoints, and the check that the start does not
* come after the end. StoryRunOptions (Pokemon_StoryRunOptions.h) is this
* group plus the run policy.
*
*/

#ifndef PokemonAutomation_Pokemon_StoryRangeOptions_H
#define PokemonAutomation_Pokemon_StoryRangeOptions_H

#include <string>
#include "Common/Cpp/Options/GroupOption.h"
#include "CommonTools/Options/StringSelectOption.h"

namespace PokemonAutomation{
namespace Pokemon{


// A program shows the group, or adds START_CHECKPOINT and END_CHECKPOINT
// to its own options under its own keys (keeping the keys its saved
// settings already use) and calls check_validity() from its own.
class StoryRangeOptions : public GroupOption{
public:
// `checkpoints`: the dropdown database (make_story_select_database()
// or story_checkpoint_database()), kept alive by the caller. The
// dropdowns start on its first and last entries. `end_lock`:
// UNLOCK_WHILE_RUNNING for a program that reads the end after each
// checkpoint, so the end can be moved during a run.
StoryRangeOptions(
std::string label, const StringSelectDatabase& checkpoints,
LockMode end_lock = LockMode::LOCK_WHILE_RUNNING
);

// The checkpoints chosen, by index in the database, both inclusive.
size_t start_index() const;
size_t end_index() const;
// "The start checkpoint comes after the end checkpoint." if it does.
virtual std::string check_validity() const override;

public:
StringSelectOption START_CHECKPOINT;
StringSelectOption END_CHECKPOINT;
};



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* Story Range Options Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h"
#include "Pokemon_StoryRangeOptions.h"
#include "Pokemon_StoryRangeOptions_Tests.h"

namespace PokemonAutomation{
namespace Pokemon{

namespace{

// A stand-in for a story checkpoint: only its name is read.
struct NamedCheckpoint{
std::string label;
std::string name() const{
return label;
}
};

// Two tutorial checkpoints, then three of the main story, as SV's list is
// laid out.
const std::vector<std::unique_ptr<NamedCheckpoint>>& story_list(){
static const std::vector<std::unique_ptr<NamedCheckpoint>> list = []{
std::vector<std::unique_ptr<NamedCheckpoint>> ret;
for (std::string_view label : {"tutorial 0", "tutorial 1", "main 0", "main 1", "main 2"}){
ret.emplace_back(std::make_unique<NamedCheckpoint>(NamedCheckpoint{.label = std::string(label)}));
}
return ret;
}();
return list;
}

// The main story's dropdowns: entries 2..4 of the list, slugged 2..4.
const StringSelectDatabase& main_story_database(){
static const StringSelectDatabase database = make_story_select_database(story_list(), 2, story_list().size());
return database;
}

// The start and end set by slug, as saved settings load them; empty
// leaves the default.
struct StoryRangeInput{
std::string name;
std::string start_slug;
std::string end_slug;
};

// The indexes in the dropdown, and whether the range is valid.
struct StoryRangeExpectation{
size_t start;
size_t end;
bool valid;
};

// A range chosen in the main story's dropdowns and what the group reads from it.
struct StoryRangeCase{
StoryRangeInput input;
StoryRangeExpectation expectation;
};

class Test_StoryRange : public UnitTest{

Check failure on line 71 in SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

test-case: construct each UnitTest from one case struct with name, input and expectation fields (input and expectation structs, the name outside the input); register a named table of designated cases in a range-for
public:
Test_StoryRange(StoryRangeCase test_case)
: UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.input.name))
, m_case(std::move(test_case))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
StoryRangeOptions range("Checkpoints", main_story_database());
if (!m_case.input.start_slug.empty()){
range.START_CHECKPOINT.set_by_slug(m_case.input.start_slug);
}
if (!m_case.input.end_slug.empty()){
range.END_CHECKPOINT.set_by_slug(m_case.input.end_slug);
}
const StoryRangeExpectation& expected = m_case.expectation;
if (range.start_index() != expected.start || range.end_index() != expected.end){
return std::format(
"Expected indexes {} to {}, got {} to {}",
expected.start, expected.end, range.start_index(), range.end_index()
);
}
const std::string error = range.check_validity();
if (error.empty() != expected.valid){
return expected.valid ? std::format("Expected a valid range, got: {}", error) : "Expected the range refused.";
}
if (!expected.valid && error != "The start checkpoint comes after the end checkpoint."){
return std::format("Unexpected message: {}", error);
}
return true;
}

private:
const StoryRangeCase m_case;
};

const StoryRangeCase STORY_RANGE_CASES[] = {
{
.input = {.name = "the whole database by default", .start_slug = "", .end_slug = ""},
.expectation = {.start = 0, .end = 2, .valid = true},
},
{
.input = {.name = "slugs are whole-list indexes, indexes are the dropdown's", .start_slug = "3", .end_slug = "4"},
.expectation = {.start = 1, .end = 2, .valid = true},
},
{
.input = {.name = "one checkpoint", .start_slug = "3", .end_slug = "3"},
.expectation = {.start = 1, .end = 1, .valid = true},
},
{
.input = {.name = "a start after the end is refused", .start_slug = "4", .end_slug = "2"},
.expectation = {.start = 2, .end = 0, .valid = false},
},
};

} // namespace


void add_tests_StoryRangeOptions(UnitTestDatabase& database){
for (const StoryRangeCase& test_case : STORY_RANGE_CASES){
database.add<Test_StoryRange>(test_case);
}
}



} // namespace Pokemon
} // namespace PokemonAutomation
Loading
Loading