Skip to content

AutoStory: shared start/end select database and story index - #1828

Merged
jw098 merged 6 commits into
PokemonAutomation:mainfrom
dayfine:autostory/story-select
Nov 10, 2026
Merged

jw098 merged 6 commits into
PokemonAutomation:mainfrom
dayfine:autostory/story-select

Conversation

@dayfine

@dayfine dayfine commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Moves SV AutoStory's repeated start/end dropdown and story-index code into two shared helpers that other games' AutoStory can reuse.

  • make_story_select_database() builds a start/end dropdown from a slice of the segment or checkpoint list, slugged by the index in the whole list. It replaces six hand-built databases.
  • story_index() does the tutorial/main-story offset once, instead of in six helpers and two descriptions.
  • Both are in Pokemon/AutoStory/Pokemon_AutoStorySelect.h, with their tests beside it. No behaviour change.

Testing

  • New unit tests Pokemon::AutoStoryIndex and Pokemon::AutoStorySelectDatabase; fork CI passed on Mac, Windows Clang and Ubuntu.
  • Not run on a Switch, since nothing changes in behaviour.

🤖 Generated with Claude Code

SV AutoStory built six near-identical start/end dropdown databases by hand
and repeated the tutorial/main-story index offset maths in six helpers and
two descriptions. make_story_select_database() and story_index() in
Pokemon/AutoStory/Pokemon_AutoStorySelect.h do each once, for other games'
AutoStory to reuse, with their tests beside them. No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@Mysticial

Mysticial commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

@jw098 will need to look at this one since I assume the expectation is that SV AutoStory would get its options refactored to use this.

@pa-devbot pa-devbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI review: Clean, behavior-preserving refactor. Verified on this branch: it builds and the full command-line suite is green (20,333 passed / 0 failed / 3 skipped), including the 6 new tests (Pokemon::AutoStoryIndex, Pokemon::AutoStorySelectDatabase).

What's good

  • make_story_select_database() slugs by whole-list index and reads name() off the entry, matching the old std::to_string(index_num) builders. The i < list.size() clamp is a small robustness win over the old all_segments[i] indexing. Templating on Entry (any type with name()) is what lets one helper serve both segments and checkpoints.
  • story_index() collapses the first_main_story_index + idx offset into one place; all four get_*_index() now route through it, and the two checkpoint descriptions now call their getters. Equivalent to the original if/else for both TUTORIAL and MAIN_STORY (only two enum values, default TUTORIAL).
  • Tests hit the interesting cases: whole-list slugging, tutorial pass-through, main-story offset, and the end-past-list clamp.

One gap in the SV refactor — the tutorial/main-story offset is still inlined in the two segment description functions, which were left behind while the sibling checkpoint descriptions were moved to call their getters:

  • SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp:1030 start_segment_description()
  • .../PokemonSV_AutoStory.cpp:1040 end_segment_description()

For symmetry with start_checkpoint_description()/end_checkpoint_description() (which now call get_start_checkpoint_index()/get_end_checkpoint_index()), these could just be:

std::string AutoStory::start_segment_description(){
    return "    " + ALL_AUTO_STORY_SEGMENT_LIST()[get_start_segment_index()]->start_text();
}
std::string AutoStory::end_segment_description(){
    return "    " + ALL_AUTO_STORY_SEGMENT_LIST()[get_end_segment_index()]->end_text();
}

That removes the last two inline copies of the offset and makes story_index() the single source of truth. Behavior is unchanged.

(Aside: no other game has an AutoStory program yet, so SV is the only consumer today — good that the helpers already live in Pokemon/AutoStory/ in the Pokemon namespace, ready to be reused the moment another game ships one.)

