-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update Autostory tools. added UnexpectedBattleException. (#493)
* update Autostory tools. added UnexpectedBattleException. add battle detection for functions that need to detect overworld * fix build * fix build * fix catch declaration
- Loading branch information
Showing
10 changed files
with
867 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
SerialPrograms/Source/CommonFramework/Exceptions/UnexpectedBattleException.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Unexpected Battle 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 "UnexpectedBattleException.h" | ||
|
||
namespace PokemonAutomation{ | ||
|
||
|
||
UnexpectedBattleException::UnexpectedBattleException(ErrorReport error_report, Logger& logger, std::string message) | ||
: ScreenshotException(error_report, std::move(message)) | ||
{ | ||
logger.log(std::string(UnexpectedBattleException::name()) + ": " + m_message, COLOR_RED); | ||
} | ||
UnexpectedBattleException::UnexpectedBattleException(ErrorReport error_report, Logger& logger, std::string message, std::shared_ptr<const ImageRGB32> screenshot) | ||
: ScreenshotException(error_report, std::move(message), std::move(screenshot)) | ||
{ | ||
logger.log(std::string(UnexpectedBattleException::name()) + ": " + m_message, COLOR_RED); | ||
} | ||
UnexpectedBattleException::UnexpectedBattleException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot) | ||
: ScreenshotException(error_report, console, std::move(message), take_screenshot) | ||
{ | ||
console.log(std::string(UnexpectedBattleException::name()) + ": " + m_message, COLOR_RED); | ||
} | ||
|
||
|
||
void UnexpectedBattleException::send_notification(ProgramEnvironment& env, EventNotificationOption& notification) const{ | ||
std::vector<std::pair<std::string, std::string>> embeds; | ||
if (!m_message.empty()){ | ||
embeds.emplace_back(std::pair<std::string, std::string>("Message:", m_message)); | ||
} | ||
if (m_send_error_report == ErrorReport::SEND_ERROR_REPORT && m_screenshot){ | ||
std::string label = name(); | ||
std::string filename = dump_image_alone(env.logger(), env.program_info(), label, *m_screenshot); | ||
send_program_telemetry( | ||
env.logger(), true, COLOR_RED, | ||
env.program_info(), | ||
label, | ||
embeds, | ||
filename | ||
); | ||
} | ||
send_program_notification( | ||
env, notification, | ||
COLOR_RED, | ||
"Program Error", | ||
std::move(embeds), "", | ||
screenshot() | ||
); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
SerialPrograms/Source/CommonFramework/Exceptions/UnexpectedBattleException.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Unexpected Battle Exception | ||
* | ||
* From: https://github.com/PokemonAutomation/Arduino-Source | ||
* | ||
*/ | ||
|
||
#ifndef PokemonAutomation_UnexpectedBattleException_H | ||
#define PokemonAutomation_UnexpectedBattleException_H | ||
|
||
#include <memory> | ||
#include "ScreenshotException.h" | ||
|
||
namespace PokemonAutomation{ | ||
|
||
class FatalProgramException; | ||
|
||
|
||
// Thrown by subroutines if caught in an wild battle in-game unexpectedly. | ||
// These include recoverable errors which can be consumed by the program. | ||
class UnexpectedBattleException : public ScreenshotException{ | ||
public: | ||
explicit UnexpectedBattleException(ErrorReport error_report, Logger& logger, std::string message); | ||
explicit UnexpectedBattleException(ErrorReport error_report, Logger& logger, std::string message, std::shared_ptr<const ImageRGB32> screenshot); | ||
explicit UnexpectedBattleException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot); | ||
|
||
virtual const char* name() const override{ return "UnexpectedBattleException"; } | ||
virtual std::string message() const override{ return m_message; } | ||
|
||
virtual void send_notification(ProgramEnvironment& env, EventNotificationOption& notification) const override; | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.