diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index c68c1b0f4..fbae96cc1 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -1348,8 +1348,12 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.h Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.cpp Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.h + Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp + Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h Source/PokemonSV/Inference/PokemonSV_MoneyReader.cpp Source/PokemonSV/Inference/PokemonSV_MoneyReader.h + # Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp + # Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.cpp Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.h Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp @@ -1360,6 +1364,8 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/Inference/PokemonSV_SweatBubbleDetector.h Source/PokemonSV/Inference/PokemonSV_TournamentPrizeNameReader.cpp Source/PokemonSV/Inference/PokemonSV_TournamentPrizeNameReader.h + # Source/PokemonSV/Inference/PokemonSV_TutorialDetector.cpp + # Source/PokemonSV/Inference/PokemonSV_TutorialDetector.h Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.cpp Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.cpp @@ -1418,6 +1424,12 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/PokemonSV_Panels.h Source/PokemonSV/PokemonSV_Settings.cpp Source/PokemonSV/PokemonSV_Settings.h + # Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp + # Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.cpp Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h Source/PokemonSV/Programs/Battles/PokemonSV_Battles.cpp diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index 8e90e8d4f..e6cb50358 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -674,12 +674,15 @@ SOURCES += \ Source/PokemonSV/Inference/PokemonSV_ClothingTopDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.cpp \ + Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp \ Source/PokemonSV/Inference/PokemonSV_MoneyReader.cpp \ + #Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.cpp \ Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp \ Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp \ Source/PokemonSV/Inference/PokemonSV_SweatBubbleDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_TournamentPrizeNameReader.cpp \ + #Source/PokemonSV/Inference/PokemonSV_TutorialDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.cpp \ Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.cpp \ Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.cpp \ @@ -708,6 +711,9 @@ SOURCES += \ Source/PokemonSV/Options/PokemonSV_TournamentPrizeTable.cpp \ Source/PokemonSV/PokemonSV_Panels.cpp \ Source/PokemonSV/PokemonSV_Settings.cpp \ + #Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_Battles.cpp \ Source/PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.cpp \ @@ -1750,12 +1756,15 @@ HEADERS += \ Source/PokemonSV/Inference/PokemonSV_ClothingTopDetector.h \ Source/PokemonSV/Inference/PokemonSV_ESPEmotionDetector.h \ Source/PokemonSV/Inference/PokemonSV_MainMenuDetector.h \ + Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h \ Source/PokemonSV/Inference/PokemonSV_MoneyReader.h \ + #Source/PokemonSV/Inference/PokemonSV_PokemonMovesReader.h \ Source/PokemonSV/Inference/PokemonSV_PokePortalDetector.h \ Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h \ Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.h \ Source/PokemonSV/Inference/PokemonSV_SweatBubbleDetector.h \ Source/PokemonSV/Inference/PokemonSV_TournamentPrizeNameReader.h \ + #Source/PokemonSV/Inference/PokemonSV_TutorialDetector.h \ Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h \ Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h \ Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.h \ @@ -1786,6 +1795,9 @@ HEADERS += \ Source/PokemonSV/Options/PokemonSV_TournamentPrizeTable.h \ Source/PokemonSV/PokemonSV_Panels.h \ Source/PokemonSV/PokemonSV_Settings.h \ + #Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h \ Source/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h \ Source/PokemonSV/Programs/Battles/PokemonSV_Battles.h \ Source/PokemonSV/Programs/Battles/PokemonSV_SinglesBattler.h \ diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp new file mode 100644 index 000000000..45b38e2e8 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.cpp @@ -0,0 +1,53 @@ +/* Menu Option Reader + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include +#include "Common/Cpp/Containers/FixedLimitVector.tpp" +#include "Common/Cpp/Concurrency/AsyncDispatcher.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonFramework/Tools/ConsoleHandle.h" +#include "PokemonSV_MenuOptionReader.h" + +#include "Common/Cpp/PrettyPrint.h" +#include +using std::cout; +using std::endl; + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + + +MenuOptionReader& MenuOptionReader::instance(){ + static MenuOptionReader reader; + return reader; +} + +MenuOptionReader::MenuOptionReader() + : SmallDictionaryMatcher("PokemonSV/MenuOptionsOCR.json") +{} + +OCR::StringMatchResult MenuOptionReader::read_substring( + Logger& logger, + Language language, + const ImageViewRGB32& image, + const std::vector& text_color_ranges, + double min_text_ratio, double max_text_ratio +) const{ + return match_substring_from_image_multifiltered( + &logger, language, image, text_color_ranges, + MAX_LOG10P, MAX_LOG10P_SPREAD, min_text_ratio, max_text_ratio + ); +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h new file mode 100644 index 000000000..69edb8abf --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_MenuOptionReader.h @@ -0,0 +1,49 @@ +/* Menu Option Reader + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_MenuOptionReader_H +#define PokemonAutomation_PokemonSV_MenuOptionReader_H + +#include +#include +#include "Common/Cpp/Containers/FixedLimitVector.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonFramework/OCR/OCR_SmallDictionaryMatcher.h" +#include "PokemonSV/Inference/Dialogs/PokemonSV_GradientArrowDetector.h" +#include "PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h" + +namespace PokemonAutomation{ + class AsyncDispatcher; + class ConsoleHandle; + class BotBaseContext; +namespace NintendoSwitch{ +namespace PokemonSV{ + +class MenuOptionReader : public OCR::SmallDictionaryMatcher{ + static constexpr double MAX_LOG10P = -1.30; + static constexpr double MAX_LOG10P_SPREAD = 0.50; + +public: + MenuOptionReader(); + + static MenuOptionReader& instance(); + + OCR::StringMatchResult read_substring( + Logger& logger, + Language language, + const ImageViewRGB32& image, + const std::vector& text_color_ranges, + double min_text_ratio = 0.01, double max_text_ratio = 0.50 + ) const; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp new file mode 100644 index 000000000..fff90ad85 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp @@ -0,0 +1,214 @@ +/* Menu Option Session + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include +#include "Common/Cpp/Containers/FixedLimitVector.tpp" +#include "Common/Cpp/Concurrency/AsyncDispatcher.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonFramework/Tools/ConsoleHandle.h" +#include "CommonFramework/OCR/OCR_NumberReader.h" +#include "PokemonSV_MenuOption.h" +#include "PokemonSV/Inference/PokemonSV_MenuOptionReader.h" + +#include "Common/Cpp/PrettyPrint.h" +#include +// using std::cout; +// using std::endl; + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +MenuOption::~MenuOption() = default; + +MenuOption::MenuOption( + ConsoleHandle& console, + BotBaseContext& context, + Language language +) + : m_console(console) + , m_context(context) + , m_language(language) + , m_overlays(console.overlay()) + , m_arrow(COLOR_CYAN, GradientArrowType::RIGHT, {0.02, 0.10, 0.05, 0.80}) +{ + // reader.make_overlays(m_overlays); + for (size_t c = 0; c < 10; c++){ + m_boxes_item[c] = ImageFloatBox(0.055, 0.135 + c * 0.0739, 0.260, 0.060); + m_boxes_toggle[c] = ImageFloatBox(0.345, 0.135 + c * 0.0739, 0.175, 0.060); + m_overlays.add(COLOR_BLUE, m_boxes_item[c]); + m_overlays.add(COLOR_BLUE, m_boxes_toggle[c]); + } +} + +void MenuOption::set_options( + std::vector>> options +) const{ + for (std::pair> option : options){ + move_to_option(option.first); + set_target_option(option.second); + } +} + +void MenuOption::set_target_option(const std::vector target_option_toggle_list) const{ + + for (size_t attempt = 0; attempt < 10; attempt++){ + std::string current_option_slug = read_option_toggle(); + MenuOptionToggleEnum current_option_toggle_enum = menu_option_toggle_lookup_by_slug(current_option_slug).enum_value; + + if (std::find(target_option_toggle_list.begin(), target_option_toggle_list.end(), current_option_toggle_enum) != target_option_toggle_list.end()){ + return; + } + + pbf_press_dpad(m_context, DPAD_RIGHT, 10, 50); + } + + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, m_console, + "MenuOption::set_target_option(): Unable to set option to the correct toggle." + ); + +} + +int8_t MenuOption::get_selected_index(const ImageViewRGB32& screen) const { + m_context.wait_for_all_requests(); + ImageFloatBox box; + if (!m_arrow.detect(box, screen)){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, m_console, + "MenuOption::get_selected_index(): Unable to find cursor." + ); + } + +// cout << box.y << endl; + double slot = (box.y - 0.135185) / 0.0739; + int8_t selected_index = (int8_t)(slot + 0.5); + + if (selected_index < 0 || selected_index >= 10){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, m_console, + "MenuOption::get_selected_index(): Invalid cursor slot." + ); + } + // cout << "selected index:" + std::to_string(selected_index) << endl; + + return selected_index; +} + +std::string MenuOption::read_option(const ImageViewRGB32& cropped) const{ + // cropped.save("test.png"); + const auto ocr_result = MenuOptionReader::instance().read_substring( + m_console, m_language, + cropped, OCR::BLACK_TEXT_FILTERS() + ); + + std::multimap results; + if (!ocr_result.results.empty()){ + for (const auto& result : ocr_result.results){ + results.emplace(result.first, result.second); + } + } + + if (results.empty()){ + if (m_language == Language::German){ + // German Menu Option uses numbers for text speed settings, which string OCR has trouble with detecting. + int16_t number = read_number(m_console, cropped); + switch (number){ + case 1: + return "slow"; + case 2: + return "normal"; + case 3: + return "fast"; + } + } + return ""; + } + + if (results.size() > 1){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, + m_console, + "MenuOption::read_option(): Unable to read item. Ambiguous or multiple results." + ); + } + + return results.begin()->second.token; +} + +int16_t MenuOption::read_number( + Logger& logger, + const ImageViewRGB32& cropped +) const{ + + int16_t number = (int16_t)OCR::read_number_waterfill(logger, cropped, 0xff000000, 0xff808080); + + if (number < 1 || number > 3){ + number = -1; + } + return (int16_t)number; +} + +std::string MenuOption::read_option_item() const{ + m_context.wait_for_all_requests(); + VideoSnapshot screen = m_console.video().snapshot(); + + ImageFloatBox selected_box = m_boxes_item[get_selected_index(screen)]; + ImageViewRGB32 cropped = extract_box_reference(screen, selected_box); + return read_option(cropped); + +} + +std::string MenuOption::read_option_toggle() const{ + m_context.wait_for_all_requests(); + VideoSnapshot screen = m_console.video().snapshot(); + + ImageFloatBox selected_box = m_boxes_toggle[get_selected_index(screen)]; + ImageViewRGB32 cropped = extract_box_reference(screen, selected_box); + + return read_option(cropped); +} + + +void MenuOption::move_to_option(const MenuOptionItemEnum target_option_enum) const{ + std::string current_option_slug = read_option_item(); + MenuOptionItem current_option = menu_option_item_lookup_by_slug(current_option_slug); + + MenuOptionItem target_option = menu_option_item_lookup_by_enum(target_option_enum); + std::string target_option_slug = target_option.slug; + int diff = target_option.index - current_option.index; + // cout << "target_option diff: " << std::to_string(target_option.index) << endl; + // cout << "current_option diff: " << std::to_string(current_option.index) << endl; + // cout << "diff: " << std::to_string(diff) << endl; + while (diff != 0){ + // move cursor in direction of target_option + if (diff > 0){ + for (size_t i = 0; i < (size_t)diff; i++){ + pbf_press_dpad(m_context, DPAD_DOWN, 10, 50); + } + } + if (diff < 0){ + for (size_t i = 0; i < (size_t)-diff; i++){ + pbf_press_dpad(m_context, DPAD_UP, 10, 50); + } + } + current_option_slug = read_option_item(); + current_option = menu_option_item_lookup_by_slug(current_option_slug); + diff = target_option.index - current_option.index; + // cout << "diff: " << std::to_string(diff) << endl; + } +} + + + + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h new file mode 100644 index 000000000..a47617cde --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h @@ -0,0 +1,83 @@ +/* Menu Option Session + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_MenuOption_H +#define PokemonAutomation_PokemonSV_MenuOption_H + +#include +#include +#include "Common/Cpp/Containers/FixedLimitVector.h" +#include "CommonFramework/Language.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonFramework/OCR/OCR_SmallDictionaryMatcher.h" +#include "PokemonSV/Inference/Dialogs/PokemonSV_GradientArrowDetector.h" +#include "PokemonSV_MenuOptionDatabase.h" + +namespace PokemonAutomation{ + class AsyncDispatcher; + class ConsoleHandle; + class BotBaseContext; +namespace NintendoSwitch{ +namespace PokemonSV{ + + + +class MenuOption{ +public: + ~MenuOption(); + MenuOption( + ConsoleHandle& console, BotBaseContext& context, + Language language + ); + + // change all settings as per options + void set_options( + std::vector>> options) const; + +private: + + // set the current selected option, to the given option_toggle + // (which is a list of option_toggles, since the mapping for the options in each language is slightly different) + void set_target_option( + const std::vector target_option_toggle_list + ) const; + + // Move to the target_option. + // Returns empty string if not found. + void move_to_option(const MenuOptionItemEnum target_option) const; + + std::string read_option(const ImageViewRGB32& cropped) const; + + int16_t read_number(Logger& logger, const ImageViewRGB32& cropped) const; + + // return the slug for the selected menu option item + std::string read_option_item() const; + + // return the slug for the selected menu option toggle + std::string read_option_toggle() const; + + // return the index row of the currently selected item. + // this detects the gradient arrow. + int8_t get_selected_index(const ImageViewRGB32& screen) const; + + +private: + ConsoleHandle& m_console; + BotBaseContext& m_context; + Language m_language; + VideoOverlaySet m_overlays; + GradientArrowDetector m_arrow; + std::array m_boxes_item; + std::array m_boxes_toggle; +}; + + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp new file mode 100644 index 000000000..dfc8f9769 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.cpp @@ -0,0 +1,148 @@ +/* Menu Option Database + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "PokemonSV_MenuOptionDatabase.h" +#include +using std::cout; +using std::endl; + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +static const std::vector& MenuOption_AllItems(){ + static const std::vector database{ + {MenuOptionItemEnum::TEXT_SPEED, "text-speed", 0}, + {MenuOptionItemEnum::SKIP_MOVE_LEARNING, "skip-move-learning", 1}, + {MenuOptionItemEnum::SEND_TO_BOXES, "send-to-boxes", 2}, + {MenuOptionItemEnum::GIVE_NICKNAMES, "give-nicknames", 3}, + {MenuOptionItemEnum::VERTICAL_CAMERA_CONTROLS, "vertical-camera-controls", 4}, + {MenuOptionItemEnum::HORIZONTAL_CAMERA_CONTROLS, "horizontal-camera-controls", 5}, + {MenuOptionItemEnum::CAMERA_SUPPORT, "camera-support", 6}, + {MenuOptionItemEnum::CAMERA_INTERPOLATION, "camera-interpolation", 7}, + {MenuOptionItemEnum::CAMERA_DISTANCE, "camera-distance", 8}, + {MenuOptionItemEnum::AUTOSAVE, "autosave", 9}, + {MenuOptionItemEnum::SHOW_NICKNAMES, "show-nicknames", 10}, + {MenuOptionItemEnum::SKIP_CUTSCENES, "skip-cutscenes", 11}, + {MenuOptionItemEnum::BACKGROUN_MUSIC, "background-music", 12}, + {MenuOptionItemEnum::SOUND_EFFECTS, "sound-effects", 13}, + {MenuOptionItemEnum::POKEMON_CRIES, "pokemon-cries", 14}, + {MenuOptionItemEnum::CONTROLLER_RUMBLE, "controller-rumble", 15}, + {MenuOptionItemEnum::HELPING_FUNCTIONS, "helping-functions", 16}, + {MenuOptionItemEnum::CONTROLS_WHILE_FLYING, "controls-while-flying", 17}, + }; + + return database; + +} + +static const std::vector& MenuOption_AllToggles(){ + static const std::vector database{ + {MenuOptionToggleEnum::SLOW, "slow"}, + {MenuOptionToggleEnum::AVERAGE, "average"}, + {MenuOptionToggleEnum::NORMAL, "normal"}, + {MenuOptionToggleEnum::FAST, "fast"}, + {MenuOptionToggleEnum::ON, "on"}, + {MenuOptionToggleEnum::OFF, "off"}, + {MenuOptionToggleEnum::MANUAL, "manual"}, + {MenuOptionToggleEnum::AUTOMATIC, "automatic"}, + {MenuOptionToggleEnum::REGULAR, "regular"}, + {MenuOptionToggleEnum::INVERTED, "inverted"}, + {MenuOptionToggleEnum::CLOSE, "close"}, + {MenuOptionToggleEnum::FAR, "far"}, + {MenuOptionToggleEnum::DONT_SHOW, "dont-show"}, + {MenuOptionToggleEnum::SHOW, "show"}, + }; + + return database; + +} + +static std::map make_MenuOptionItem_lookup_by_enum(){ + std::map ret; + for (const MenuOptionItem& item : MenuOption_AllItems()){ + if (!ret.emplace(item.enum_value, &item).second){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Enum: " + std::to_string((int)item.enum_value)); + } + } + return ret; +} +const MenuOptionItem& menu_option_item_lookup_by_enum(MenuOptionItemEnum enum_value){ + static const std::map database = make_MenuOptionItem_lookup_by_enum(); + auto iter = database.find(enum_value); + if (iter != database.end()){ + return *iter->second; + }else{ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown Enum: " + std::to_string((int)enum_value)); + } +} +static std::map make_MenuOptionItem_lookup_by_slug(){ + std::map ret; + for (const MenuOptionItem& item : MenuOption_AllItems()){ + if (!ret.emplace(item.slug, &item).second){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Enum: " + item.slug); + } + } + return ret; +} +const MenuOptionItem& menu_option_item_lookup_by_slug(std::string& slug){ + static const std::map database = make_MenuOptionItem_lookup_by_slug(); + auto iter = database.find(slug); + if (iter != database.end()){ + return *iter->second; + }else{ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown Enum: " + slug); + } +} + +static std::map make_MenuOptionToggle_lookup_by_enum(){ + std::map ret; + for (const MenuOptionToggle& item : MenuOption_AllToggles()){ + if (!ret.emplace(item.enum_value, &item).second){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Enum: " + std::to_string((int)item.enum_value)); + } + } + return ret; +} +const MenuOptionToggle& menu_option_toggle_lookup_by_enum(MenuOptionToggleEnum enum_value){ + static const std::map database = make_MenuOptionToggle_lookup_by_enum(); + auto iter = database.find(enum_value); + if (iter != database.end()){ + return *iter->second; + }else{ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown Enum: " + std::to_string((int)enum_value)); + } +} + +static std::map make_MenuOptionToggle_lookup_by_slug(){ + std::map ret; + for (const MenuOptionToggle& item : MenuOption_AllToggles()){ + if (!ret.emplace(item.slug, &item).second){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Enum: " + item.slug); + } + } + return ret; +} +const MenuOptionToggle& menu_option_toggle_lookup_by_slug(std::string& slug){ + static const std::map database = make_MenuOptionToggle_lookup_by_slug(); + auto iter = database.find(slug); + if (iter != database.end()){ + return *iter->second; + }else{ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown Enum: " + slug); + } +} + + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h new file mode 100644 index 000000000..08551960f --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOptionDatabase.h @@ -0,0 +1,82 @@ +/* Menu Option Database + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_MenuOptionDatabase_H +#define PokemonAutomation_PokemonSV_MenuOptionDatabase_H + +#include + +namespace PokemonAutomation{ + class AsyncDispatcher; + class ConsoleHandle; + class BotBaseContext; +namespace NintendoSwitch{ +namespace PokemonSV{ + + +enum class MenuOptionItemEnum{ + TEXT_SPEED, + SKIP_MOVE_LEARNING, + SEND_TO_BOXES, + GIVE_NICKNAMES, + VERTICAL_CAMERA_CONTROLS, + HORIZONTAL_CAMERA_CONTROLS, + CAMERA_SUPPORT, + CAMERA_INTERPOLATION, + CAMERA_DISTANCE, + AUTOSAVE, + SHOW_NICKNAMES, + SKIP_CUTSCENES, + BACKGROUN_MUSIC, + SOUND_EFFECTS, + POKEMON_CRIES, + CONTROLLER_RUMBLE, + HELPING_FUNCTIONS, + CONTROLS_WHILE_FLYING, +}; + +enum class MenuOptionToggleEnum{ + SLOW, + AVERAGE, + NORMAL, + FAST, + ON, + OFF, + MANUAL, + AUTOMATIC, + REGULAR, + INVERTED, + CLOSE, + FAR, + DONT_SHOW, + SHOW, + +}; + +struct MenuOptionItem{ + MenuOptionItemEnum enum_value; + std::string slug; + int8_t index; +}; + +struct MenuOptionToggle{ + MenuOptionToggleEnum enum_value; + std::string slug; + +}; + +const MenuOptionItem& menu_option_item_lookup_by_enum(MenuOptionItemEnum enum_value); + +const MenuOptionItem& menu_option_item_lookup_by_slug(std::string& slug); + +const MenuOptionToggle& menu_option_toggle_lookup_by_enum(MenuOptionToggleEnum enum_value); + +const MenuOptionToggle& menu_option_toggle_lookup_by_slug(std::string& slug); + +} +} +} +#endif