Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* AutoStory Select
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_AutoStorySelect_H
#define PokemonAutomation_Pokemon_AutoStorySelect_H

#include <memory>
#include <string>
#include <vector>
#include "CommonTools/Options/StringSelectOption.h"

namespace PokemonAutomation{
namespace Pokemon{


// A dropdown database of the story segments or checkpoints [begin, end) of
// `list`, labeled by their name() and slugged by their index in the whole
// list, so a slug picks the same entry whichever section it was chosen from.
template <typename Entry>
StringSelectDatabase make_story_select_database(
const std::vector<std::unique_ptr<Entry>>& list,
size_t begin, size_t end
){
StringSelectDatabase ret;
for (size_t i = begin; i < end && i < list.size(); i++){
ret.add_entry(StringSelectEntry(std::to_string(i), list[i]->name()));
}
return ret;
}


}
}
#endif
40 changes: 40 additions & 0 deletions SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h"
#include "Inference/PokemonSV_WhiteButtonDetector.h"
#include "Inference/Boxes/PokemonSV_BoxDetection.h"
#include "Inference/Boxes/PokemonSV_BoxEggDetector.h"
Expand Down Expand Up @@ -148,7 +149,46 @@

}

namespace{

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

class Test_AutoStorySelectDatabase : public UnitTest{
public:
Test_AutoStorySelectDatabase()
: UnitTest("Pokemon::AutoStorySelectDatabase - a section keeps whole-list slugs")
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
std::vector<std::unique_ptr<NamedEntry>> list;
for (const char* label : {"a", "b", "c", "d"}){
list.emplace_back(std::make_unique<NamedEntry>(NamedEntry{label}));
}
const StringSelectDatabase database = Pokemon::make_story_select_database(list, 2, 10);
const std::vector<StringSelectEntry>& entries = database.case_list();
if (entries.size() != 2){
return "Expected 2 entries (the end is clamped to the list), got " + std::to_string(entries.size());
}
if (entries[0].slug != "2" || entries[0].display_name != "c" || entries[1].slug != "3" || entries[1].display_name != "d"){
return "Expected slugs 2, 3 labeled c, d; got " + entries[0].slug + " " + entries[0].display_name
+ ", " + entries[1].slug + " " + entries[1].display_name;
}
return true;
}
};

void add_tests_AutoStory(UnitTestDatabase& database){
database.add<Test_AutoStorySelectDatabase>();
}

}

void add_tests(UnitTestDatabase& database){

Check warning on line 190 in SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::add_tests( UnitTestDatabase & database): function_lines=34 (advisory above 25, limit 50)
add_tests_AutoStory(database);
database.add<Test_BBQuestsSlugs>();

// Full-frame references, in the CommandLineTests repo: they exercise the production
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.h"
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
#include "Pokemon/Pokemon_Strings.h"
#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h"
#include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
#include "VideoGames/PokemonSV/PokemonSV_Settings.h"
#include "VideoGames/PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
Expand Down Expand Up @@ -150,51 +151,24 @@ const std::vector<std::unique_ptr<AutoStory_Segment>>& ALL_AUTO_STORY_SEGMENT_LI
}


StringSelectDatabase make_all_segments_database(){
StringSelectDatabase ret;
int index_num = 0;
for (const auto& segment : ALL_AUTO_STORY_SEGMENT_LIST()){
ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name()));
index_num++;
}
return ret;
}
const StringSelectDatabase& ALL_SEGMENTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_all_segments_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_SEGMENT_LIST(), 0, ALL_AUTO_STORY_SEGMENT_LIST().size()
);
return database;
}

StringSelectDatabase make_tutorial_segments_database(){
StringSelectDatabase ret;
const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE();
size_t start = 0;
size_t end = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1;
for (size_t i = start; i < end; i++){
const auto& segment = all_segments[i];
ret.add_entry(segment);
}
return ret;
}

const StringSelectDatabase& TUTORIAL_SEGMENTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_tutorial_segments_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_SEGMENT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_SEGMENT + 1
);
return database;
}

StringSelectDatabase make_mainstory_segments_database(){
StringSelectDatabase ret;
const StringSelectDatabase& all_segments = ALL_SEGMENTS_SELECT_DATABASE();
size_t start = INDEX_OF_LAST_TUTORIAL_SEGMENT + 1;
size_t end = all_segments.case_list().size();
for (size_t i = start; i < end; i++){
const auto& segment = all_segments[i];
ret.add_entry(segment);
}
return ret;
}

const StringSelectDatabase& MAINSTORY_SEGMENTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_mainstory_segments_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_SEGMENT_LIST(), INDEX_OF_LAST_TUTORIAL_SEGMENT + 1, ALL_AUTO_STORY_SEGMENT_LIST().size()
);
return database;
}

Expand Down Expand Up @@ -324,51 +298,24 @@ const std::vector<std::unique_ptr<AutoStory_Checkpoint>>& ALL_AUTO_STORY_CHECKPO
return checkpoint_list;
}

StringSelectDatabase make_all_checkpoints_database(){
StringSelectDatabase ret;
int index_num = 0;
for (const auto& segment : ALL_AUTO_STORY_CHECKPOINT_LIST()){
ret.add_entry(StringSelectEntry(std::to_string(index_num), segment->name()));
index_num++;
}
return ret;
}
const StringSelectDatabase& ALL_CHECKPOINTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_all_checkpoints_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, ALL_AUTO_STORY_CHECKPOINT_LIST().size()
);
return database;
}

StringSelectDatabase make_tutorial_checkpoints_database(){
StringSelectDatabase ret;
const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE();
size_t start = 0;
size_t end = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1;
for (size_t i = start; i < end; i++){
const auto& segment = all_checkpoints[i];
ret.add_entry(segment);
}
return ret;
}

const StringSelectDatabase& TUTORIAL_CHECKPOINTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_tutorial_checkpoints_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_CHECKPOINT_LIST(), 0, INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1
);
return database;
}

StringSelectDatabase make_mainstory_checkpoints_database(){
StringSelectDatabase ret;
const StringSelectDatabase& all_checkpoints = ALL_CHECKPOINTS_SELECT_DATABASE();
size_t start = INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1;
size_t end = all_checkpoints.case_list().size();
for (size_t i = start; i < end; i++){
const auto& segment = all_checkpoints[i];
ret.add_entry(segment);
}
return ret;
}

const StringSelectDatabase& MAINSTORY_CHECKPOINTS_SELECT_DATABASE(){
static StringSelectDatabase database = make_mainstory_checkpoints_database();
static StringSelectDatabase database = make_story_select_database(
ALL_AUTO_STORY_CHECKPOINT_LIST(), INDEX_OF_LAST_TUTORIAL_CHECKPOINT + 1, ALL_AUTO_STORY_CHECKPOINT_LIST().size()
);
return database;
}

Expand Down
1 change: 1 addition & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ file(GLOB LIBRARY_SOURCES
Source/Pokemon/Options/Pokemon_NameSelectWidget.h
Source/Pokemon/Options/Pokemon_StatsHuntFilter.cpp
Source/Pokemon/Options/Pokemon_StatsHuntFilter.h
Source/Pokemon/AutoStory/Pokemon_AutoStorySelect.h
Source/Pokemon/Pokemon_AdvRng.cpp
Source/Pokemon/Pokemon_AdvRng.h
Source/Pokemon/Pokemon_BdspRng.cpp
Expand Down
Loading