From 2871e3ef2b0fd3db9bd609c7fb7ec2392d801fc0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 23:48:34 -0800 Subject: [PATCH 1/7] AutoStory: shared StoryLog and StoryRangeOptions (prep for #114, #312, #320) StoryLog (checkpoint log lines, stats counts) and StoryRangeOptions (the start/end checkpoint dropdowns, story_checkpoint_database()) moved unchanged from #312, so the SV program (#320) and the engine (#114) can share them without the story engine. story_checkpoint_database() now takes the checkpoints' labels instead of StoryCheckpoint. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 3 + .../Pokemon/AutoStory/Pokemon_StoryLog.cpp | 73 ++++++++ .../Pokemon/AutoStory/Pokemon_StoryLog.h | 76 ++++++++ .../AutoStory/Pokemon_StoryLog_Tests.cpp | 173 ++++++++++++++++++ .../AutoStory/Pokemon_StoryRun_Tests.h | 28 +++ .../Options/Pokemon_StoryRangeOptions.cpp | 60 ++++++ .../Options/Pokemon_StoryRangeOptions.h | 64 +++++++ .../Pokemon_StoryRangeOptions_Tests.cpp | 135 ++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 7 + 9 files changed, 619 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h 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 diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 43d70b5ecf..223a31bc75 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -14,6 +14,7 @@ #include "Common/Qt/QtThreadPool_Tests.h" #include "Kernels/Kernels_Tests.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h" +#include "Pokemon/AutoStory/Pokemon_StoryRun_Tests.h" #include "CommonFramework/AudioPipeline/AudioInfo_Tests.h" #include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h" #include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h" @@ -69,6 +70,8 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ OCR::add_tests(ret); Kernels::add_tests(ret); Pokemon::add_tests_AutoStorySelect(ret); + Pokemon::add_tests_StoryLog(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/AutoStory/Pokemon_StoryLog.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp new file mode 100644 index 0000000000..0a9262d2c0 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp @@ -0,0 +1,73 @@ +/* Story Log + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryLog.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +std::string resets_text(size_t attempt){ + if (attempt <= 1){ + return "one-shot"; + } + return std::format("{} reset{}", attempt - 1, attempt == 2 ? "" : "s"); +} + +} // namespace + + +std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status){ + return std::format("[Event] {}/{} {}: {}", checkpoint, number, event, status); +} + +std::string checkpoint_start_line(std::string_view checkpoint, std::optional events){ + if (!events){ + return std::format("[Checkpoint] {}: start", checkpoint); + } + return std::format("[Checkpoint] {}: start, {} events", checkpoint, *events); +} + +std::string checkpoint_attempt_line(std::string_view checkpoint, size_t attempt, std::optional attempts){ + if (!attempts){ + return std::format("[Checkpoint] {}: attempt {}", checkpoint, attempt); + } + return std::format("[Checkpoint] {}: attempt {}/{}", checkpoint, attempt, *attempts); +} + +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place){ + return std::format( + "[Checkpoint] {}: passed on attempt {} ({}){}", + checkpoint, attempt, resets_text(attempt), + in_place == 0 ? "" : std::format(", {} in place", in_place) + ); +} + +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt){ + return std::format("[Checkpoint] {}: failed, resetting for attempt {}", checkpoint, next_attempt); +} + +std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts){ + return std::format( + "[Segment] {}: {} failed, reloading for attempt {}/{}", + segment, checkpoint, next_attempt, attempts + ); +} + + +void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts){ + stats.m_segment += counts.segments; + stats.m_checkpoint += counts.checkpoints; + stats.m_reset += counts.resets; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h new file mode 100644 index 0000000000..f9576e1e69 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h @@ -0,0 +1,76 @@ +/* Story Log + * + * From: https://github.com/PokemonAutomation/ + * + * The log lines an AutoStory program writes around its checkpoints, in + * one format for every game: the story engine (Pokemon_StoryEvents.h, + * Pokemon_StorySegments.h) writes them, and a game with its own checkpoint + * loop (SV's) writes the same lines, so the lab watcher and whoever reads + * a log find each checkpoint's start, attempts, resets and pass the same + * way. Also the program's stats counts. Nothing here runs a story. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryLog_H +#define PokemonAutomation_Pokemon_StoryLog_H + +#include +#include +#include +#include +#include "Pokemon_AutoStoryStats.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// One event's line: +// [Event] 00.04/3 talk_mom: start +// [Event] 00.04/3 talk_mom: failed: expect_failed: has_parcel +std::string event_log_line(std::string_view checkpoint, size_t number, std::string_view event, std::string_view status); + +// A checkpoint starts; the story engine also says it has `events` events: +// [Checkpoint] 00.04: start +// [Checkpoint] 00.04: start, 3 events +std::string checkpoint_start_line(std::string_view checkpoint, std::optional events = std::nullopt); + +// An attempt at a checkpoint starts, counting from 1, out of the +// program's limit of `attempts` if it has one: +// [Checkpoint] 00.04: attempt 2 +// [Checkpoint] 00.04: attempt 2/3 +std::string checkpoint_attempt_line( + std::string_view checkpoint, size_t attempt, std::optional attempts = std::nullopt +); + +// A checkpoint passed on attempt `attempt`, after `in_place` recoveries in +// place: +// [Checkpoint] 00.03: passed on attempt 1 (one-shot) +// [Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place +std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, size_t in_place = 0); + +// An attempt failed and the game resets to the checkpoint's save for +// attempt `next_attempt`: +// [Checkpoint] 00.04: failed, resetting for attempt 2 +std::string checkpoint_reset_line(std::string_view checkpoint, size_t next_attempt); +// The story engine reloads within segment `segment`, out of `attempts`: +// [Segment] 00: 00.02 failed, reloading for attempt 2/3 +std::string segment_reload_line(std::string_view segment, std::string_view checkpoint, size_t next_attempt, size_t attempts); + + +// What a story run adds to the program's stats. +struct StoryRunCounts{ + size_t segments = 0; + // Checkpoints passed (and saved at). + size_t checkpoints = 0; + // Game resets or reloads after failed attempts. + size_t resets = 0; +}; + +// Adds `counts` to the shared AutoStory stats. +void record_story_counts(AutoStoryStats& stats, const StoryRunCounts& counts); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp new file mode 100644 index 0000000000..86b1e59b86 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp @@ -0,0 +1,173 @@ +/* Story Log Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_StoryRun_Tests.h" +#include "Pokemon_StoryLog.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +// A formatter's line, made when the table is built. +struct StoryLogInput{ + std::string name; + std::string line; +}; + +// The exact line: the lab watcher and the engine tests read these. +struct StoryLogExpectation{ + std::string line; +}; + +// One formatter call and the line it must make. +struct StoryLogCase{ + StoryLogInput input; + StoryLogExpectation expectation; +}; + +class Test_StoryLog : public UnitTest{ +public: + Test_StoryLog(StoryLogCase test_case) + : UnitTest("Pokemon::StoryLog - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + if (m_case.input.line != m_case.expectation.line){ + return "Expected \"" + m_case.expectation.line + "\", got \"" + m_case.input.line + "\""; + } + return true; + } + +private: + const StoryLogCase m_case; +}; + +const StoryLogCase STORY_LOG_CASES[] = { + { + .input = {.name = "event", .line = event_log_line("00.04", 3, "talk_mom", "start")}, + .expectation = {.line = "[Event] 00.04/3 talk_mom: start"}, + }, + { + .input = {.name = "checkpoint start", .line = checkpoint_start_line("00.04")}, + .expectation = {.line = "[Checkpoint] 00.04: start"}, + }, + { + .input = {.name = "checkpoint start with its events", .line = checkpoint_start_line("00.04", 3)}, + .expectation = {.line = "[Checkpoint] 00.04: start, 3 events"}, + }, + { + .input = {.name = "attempt", .line = checkpoint_attempt_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: attempt 2"}, + }, + { + .input = {.name = "attempt out of a limit", .line = checkpoint_attempt_line("00.04", 2, 3)}, + .expectation = {.line = "[Checkpoint] 00.04: attempt 2/3"}, + }, + { + .input = {.name = "one-shot pass", .line = checkpoint_pass_line("00.03", 1)}, + .expectation = {.line = "[Checkpoint] 00.03: passed on attempt 1 (one-shot)"}, + }, + { + .input = {.name = "pass after one reset", .line = checkpoint_pass_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 2 (1 reset)"}, + }, + { + .input = {.name = "pass after resets and recoveries in place", .line = checkpoint_pass_line("00.04", 3, 1)}, + .expectation = {.line = "[Checkpoint] 00.04: passed on attempt 3 (2 resets), 1 in place"}, + }, + { + .input = {.name = "reset", .line = checkpoint_reset_line("00.04", 2)}, + .expectation = {.line = "[Checkpoint] 00.04: failed, resetting for attempt 2"}, + }, + { + .input = {.name = "reload within a segment", .line = segment_reload_line("00", "00.02", 2, 3)}, + .expectation = {.line = "[Segment] 00: 00.02 failed, reloading for attempt 2/3"}, + }, +}; + + +// Counts added to fresh stats, in order. +struct StoryCountsInput{ + std::string name; + std::vector added; +}; + +// The stats after them: counts add up rather than replace. +struct StoryCountsExpectation{ + uint64_t segments; + uint64_t checkpoints; + uint64_t resets; +}; + +// Counts recorded into the AutoStory stats and the totals they must reach. +struct StoryCountsCase{ + StoryCountsInput input; + StoryCountsExpectation expectation; +}; + +class Test_StoryCounts : public UnitTest{ +public: + Test_StoryCounts(StoryCountsCase test_case) + : UnitTest("Pokemon::StoryLog - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + AutoStoryStats stats; + for (const StoryRunCounts& counts : m_case.input.added){ + record_story_counts(stats, counts); + } + const StoryCountsExpectation& expected = m_case.expectation; + if (stats.m_segment != expected.segments || stats.m_checkpoint != expected.checkpoints || stats.m_reset != expected.resets){ + return "Expected " + std::to_string(expected.segments) + " segments, " + std::to_string(expected.checkpoints) + + " checkpoints and " + std::to_string(expected.resets) + " resets, got " + + std::to_string(stats.m_segment) + ", " + std::to_string(stats.m_checkpoint) + + " and " + std::to_string(stats.m_reset); + } + return true; + } + +private: + const StoryCountsCase m_case; +}; + +const StoryCountsCase STORY_COUNTS_CASES[] = { + { + .input = {.name = "a segment's counts in the stats", .added = {{.segments = 1, .checkpoints = 2, .resets = 3}}}, + .expectation = {.segments = 1, .checkpoints = 2, .resets = 3}, + }, + { + .input = { + .name = "a checkpoint loop's counts add up", + .added = {{.segments = 0, .checkpoints = 1, .resets = 0}, {.segments = 0, .checkpoints = 0, .resets = 1}, {.segments = 0, .checkpoints = 1, .resets = 0}}, + }, + .expectation = {.segments = 0, .checkpoints = 2, .resets = 1}, + }, +}; + +} // namespace + + +void add_tests_StoryLog(UnitTestDatabase& database){ + for (const StoryLogCase& test_case : STORY_LOG_CASES){ + database.add(test_case); + } + for (const StoryCountsCase& test_case : STORY_COUNTS_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h new file mode 100644 index 0000000000..faa1fcaa0a --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h @@ -0,0 +1,28 @@ +/* Story Run Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The unit tests of the pieces every AutoStory program shares, story + * engine or not: the checkpoint log lines and the range options. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryRun_Tests_H +#define PokemonAutomation_Pokemon_StoryRun_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared checkpoint log lines and stats counts. +void add_tests_StoryLog(UnitTestDatabase& database); +// 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/Pokemon/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp new file mode 100644 index 0000000000..de09808652 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp @@ -0,0 +1,60 @@ +/* Story Range Options + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryRangeOptions.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +StringSelectDatabase story_checkpoint_database(std::span labels){ + StringSelectDatabase database; + for (size_t c = 0; c < labels.size(); c++){ + database.add_entry(StringSelectEntry(std::to_string(c), labels[c])); + } + return database; +} + + +StoryRangeOptions::StoryRangeOptions(std::string label, const StringSelectDatabase& checkpoints, LockMode end_lock) + : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) + , START_CHECKPOINT( + "Start checkpoint:
The program starts from this checkpoint's save.", + checkpoints, + LockMode::LOCK_WHILE_RUNNING, + 0 + ) + , END_CHECKPOINT( + "End checkpoint:
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 diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h new file mode 100644 index 0000000000..e5d8cc0421 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h @@ -0,0 +1,64 @@ +/* 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 +#include +#include "Common/Cpp/Options/GroupOption.h" +#include "CommonTools/Options/StringSelectOption.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// 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. +StringSelectDatabase story_checkpoint_database(std::span labels); + + +// 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 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..940f606817 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -0,0 +1,135 @@ +/* Story Range Options Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_StoryRun_Tests.h" +#include "Pokemon_StoryRangeOptions.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; +} + +// 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{ +public: + Test_StoryRange(StoryRangeCase test_case) + : UnitTest("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 "Expected indexes " + std::to_string(expected.start) + " to " + std::to_string(expected.end) + + ", got " + std::to_string(range.start_index()) + " to " + std::to_string(range.end_index()); + } + const std::string error = range.check_validity(); + if (error.empty() != expected.valid){ + return expected.valid ? "Expected a valid range, got: " + error : "Expected the range refused."; + } + if (!expected.valid && error != "The start checkpoint comes after the end checkpoint."){ + return "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_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 660beed45a..41cdf5d762 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1467,10 +1467,17 @@ 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/AutoStory/Pokemon_AutoStorySelect.h Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h + Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp + Source/Pokemon/AutoStory/Pokemon_StoryLog.h + Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.h Source/Pokemon/Pokemon_AdvRng.cpp Source/Pokemon/Pokemon_AdvRng.h Source/Pokemon/Pokemon_BdspRng.cpp From 25331e37cf5ff2eb951f3ee32faa7f9babf9eef1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 13:29:40 -0800 Subject: [PATCH 2/7] AutoStory: move story_checkpoint_database() to AutoStorySelect It builds a dropdown database like make_story_select_database(), so it lives next to it in Pokemon_AutoStorySelect.h (header-only, inline) with a test beside that function's. StoryRangeOptions keeps only the option group. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_AutoStorySelect.h | 17 +++++++++++ .../Pokemon_AutoStorySelect_Tests.cpp | 30 +++++++++++++++++++ .../Options/Pokemon_StoryRangeOptions.cpp | 9 ------ .../Options/Pokemon_StoryRangeOptions.h | 11 ------- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h index 84276b0b86..1ac12c51f8 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h @@ -8,6 +8,7 @@ #define PokemonAutomation_Pokemon_AutoStorySelect_H #include +#include #include #include #include "CommonTools/Options/StringSelectOption.h" @@ -32,6 +33,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 labels){ + 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 diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp index efdd49bd8f..a80fb41824 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -103,6 +103,35 @@ class Test_AutoStorySelectDatabase : public UnitTest{ const AutoStorySelectScenario m_scenario; }; +// story_checkpoint_database() over a game's checkpoint labels: one entry +// per label, in order, slugged by its index. +class Test_StoryCheckpointDatabase : public UnitTest{ +public: + Test_StoryCheckpointDatabase() + : UnitTest("Pokemon::AutoStorySelectDatabase - checkpoint labels slugged by index") + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::vector labels = {"00.01 Pallet Town", "00.02 Oak's lab"}; + const StringSelectDatabase database = story_checkpoint_database(labels); + std::vector> got; + for (const StringSelectEntry& entry : database.case_list()){ + got.emplace_back(entry.slug, entry.display_name); + } + const std::vector> expected = { + {"0", "00.01 Pallet Town"}, {"1", "00.02 Oak's lab"}, + }; + if (got != expected){ + std::string text; + for (const auto& [slug, label] : got){ + text += (text.empty() ? "" : ", ") + slug + " \"" + label + "\""; + } + return "Expected slugs 0 and 1 over the labels in order, got [" + text + "]"; + } + return true; + } +}; + void add_index_tests(UnitTestDatabase& database){ const AutoStoryIndexScenario scenarios[] = { { @@ -158,6 +187,7 @@ void add_select_database_tests(UnitTestDatabase& database){ for (const AutoStorySelectScenario& scenario : select_scenarios){ database.add(scenario); } + database.add(); } } diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp index de09808652..d294e5e386 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.cpp @@ -11,15 +11,6 @@ namespace PokemonAutomation{ namespace Pokemon{ -StringSelectDatabase story_checkpoint_database(std::span labels){ - StringSelectDatabase database; - for (size_t c = 0; c < labels.size(); c++){ - database.add_entry(StringSelectEntry(std::to_string(c), labels[c])); - } - return database; -} - - StoryRangeOptions::StoryRangeOptions(std::string label, const StringSelectDatabase& checkpoints, LockMode end_lock) : GroupOption(std::move(label), LockMode::LOCK_WHILE_RUNNING) , START_CHECKPOINT( diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h index e5d8cc0421..809f3324d2 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions.h @@ -12,7 +12,6 @@ #ifndef PokemonAutomation_Pokemon_StoryRangeOptions_H #define PokemonAutomation_Pokemon_StoryRangeOptions_H -#include #include #include "Common/Cpp/Options/GroupOption.h" #include "CommonTools/Options/StringSelectOption.h" @@ -21,16 +20,6 @@ namespace PokemonAutomation{ namespace Pokemon{ -// 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. -StringSelectDatabase story_checkpoint_database(std::span labels); - - // 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. From 824117c3809e1852b136a3f186231335ee9fbd17 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 13:30:10 -0800 Subject: [PATCH 3/7] AutoStory: table-driven story_checkpoint_database() test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon_AutoStorySelect_Tests.cpp | 59 +++++++++++++------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp index a80fb41824..9f4bb07525 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -91,7 +91,6 @@ class Test_AutoStorySelectDatabase : public UnitTest{ return true; } -private: static std::string describe(const std::vector>& entries){ std::string text; for (const auto& [slug, label] : entries){ @@ -100,36 +99,60 @@ class Test_AutoStorySelectDatabase : public UnitTest{ return "[" + text + "]"; } +private: const AutoStorySelectScenario m_scenario; }; -// story_checkpoint_database() over a game's checkpoint labels: one entry -// per label, in order, slugged by its index. +// A game's checkpoint labels, in story order. +struct StoryCheckpointDatabaseInput{ + std::string name; + std::vector labels; +}; + +// The (slug, label) entries: one per label, in order, slugged by its index. +struct StoryCheckpointDatabaseExpectation{ + std::vector> 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{ public: - Test_StoryCheckpointDatabase() - : UnitTest("Pokemon::AutoStorySelectDatabase - checkpoint labels slugged by index") + Test_StoryCheckpointDatabase(StoryCheckpointDatabaseCase test_case) + : UnitTest("Pokemon::AutoStorySelectDatabase - " + test_case.input.name) + , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const std::vector labels = {"00.01 Pallet Town", "00.02 Oak's lab"}; - const StringSelectDatabase database = story_checkpoint_database(labels); + const StringSelectDatabase database = story_checkpoint_database(m_case.input.labels); std::vector> got; for (const StringSelectEntry& entry : database.case_list()){ got.emplace_back(entry.slug, entry.display_name); } - const std::vector> expected = { - {"0", "00.01 Pallet Town"}, {"1", "00.02 Oak's lab"}, - }; - if (got != expected){ - std::string text; - for (const auto& [slug, label] : got){ - text += (text.empty() ? "" : ", ") + slug + " \"" + label + "\""; - } - return "Expected slugs 0 and 1 over the labels in order, got [" + text + "]"; + if (got != m_case.expectation.entries){ + return "Expected " + Test_AutoStorySelectDatabase::describe(m_case.expectation.entries) + + ", got " + Test_AutoStorySelectDatabase::describe(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){ @@ -187,7 +210,9 @@ void add_select_database_tests(UnitTestDatabase& database){ for (const AutoStorySelectScenario& scenario : select_scenarios){ database.add(scenario); } - database.add(); + for (const StoryCheckpointDatabaseCase& test_case : STORY_CHECKPOINT_DATABASE_CASES){ + database.add(test_case); + } } } From 348ed174c8b672dcada55876e034136995fc99cb Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 13:30:31 -0800 Subject: [PATCH 4/7] AutoStory: describe checkpoint database entries without touching the select test Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_AutoStorySelect_Tests.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp index 9f4bb07525..b24f1c0179 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -91,6 +91,7 @@ class Test_AutoStorySelectDatabase : public UnitTest{ return true; } +private: static std::string describe(const std::vector>& entries){ std::string text; for (const auto& [slug, label] : entries){ @@ -99,10 +100,18 @@ class Test_AutoStorySelectDatabase : public UnitTest{ return "[" + text + "]"; } -private: const AutoStorySelectScenario m_scenario; }; +// (slug, label) entries as [0 "label", ...]. +std::string describe_entries(const std::vector>& entries){ + std::string text; + for (const auto& [slug, label] : entries){ + text += (text.empty() ? "" : ", ") + slug + " \"" + label + "\""; + } + return "[" + text + "]"; +} + // A game's checkpoint labels, in story order. struct StoryCheckpointDatabaseInput{ std::string name; @@ -134,8 +143,7 @@ class Test_StoryCheckpointDatabase : public UnitTest{ got.emplace_back(entry.slug, entry.display_name); } if (got != m_case.expectation.entries){ - return "Expected " + Test_AutoStorySelectDatabase::describe(m_case.expectation.entries) - + ", got " + Test_AutoStorySelectDatabase::describe(got); + return "Expected " + describe_entries(m_case.expectation.entries) + ", got " + describe_entries(got); } return true; } From c7eae8af41b76a1033a3c2115d031e35c2eda38b Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 14:30:55 -0800 Subject: [PATCH 5/7] Story range options: build test messages with std::format Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_AutoStorySelect_Tests.cpp | 9 +++++---- .../Options/Pokemon_StoryRangeOptions_Tests.cpp | 13 ++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp index b24f1c0179..7b6aea3085 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -107,9 +108,9 @@ class Test_AutoStorySelectDatabase : public UnitTest{ std::string describe_entries(const std::vector>& entries){ std::string text; for (const auto& [slug, label] : entries){ - text += (text.empty() ? "" : ", ") + slug + " \"" + label + "\""; + text += std::format("{}{} \"{}\"", text.empty() ? "" : ", ", slug, label); } - return "[" + text + "]"; + return std::format("[{}]", text); } // A game's checkpoint labels, in story order. @@ -132,7 +133,7 @@ struct StoryCheckpointDatabaseCase{ class Test_StoryCheckpointDatabase : public UnitTest{ public: Test_StoryCheckpointDatabase(StoryCheckpointDatabaseCase test_case) - : UnitTest("Pokemon::AutoStorySelectDatabase - " + test_case.input.name) + : UnitTest(std::format("Pokemon::AutoStorySelectDatabase - {}", test_case.input.name)) , m_case(std::move(test_case)) {} @@ -143,7 +144,7 @@ class Test_StoryCheckpointDatabase : public UnitTest{ got.emplace_back(entry.slug, entry.display_name); } if (got != m_case.expectation.entries){ - return "Expected " + describe_entries(m_case.expectation.entries) + ", got " + describe_entries(got); + return std::format("Expected {}, got {}", describe_entries(m_case.expectation.entries), describe_entries(got)); } return true; } diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp index 8e543f5f30..4cd40b9e7e 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -70,7 +71,7 @@ struct StoryRangeCase{ class Test_StoryRange : public UnitTest{ public: Test_StoryRange(StoryRangeCase test_case) - : UnitTest("Pokemon::StoryRangeOptions - " + test_case.input.name) + : UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.input.name)) , m_case(std::move(test_case)) {} @@ -84,15 +85,17 @@ class Test_StoryRange : public UnitTest{ } const StoryRangeExpectation& expected = m_case.expectation; if (range.start_index() != expected.start || range.end_index() != expected.end){ - return "Expected indexes " + std::to_string(expected.start) + " to " + std::to_string(expected.end) - + ", got " + std::to_string(range.start_index()) + " to " + std::to_string(range.end_index()); + 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 ? "Expected a valid range, got: " + error : "Expected the range refused."; + 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 "Unexpected message: " + error; + return std::format("Unexpected message: {}", error); } return true; } From 9ea62b9b93f0300ef5af8a24a63ff4af1f29b53f Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:37:07 -0800 Subject: [PATCH 6/7] PokemonSV AutoStory: shared checkpoint range options and log lines The tutorial and main story checkpoint dropdowns are now the shared StoryRangeOptions, added under the same keys (START_CHECKPOINT_TUTORIAL, END_CHECKPOINT_TUTORIAL, START_CHECKPOINT_MAINSTORY, END_CHECKPOINT_MAINSTORY) over the same databases, so saved settings load unchanged; the end stays unlocked while running. The start-before-end check is the range's. The checkpoint loops log the shared attempt and reset lines, and the run logs the shared checkpoint start line. Rebased onto autostory/story-range-options (#325) and squashed: it uses only the shared range options (#325) and log lines (#45), not #312. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonSV_AutoStory.cpp | 76 ++++++++----------- .../Programs/AutoStory/PokemonSV_AutoStory.h | 14 ++-- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 8 +- .../AutoStory/PokemonSV_AutoStoryTools.h | 4 +- 4 files changed, 47 insertions(+), 55 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 130271139b..945731d147 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -28,6 +28,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/Pokemon_Strings.h" #include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" @@ -347,6 +348,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 +400,9 @@ 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" - ) - , 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) - ) - , 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) - ) + // The end is read after each checkpoint, so it stays unlocked. + , TUTORIAL_CHECKPOINTS("Tutorial Checkpoints", TUTORIAL_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING) + , MAINSTORY_CHECKPOINTS("Main Story Checkpoints", MAINSTORY_CHECKPOINTS_SELECT_DATABASE(), LockMode::UNLOCK_WHILE_RUNNING) , 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 +694,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 +722,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 +753,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 +1047,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 ); } @@ -1216,8 +1202,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } if (ENABLE_ADVANCED_MODE){ - if (get_start_checkpoint_index() > get_end_checkpoint_index()){ - throw UserSetupError(env.logger(), "The start checkpoint cannot be later than the end segment."); + if (!checkpoint_range().check_validity().empty()){ + throw UserSetupError(env.logger(), checkpoint_range().check_validity()); } }else{ @@ -1230,7 +1216,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex require_player(env.console, context, BUTTON_L); if (ENABLE_ADVANCED_MODE){ - env.console.log("Start Checkpoint " + ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name(), COLOR_ORANGE); + env.console.log(Pokemon::checkpoint_start_line(ALL_AUTO_STORY_CHECKPOINT_LIST()[get_start_checkpoint_index()]->name()), COLOR_ORANGE); }else{ env.console.log("Start Segment " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->name(), COLOR_ORANGE); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h index d62d9b2ad2..b2ca877499 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 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 shared 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/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index c2d61152df..759350295e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -1445,7 +1445,7 @@ void checkpoint_reattempt_loop( save_game_from_overworld(env.program_info(), env.console, context); } - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); context.wait_for_all_requests(); action(i); @@ -1479,7 +1479,7 @@ void checkpoint_reattempt_loop( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); @@ -1507,7 +1507,7 @@ void checkpoint_reattempt_loop_tutorial( send_program_status_notification(env, notif_status_update, "Saved at checkpoint."); } - env.console.log(checkpoint_text + " Num attempts: " + std::to_string(i)); + env.console.log(Pokemon::checkpoint_attempt_line(checkpoint_text, i + 1)); context.wait_for_all_requests(); action(i); @@ -1538,7 +1538,7 @@ void checkpoint_reattempt_loop_tutorial( ); } context.wait_for_all_requests(); - env.console.log("Resetting from checkpoint."); + env.console.log(Pokemon::checkpoint_reset_line(checkpoint_text, i + 2)); reset_game(env.program_info(), env.console, context); stats.m_reset++; env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index e39d8a47da..312533cde7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_PokemonSV_AutoStoryTools_H #define PokemonAutomation_PokemonSV_AutoStoryTools_H +#include #include #include "CommonFramework/Language.h" #include "CommonFramework/ImageTools/ImageBoxes.h" @@ -15,6 +16,7 @@ #include "ML/Inference/ML_YOLONavigation.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" namespace PokemonAutomation{ @@ -108,7 +110,7 @@ class AutoStory_Checkpoint { AutoStoryStats& stats) const = 0; std::string checkpoint_text() const { - return "Checkpoint:: " + name() + ". Start point: " + start_text(); + return std::format("{}. Start point: {}", name(), start_text()); } }; From d24b86d1a04b0c1bfea2c9ea8f75c8e0116f7bb2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:34:14 -0800 Subject: [PATCH 7/7] SV AutoStory: drop the log header include, now in the .cpp files via #45 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h | 1 - 1 file changed, 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index 312533cde7..8583c68c42 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -16,7 +16,6 @@ #include "ML/Inference/ML_YOLONavigation.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" -#include "Pokemon/AutoStory/Pokemon_StoryLog.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" namespace PokemonAutomation{