-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update Autostory tools. added UnexpectedBattleException. #493
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this, there will be 4 exception classes with near identical implementations. I'll probably revisit this in future to try to merge away some of this duplicate code.