From 4da5a2d6211ab76f36f1f1b97214466afdf6d90c Mon Sep 17 00:00:00 2001 From: jw098 Date: Sun, 3 Nov 2024 11:42:48 -0800 Subject: [PATCH] olive action failed exception (#499) --- SerialPrograms/CMakeLists.txt | 2 + SerialPrograms/SerialPrograms.pro | 2 + .../Exceptions/OliveActionFailedException.cpp | 34 ++++++++++++++ .../Exceptions/OliveActionFailedException.h | 46 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.cpp create mode 100644 SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index da51665b9..16e52b4ed 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -307,6 +307,8 @@ file(GLOB MAIN_SOURCES Source/CommonFramework/Environment/SystemSleep.h Source/CommonFramework/Exceptions/FatalProgramException.cpp Source/CommonFramework/Exceptions/FatalProgramException.h + Source/CommonFramework/Exceptions/OliveActionFailedException.cpp + Source/CommonFramework/Exceptions/OliveActionFailedException.h Source/CommonFramework/Exceptions/OperationFailedException.cpp Source/CommonFramework/Exceptions/OperationFailedException.h Source/CommonFramework/Exceptions/ProgramFinishedException.cpp diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index 8f4cdea9a..84b360052 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -179,6 +179,7 @@ SOURCES += \ Source/CommonFramework/Environment/HardwareValidation.cpp \ Source/CommonFramework/Environment/SystemSleep.cpp \ Source/CommonFramework/Exceptions/FatalProgramException.cpp \ + Source/CommonFramework/Exceptions/OliveActionFailedException.cpp \ Source/CommonFramework/Exceptions/OperationFailedException.cpp \ Source/CommonFramework/Exceptions/ProgramFinishedException.cpp \ Source/CommonFramework/Exceptions/ScreenshotException.cpp \ @@ -1235,6 +1236,7 @@ HEADERS += \ Source/CommonFramework/Environment/HardwareValidation_x86.tpp \ Source/CommonFramework/Environment/SystemSleep.h \ Source/CommonFramework/Exceptions/FatalProgramException.h \ + Source/CommonFramework/Exceptions/OliveActionFailedException.h \ Source/CommonFramework/Exceptions/OperationFailedException.h \ Source/CommonFramework/Exceptions/ProgramFinishedException.h \ Source/CommonFramework/Exceptions/ScreenshotException.h \ diff --git a/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.cpp b/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.cpp new file mode 100644 index 000000000..5e9ddc278 --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.cpp @@ -0,0 +1,34 @@ +/* Operation Failed Exception + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/Tools/ErrorDumper.h" +#include "CommonFramework/Tools/ProgramEnvironment.h" +#include "CommonFramework/Tools/ConsoleHandle.h" +#include "OliveActionFailedException.h" + +namespace PokemonAutomation{ + + +OliveActionFailedException::OliveActionFailedException(ErrorReport error_report, Logger& logger, std::string message, OliveFail fail_reason) + : OperationFailedException(error_report, logger, std::move(message)) + , m_fail_reason(fail_reason) +{} +OliveActionFailedException::OliveActionFailedException(ErrorReport error_report, Logger& logger, std::string message, std::shared_ptr screenshot, OliveFail fail_reason) + : OperationFailedException(error_report, logger, std::move(message), std::move(screenshot)) + , m_fail_reason(fail_reason) +{} +OliveActionFailedException::OliveActionFailedException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot, OliveFail fail_reason) + : OperationFailedException(error_report, console, std::move(message), take_screenshot) + , m_fail_reason(fail_reason) +{} + + + + + +} diff --git a/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.h b/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.h new file mode 100644 index 000000000..600a1017c --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/Exceptions/OliveActionFailedException.h @@ -0,0 +1,46 @@ +/* Operation Failed Exception + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_OliveActionFailedException_H +#define PokemonAutomation_OliveActionFailedException_H + +#include +#include "OperationFailedException.h" + +namespace PokemonAutomation{ + +class FatalProgramException; + +enum class OliveFail{ + NONE, + FAILED_ALIGN_TO_OLIVE, + FAILED_PUSH_OLIVE_TOTAL_DISTANCE, + NO_OLIVE_DETECTED, + FAILED_WALK_TO_OLIVE, + OLIVE_STUCK, +}; + +// Thrown by subroutines if they fail for an in-game reason. +// These include recoverable errors which can be consumed by the program. +class OliveActionFailedException : public OperationFailedException{ +public: + explicit OliveActionFailedException(ErrorReport error_report, Logger& logger, std::string message, OliveFail fail_reason = OliveFail::NONE); + explicit OliveActionFailedException(ErrorReport error_report, Logger& logger, std::string message, std::shared_ptr screenshot, OliveFail fail_reason = OliveFail::NONE); + explicit OliveActionFailedException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot, OliveFail fail_reason = OliveFail::NONE); + + virtual const char* name() const override{ return "OliveActionFailedException"; } + +public: + OliveFail m_fail_reason; + +}; + + + + + +} +#endif