From 7078725aedfad31e63e3422b73c25458f0814224 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 12:42:59 -0800 Subject: [PATCH 1/4] AutoStory: shared start/end checkpoint range options; SV uses them StoryRangeOptions holds the start and end checkpoint dropdowns over one story list and checks the start does not come after the end. SV's tutorial and main-story checkpoint pairs now use it, adding the dropdowns under their old keys and with their old labels, defaults and lock modes, so saved settings still load. --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../Options/Pokemon_StoryRangeOptions.cpp | 61 ++++++ .../Options/Pokemon_StoryRangeOptions.h | 59 +++++ .../Pokemon_StoryRangeOptions_Tests.cpp | 206 ++++++++++++++++++ .../Options/Pokemon_StoryRangeOptions_Tests.h | 23 ++ .../AutoStory/PokemonSV_AutoStory.cpp | 71 +++--- .../Programs/AutoStory/PokemonSV_AutoStory.h | 14 +- SerialPrograms/cmake/SourceFiles.cmake | 4 + 8 files changed, 395 insertions(+), 45 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index b09a6b3cdf..03cded771c 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -15,6 +15,7 @@ #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" +#include "Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -72,6 +73,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ OCR::add_tests(ret); Kernels::add_tests(ret); Pokemon::add_tests_AutoStorySelect(ret); + Pokemon::add_tests_StoryRangeOptions(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp new file mode 100644 index 0000000000..6b548f5447 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp @@ -0,0 +1,61 @@ +/* Story Range Options + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryRangeOptions.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +StoryRangeOptions::DropdownLabels StoryRangeOptions::default_labels(){ + return DropdownLabels{ + .start = "Start checkpoint:
The program starts from this checkpoint's save.", + .end = "End checkpoint:
The program stops after this checkpoint.", + }; +} + +StoryRangeOptions::StoryRangeOptions( + std::string label, const StringSelectDatabase& checkpoints, + LockMode end_lock, DropdownLabels labels +) + : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) + , START_CHECKPOINT( + std::move(labels.start), + checkpoints, + LockMode::LOCK_WHILE_RUNNING, + 0 + ) + , END_CHECKPOINT( + std::move(labels.end), + 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 diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h new file mode 100644 index 0000000000..3d7e78ba02 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h @@ -0,0 +1,59 @@ +/* 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. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRangeOptions_H +#define PokemonAutomation_Pokemon_StoryRangeOptions_H + +#include +#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: + // The labels of the two dropdowns. + struct DropdownLabels{ + std::string start; + std::string end; + }; + static DropdownLabels default_labels(); + + // `checkpoints`: the dropdown database (make_story_select_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, + DropdownLabels labels = default_labels() + ); + + // 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 diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp new file mode 100644 index 0000000000..57d92e345e --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -0,0 +1,206 @@ +/* Story Range Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#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>& story_list(){ + static const std::vector> list = []{ + std::vector> ret; + for (std::string_view label : {"tutorial 0", "tutorial 1", "main 0", "main 1", "main 2"}){ + ret.emplace_back(std::make_unique(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; +} + +// A range chosen in the main story's dropdowns and what the group reads from it. +struct StoryRangeCase{ + // The start and end set by slug, as saved settings load them; empty + // leaves the default. + struct Input{ + std::string start_slug; + std::string end_slug; + }; + + // The indexes in the dropdown, and whether the range is valid. + struct Expectation{ + size_t start; + size_t end; + bool valid; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_StoryRange : public UnitTest{ +public: + Test_StoryRange(StoryRangeCase test_case) + : UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.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 StoryRangeCase::Expectation& 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[] = { + { + .name = "the whole database by default", + .input = {.start_slug = "", .end_slug = ""}, + .expectation = {.start = 0, .end = 2, .valid = true}, + }, + { + .name = "slugs are whole-list indexes, indexes are the dropdown's", + .input = {.start_slug = "3", .end_slug = "4"}, + .expectation = {.start = 1, .end = 2, .valid = true}, + }, + { + .name = "one checkpoint", + .input = {.start_slug = "3", .end_slug = "3"}, + .expectation = {.start = 1, .end = 1, .valid = true}, + }, + { + .name = "a start after the end is refused", + .input = {.start_slug = "4", .end_slug = "2"}, + .expectation = {.start = 2, .end = 0, .valid = false}, + }, +}; + +// The dropdown labels a program passes, and the labels the dropdowns show. +struct StoryRangeLabelsCase{ + // The labels passed to the constructor; none uses the default. + struct Input{ + std::optional labels; + }; + + // The labels of the start and end dropdowns. + struct Expectation{ + std::string start; + std::string end; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_StoryRangeLabels : public UnitTest{ +public: + Test_StoryRangeLabels(StoryRangeLabelsCase test_case) + : UnitTest(std::format("Pokemon::StoryRangeOptions labels - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional& labels = m_case.input.labels; + const StoryRangeOptions range = labels + ? StoryRangeOptions("Checkpoints", main_story_database(), LockMode::LOCK_WHILE_RUNNING, *labels) + : StoryRangeOptions("Checkpoints", main_story_database()); + const StoryRangeLabelsCase::Expectation& expected = m_case.expectation; + if (range.START_CHECKPOINT.label() != expected.start || range.END_CHECKPOINT.label() != expected.end){ + return std::format( + "Expected labels \"{}\" and \"{}\", got \"{}\" and \"{}\"", + expected.start, expected.end, range.START_CHECKPOINT.label(), range.END_CHECKPOINT.label() + ); + } + return true; + } + +private: + const StoryRangeLabelsCase m_case; +}; + +const StoryRangeLabelsCase STORY_RANGE_LABELS_CASES[] = { + { + .name = "the shared labels by default", + .input = {.labels = std::nullopt}, + .expectation = { + .start = "Start checkpoint:
The program starts from this checkpoint's save.", + .end = "End checkpoint:
The program stops after this checkpoint.", + }, + }, + { + .name = "a program keeps its own labels", + .input = {.labels = StoryRangeOptions::DropdownLabels{.start = "Start Checkpoint:", .end = "End Checkpoint:"}}, + .expectation = {.start = "Start Checkpoint:", .end = "End Checkpoint:"}, + }, +}; + +} // namespace + + +void add_tests_StoryRangeOptions(UnitTestDatabase& database){ + for (const StoryRangeCase& test_case : STORY_RANGE_CASES){ + database.add(test_case); + } + for (const StoryRangeLabelsCase& test_case : STORY_RANGE_LABELS_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h new file mode 100644 index 0000000000..1d3e48e19d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h @@ -0,0 +1,23 @@ +/* Story Range Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRangeOptions_Tests_H +#define PokemonAutomation_Pokemon_StoryRangeOptions_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared start/end checkpoint range options. +void add_tests_StoryRangeOptions(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 130271139b..4ef04a88d4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -347,6 +347,10 @@ AutoStory::~AutoStory(){ ENDPOINT_TUTORIAL.remove_listener(*this); STARTPOINT_MAINSTORY.remove_listener(*this); ENDPOINT_MAINSTORY.remove_listener(*this); + TUTORIAL_CHECKPOINTS.START_CHECKPOINT.remove_listener(*this); + TUTORIAL_CHECKPOINTS.END_CHECKPOINT.remove_listener(*this); + MAINSTORY_CHECKPOINTS.START_CHECKPOINT.remove_listener(*this); + MAINSTORY_CHECKPOINTS.END_CHECKPOINT.remove_listener(*this); ENABLE_TEST_CHECKPOINTS.remove_listener(*this); ENABLE_MISC_TEST.remove_listener(*this); TEST_PBF_LEFT_JOYSTICK.remove_listener(*this); @@ -395,30 +399,15 @@ AutoStory::AutoStory() LockMode::UNLOCK_WHILE_RUNNING, std::to_string(ALL_SEGMENTS_SELECT_DATABASE().case_list().size()-1) ) - , START_CHECKPOINT_TUTORIAL( - "Start Checkpoint:", //
Program will start with this checkpoint. - TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), - LockMode::LOCK_WHILE_RUNNING, - "0" + // The end is read after each checkpoint, so it stays unlocked. + , TUTORIAL_CHECKPOINTS( + "Tutorial Checkpoints", TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING, + {.start = "Start Checkpoint:", .end = "End Checkpoint:"} ) - , END_CHECKPOINT_TUTORIAL( - "End Checkpoint:", //
Program will stop after completing this checkpoint. - TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), - LockMode::UNLOCK_WHILE_RUNNING, - std::to_string(INDEX_OF_LAST_TUTORIAL_CHECKPOINT) - ) - , START_CHECKPOINT_MAINSTORY( - "Start Checkpoint:", //
Program will start with this checkpoint. - MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), - LockMode::LOCK_WHILE_RUNNING, - std::to_string(INDEX_OF_LAST_TUTORIAL_CHECKPOINT+1) + , MAINSTORY_CHECKPOINTS( + "Main Story Checkpoints", MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING, + {.start = "Start Checkpoint:", .end = "End Checkpoint:"} ) - , END_CHECKPOINT_MAINSTORY( - "End Checkpoint:", //
Program will stop after completing this checkpoint. - MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), - LockMode::UNLOCK_WHILE_RUNNING, - std::to_string(ALL_CHECKPOINTS_SELECT_DATABASE().case_list().size()-1) - ) , SETUP_NOTE{ "NOTE: Make sure you have selected the correct Start Point. " "Make sure your player character is in the exact correct start position for that Start Point, " @@ -710,11 +699,11 @@ AutoStory::AutoStory() PA_ADD_OPTION(ENDPOINT_MAINSTORY); PA_ADD_OPTION(END_DESCRIPTION); - PA_ADD_OPTION(START_CHECKPOINT_TUTORIAL); - PA_ADD_OPTION(START_CHECKPOINT_MAINSTORY); + add_option(TUTORIAL_CHECKPOINTS.START_CHECKPOINT, "START_CHECKPOINT_TUTORIAL"); + add_option(MAINSTORY_CHECKPOINTS.START_CHECKPOINT, "START_CHECKPOINT_MAINSTORY"); PA_ADD_OPTION(START_CHECKPOINT_DESCRIPTION); - PA_ADD_OPTION(END_CHECKPOINT_TUTORIAL); - PA_ADD_OPTION(END_CHECKPOINT_MAINSTORY); + add_option(TUTORIAL_CHECKPOINTS.END_CHECKPOINT, "END_CHECKPOINT_TUTORIAL"); + add_option(MAINSTORY_CHECKPOINTS.END_CHECKPOINT, "END_CHECKPOINT_MAINSTORY"); PA_ADD_OPTION(END_CHECKPOINT_DESCRIPTION); PA_ADD_OPTION(STARTERCHOICE); @@ -738,10 +727,10 @@ AutoStory::AutoStory() STARTPOINT_MAINSTORY.add_listener(*this); ENDPOINT_MAINSTORY.add_listener(*this); - START_CHECKPOINT_TUTORIAL.add_listener(*this); - END_CHECKPOINT_TUTORIAL.add_listener(*this); - START_CHECKPOINT_MAINSTORY.add_listener(*this); - END_CHECKPOINT_MAINSTORY.add_listener(*this); + TUTORIAL_CHECKPOINTS.START_CHECKPOINT.add_listener(*this); + TUTORIAL_CHECKPOINTS.END_CHECKPOINT.add_listener(*this); + MAINSTORY_CHECKPOINTS.START_CHECKPOINT.add_listener(*this); + MAINSTORY_CHECKPOINTS.END_CHECKPOINT.add_listener(*this); ENABLE_ADVANCED_MODE.add_listener(*this); @@ -769,10 +758,10 @@ void AutoStory::on_config_value_changed(void* object){ STARTPOINT_MAINSTORY.set_visibility(mainstory_segments ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); ENDPOINT_MAINSTORY.set_visibility(mainstory_segments ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); - START_CHECKPOINT_TUTORIAL.set_visibility(tutorial_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); - END_CHECKPOINT_TUTORIAL.set_visibility(tutorial_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); - START_CHECKPOINT_MAINSTORY.set_visibility(mainstory_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); - END_CHECKPOINT_MAINSTORY.set_visibility(mainstory_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); + TUTORIAL_CHECKPOINTS.START_CHECKPOINT.set_visibility(tutorial_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); + TUTORIAL_CHECKPOINTS.END_CHECKPOINT.set_visibility(tutorial_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); + MAINSTORY_CHECKPOINTS.START_CHECKPOINT.set_visibility(mainstory_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); + MAINSTORY_CHECKPOINTS.END_CHECKPOINT.set_visibility(mainstory_checkpoints ? ConfigOptionState::ENABLED : ConfigOptionState::HIDDEN); MAINSTORY_NOTE.set_visibility(STORY_SECTION == StorySection::TUTORIAL ? ConfigOptionState::HIDDEN : ConfigOptionState::ENABLED); START_DESCRIPTION.set_text(start_segment_description()); @@ -1063,20 +1052,22 @@ std::string AutoStory::end_checkpoint_description(){ return " End: " + ALL_AUTO_STORY_CHECKPOINT_LIST()[checkpoint_index]->end_text(); } +const Pokemon::StoryRangeOptions& AutoStory::checkpoint_range() const{ + return STORY_SECTION == StorySection::MAIN_STORY ? MAINSTORY_CHECKPOINTS : TUTORIAL_CHECKPOINTS; +} + size_t AutoStory::get_start_checkpoint_index(){ - const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; return story_index( - main_story, - main_story ? START_CHECKPOINT_MAINSTORY.index() : START_CHECKPOINT_TUTORIAL.index(), + STORY_SECTION == StorySection::MAIN_STORY, + checkpoint_range().start_index(), INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 ); } size_t AutoStory::get_end_checkpoint_index(){ - const bool main_story = STORY_SECTION == StorySection::MAIN_STORY; return story_index( - main_story, - main_story ? END_CHECKPOINT_MAINSTORY.index() : END_CHECKPOINT_TUTORIAL.index(), + STORY_SECTION == StorySection::MAIN_STORY, + checkpoint_range().end_index(), INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 ); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h index d62d9b2ad2..cce4d9035c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h @@ -16,6 +16,7 @@ #include "CommonTools/Options/StringSelectOption.h" #include "CommonTools/Options/LanguageOCROption.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Pokemon/Options/Pokemon_StoryRangeOptions.h" #include "PokemonSV_AutoStoryTools.h" namespace PokemonAutomation{ @@ -69,6 +70,9 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste std::string start_checkpoint_description(); std::string end_checkpoint_description(); + // The checkpoint range of the chosen story section. + const Pokemon::StoryRangeOptions& checkpoint_range() const; + private: OCR::LanguageOCROption LANGUAGE; @@ -85,11 +89,11 @@ class AutoStory : public SingleSwitchProgramInstance, public ConfigOption::Liste StringSelectOption STARTPOINT_MAINSTORY; StringSelectOption ENDPOINT_MAINSTORY; - StringSelectOption START_CHECKPOINT_TUTORIAL; - StringSelectOption END_CHECKPOINT_TUTORIAL; - - StringSelectOption START_CHECKPOINT_MAINSTORY; - StringSelectOption END_CHECKPOINT_MAINSTORY; + // The start/end checkpoint range of each section. Their dropdowns are + // added to this program's options directly, under the keys saved + // settings already use. + Pokemon::StoryRangeOptions TUTORIAL_CHECKPOINTS; + Pokemon::StoryRangeOptions MAINSTORY_CHECKPOINTS; StaticTextOption SETUP_NOTE; StaticTextOption MAINSTORY_NOTE; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ec3c844522..a8c5e2d9a5 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1476,6 +1476,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_NameSelectWidget.h Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp Source/Pokemon/Options/Pokemon_StatsHuntFilter.h + Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp + Source/Pokemon/Options/Pokemon_StoryRangeOptions.h + Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp + Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h From fd8c614b9cc4084eac06d71a6e5ba479d68cd9de Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 15:29:39 -0800 Subject: [PATCH 2/4] AutoStory: move StoryRangeOptions to Pokemon/AutoStory/Options; add_tests_AutoStory collects the AutoStory suites --- .../ComputerPrograms_UnitTestRunner.cpp | 6 ++-- .../Options/Pokemon_StoryRangeOptions.cpp | 0 .../Options/Pokemon_StoryRangeOptions.h | 0 .../Pokemon_StoryRangeOptions_Tests.cpp | 0 .../Options/Pokemon_StoryRangeOptions_Tests.h | 0 .../AutoStory/Pokemon_AutoStory_Tests.h | 32 +++++++++++++++++++ .../Programs/AutoStory/PokemonSV_AutoStory.h | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 9 +++--- 8 files changed, 40 insertions(+), 9 deletions(-) rename SerialPrograms/Source/Pokemon/{ => AutoStory}/Options/Pokemon_StoryRangeOptions.cpp (100%) rename SerialPrograms/Source/Pokemon/{ => AutoStory}/Options/Pokemon_StoryRangeOptions.h (100%) rename SerialPrograms/Source/Pokemon/{ => AutoStory}/Options/Pokemon_StoryRangeOptions_Tests.cpp (100%) rename SerialPrograms/Source/Pokemon/{ => AutoStory}/Options/Pokemon_StoryRangeOptions_Tests.h (100%) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 03cded771c..f83b4ef374 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -14,8 +14,7 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" -#include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" -#include "Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h" +#include "Pokemon/AutoStory/Pokemon_AutoStory_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -72,8 +71,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ add_tests_AudioFileLoader(ret); OCR::add_tests(ret); Kernels::add_tests(ret); - Pokemon::add_tests_AutoStorySelect(ret); - Pokemon::add_tests_StoryRangeOptions(ret); + Pokemon::add_tests_AutoStory(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp similarity index 100% rename from SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp rename to SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h similarity index 100% rename from SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h rename to SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp similarity index 100% rename from SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp rename to SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.h similarity index 100% rename from SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h rename to SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h new file mode 100644 index 0000000000..c10d032f14 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -0,0 +1,32 @@ +/* AutoStory Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The unit tests of the pieces every AutoStory program shares. + * add_tests_AutoStory() is the one entry point the unit test runner calls; + * a new shared AutoStory suite registers there. + * + */ + +#ifndef PokemonAutomation_Pokemon_AutoStory_Tests_H +#define PokemonAutomation_Pokemon_AutoStory_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Options/Pokemon_StoryRangeOptions_Tests.h" +#include "Pokemon_AutoStorySelect_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers every shared AutoStory suite, for the unit test runner. +inline void add_tests_AutoStory(UnitTestDatabase& database){ + add_tests_AutoStorySelect(database); + add_tests_StoryRangeOptions(database); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h index cce4d9035c..244e51b02f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h @@ -16,7 +16,7 @@ #include "CommonTools/Options/StringSelectOption.h" #include "CommonTools/Options/LanguageOCROption.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" -#include "Pokemon/Options/Pokemon_StoryRangeOptions.h" +#include "Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h" #include "PokemonSV_AutoStoryTools.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a8c5e2d9a5..079ecd8d38 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1476,13 +1476,14 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Options/Pokemon_NameSelectWidget.h Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp Source/Pokemon/Options/Pokemon_StatsHuntFilter.h - Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp - Source/Pokemon/Options/Pokemon_StoryRangeOptions.h - Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp - Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h + Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h + Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp + Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h + Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp + Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From a530244fd37578c1ada0e0126c2ad16a6cf038f5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 15:30:38 -0800 Subject: [PATCH 3/4] StoryRangeOptions: review fixes (string_view label, one parameter per line, comments); SV drops unneeded remove_listener calls --- .../Options/Pokemon_StoryRangeOptions.cpp | 12 ++++++---- .../Options/Pokemon_StoryRangeOptions.h | 12 +++++----- .../AutoStory/PokemonSV_AutoStory.cpp | 24 +++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp index 6b548f5447..86189340fd 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.cpp @@ -19,21 +19,23 @@ StoryRangeOptions::DropdownLabels StoryRangeOptions::default_labels(){ } StoryRangeOptions::StoryRangeOptions( - std::string label, const StringSelectDatabase& checkpoints, - LockMode end_lock, DropdownLabels labels + std::string_view label, + const StringSelectDatabase& checkpoints, + LockMode end_lock, + DropdownLabels labels ) - : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) + : GroupOption(std::string(label), LockMode::LOCK_WHILE_RUNNING) , START_CHECKPOINT( std::move(labels.start), checkpoints, LockMode::LOCK_WHILE_RUNNING, - 0 + /*default_index=*/0 ) , END_CHECKPOINT( std::move(labels.end), checkpoints, end_lock, - checkpoints.size() == 0 ? 0 : checkpoints.size() - 1 + /*default_index=*/checkpoints.size() == 0 ? 0 : checkpoints.size() - 1 ) { PA_ADD_OPTION(START_CHECKPOINT); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h index 3d7e78ba02..cafedce63c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h @@ -12,6 +12,7 @@ #define PokemonAutomation_Pokemon_StoryRangeOptions_H #include +#include #include "Common/Cpp/Options/GroupOption.h" #include "CommonTools/Options/StringSelectOption.h" @@ -19,9 +20,8 @@ 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. +// The options in an AutoStory program that pick the range of checkpoints +// to run. class StoryRangeOptions : public GroupOption{ public: // The labels of the two dropdowns. @@ -36,7 +36,8 @@ class StoryRangeOptions : public GroupOption{ // 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, + std::string_view label, + const StringSelectDatabase& checkpoints, LockMode end_lock = LockMode::LOCK_WHILE_RUNNING, DropdownLabels labels = default_labels() ); @@ -44,10 +45,9 @@ class StoryRangeOptions : public GroupOption{ // 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. + // Checks that the start checkpoint does not come after the end. virtual std::string check_validity() const override; -public: StringSelectOption START_CHECKPOINT; StringSelectOption END_CHECKPOINT; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 4ef04a88d4..9496e8310b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -347,10 +347,6 @@ AutoStory::~AutoStory(){ ENDPOINT_TUTORIAL.remove_listener(*this); STARTPOINT_MAINSTORY.remove_listener(*this); ENDPOINT_MAINSTORY.remove_listener(*this); - TUTORIAL_CHECKPOINTS.START_CHECKPOINT.remove_listener(*this); - TUTORIAL_CHECKPOINTS.END_CHECKPOINT.remove_listener(*this); - MAINSTORY_CHECKPOINTS.START_CHECKPOINT.remove_listener(*this); - MAINSTORY_CHECKPOINTS.END_CHECKPOINT.remove_listener(*this); ENABLE_TEST_CHECKPOINTS.remove_listener(*this); ENABLE_MISC_TEST.remove_listener(*this); TEST_PBF_LEFT_JOYSTICK.remove_listener(*this); @@ -401,11 +397,15 @@ AutoStory::AutoStory() ) // The end is read after each checkpoint, so it stays unlocked. , TUTORIAL_CHECKPOINTS( - "Tutorial Checkpoints", TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING, + "Tutorial Checkpoints", + TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), + LockMode::UNLOCK_WHILE_RUNNING, {.start = "Start Checkpoint:", .end = "End Checkpoint:"} ) , MAINSTORY_CHECKPOINTS( - "Main Story Checkpoints", MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING, + "Main Story Checkpoints", + MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), + LockMode::UNLOCK_WHILE_RUNNING, {.start = "Start Checkpoint:", .end = "End Checkpoint:"} ) , SETUP_NOTE{ @@ -1058,17 +1058,17 @@ const Pokemon::StoryRangeOptions& AutoStory::checkpoint_range() const{ size_t AutoStory::get_start_checkpoint_index(){ return story_index( - STORY_SECTION == StorySection::MAIN_STORY, - checkpoint_range().start_index(), - INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + /*main_story=*/STORY_SECTION == StorySection::MAIN_STORY, + /*index_in_section=*/checkpoint_range().start_index(), + /*first_main_story_index=*/INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 ); } size_t AutoStory::get_end_checkpoint_index(){ return story_index( - STORY_SECTION == StorySection::MAIN_STORY, - checkpoint_range().end_index(), - INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 + /*main_story=*/STORY_SECTION == StorySection::MAIN_STORY, + /*index_in_section=*/checkpoint_range().end_index(), + /*first_main_story_index=*/INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1 ); } From 0758e5c2443b81c1031def2a6b1793ee698a8a2e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 15:59:34 -0800 Subject: [PATCH 4/4] StoryRangeOptions: end_lock doc on its own line; parameter comments in the test database --- .../Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h | 5 +++-- .../AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h index cafedce63c..76671cc3d9 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h @@ -33,8 +33,9 @@ class StoryRangeOptions : public GroupOption{ // `checkpoints`: the dropdown database (make_story_select_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. + // 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_view label, const StringSelectDatabase& checkpoints, diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp index 57d92e345e..0d729506aa 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -44,7 +44,11 @@ const std::vector>& story_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()); + static const StringSelectDatabase database = make_story_select_database( + story_list(), + /*first=*/2, + /*last=*/story_list().size() + ); return database; }