start_segment_description() and end_segment_description() computed the
tutorial/main-story segment offset inline. They now call
get_start_segment_index() / get_end_segment_index(), like the checkpoint
descriptions, which removes the last two inline copies of that offset
(pa-devbot review on PokemonAutomation#1828). No behavior
change: both getters return the same index for tutorial and main story.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@jw098

jw098 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Overall, looks fine to me. My only comment is that we currently assume only 2 main sections: Tutorial + Main. But if this changes in the future, we'll need to refactor it to handle N sections.

story_index() maps a tutorial or main-story position to the flat story
list. Note that this assumes two consecutive sections, which is all SV
AutoStory covers, and that a branching postgame or DLC needs another model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine

dayfine commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Overall, looks fine to me. My only comment is that we currently assume only 2 main sections: Tutorial + Main. But if this changes in the future, we'll need to refactor it to handle N sections.

added a NOTE -- might tackle that as I do PostGame (Seveii islands) for FRLG

@jw098

jw098 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

You only need separate story sections if the automation needs to take a break. e.g. between the SV tutorial and main story, the user had to manually level up the leak Pokemon. If there are no breaks required, you don't need a separate story section.

@dayfine

dayfine commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Makes sense — sections are break points. Updated the NOTE: postgame/DLC append to the last section unless they need their own break.

dayfine added a commit to dayfine/Arduino-Source that referenced this pull request Nov 2, 2026
Takes the reviewed version of the shared select code from
PokemonAutomation#1828: Pokemon_AutoStorySelect.h and its
tests in Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.*. The older
AutoStory index tests in PokemonSV_Tests.cpp are dropped; PokemonAutomation#1828's suite
covers them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine added a commit to dayfine/Arduino-Source that referenced this pull request Nov 2, 2026
…pstream queue, tips

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine
dayfine requested a review from pa-devbot November 6, 2026 18:39

@pa-devbot pa-devbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI review: Reviewed #1828 (AutoStory: shared start/end select DB + story index). It's a clean, low-risk refactor — I agree it's behavior-preserving.

What I verified

  • make_story_select_database (SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h:23) is equivalent to the six old make_* builders: same entry order, same whole-list-integer slugs, same display names. The loop guard i < end && i < list.size() (:28) is safe for begin>size / end>size (no UB). StringSelectEntry(slug, name) arg order is correct (StringSelectOption.h:27), and StringSelectCell::index() returns position-in-dropdown, not slug — consistent with the main-story offset.
  • story_index (:42) matches the eight inline offset computations; STORY_SECTION is a 2-value enum (PokemonSV_AutoStory.h:75), so the main_story ? MAIN : TUTORIAL ternary always picks the right option. Unifying the four *_description() funcs into the shared getters is neutral — I confirmed the old description code was identical to the old getters against origin/main.
  • Entry::name() (virtual, PokemonSV_AutoStoryTools.h:97) is the implicit template contract; both AutoStory_Segment and AutoStory_Checkpoint satisfy it.

Tests / build

  • All 6 new tests pass (3 AutoStoryIndex, 3 AutoStorySelectDatabase); registered in ComputerPrograms_UnitTestRunner.cpp:66 and SourceFiles.cmake:1468.
  • Full CLI suite: 20,328 passed, 5 failed, 3 skipped. The 5 failures are all OCR::MultilineOCR image tests (FRLG/SV dialog PNGs + 2 generic sentences) — unrelated to this PR, which touches no OCR code or resources; the 3 skips are pre-existing audio tests.

Nits (non-blocking)

  • Param end shadows std::end (harmless here since it uses list.size()).
  • Worth a one-line comment that begin/end are expected within [0, list.size()] — the clamp only guards end, and begin>end is a silent no-op.

LGTM to me.

@jw098
jw098 merged commit 20ee9ae into PokemonAutomation:main Nov 10, 2026
8 checks passed
@dayfine
dayfine deleted the autostory/story-select branch November 10, 2026 01:55
dayfine added a commit to dayfine/Arduino-Source that referenced this pull request Nov 12, 2026
origin/main has upstream PokemonAutomation#1828, the final version of autostory/r2-story-index
(fork #44, closed); Pokemon_AutoStorySelect.h takes main's version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants