Skip to content

Commit

Permalink
Report error with screenshot when failing to read stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Oct 5, 2023
1 parent 97e7820 commit 402bb0b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ScreenshotException::ScreenshotException(ErrorReport error_report, ConsoleHandle
}
}
}
void ScreenshotException::attach_screenshot(std::shared_ptr<const ImageRGB32> screenshot){
m_screenshot = std::move(screenshot);
}
ImageViewRGB32 ScreenshotException::screenshot() const{
if (m_screenshot){
return *m_screenshot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ScreenshotException : public Exception{
explicit ScreenshotException(ErrorReport error_report, std::string message, std::shared_ptr<const ImageRGB32> screenshot);
explicit ScreenshotException(ErrorReport error_report, ConsoleHandle& console, std::string message, bool take_screenshot);

void attach_screenshot(std::shared_ptr<const ImageRGB32> screenshot);

public:
// virtual const char* name() const override{ return "ScreenshotException"; }
virtual std::string message() const override{ return m_message; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h"
#include "PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h"
#include "Pokemon/Pokemon_StatsCalculation.h"
#include "PokemonSV/Inference/PokemonSV_StatHexagonReader.h"

#ifdef PA_ARCH_x86
//#include "Kernels/Kernels_x64_SSE41.h"
Expand Down Expand Up @@ -237,10 +238,16 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco



ImageRGB32 image("screenshot-20231003-202430049819.png");
PokemonSummaryDetector detector;
cout << detector.detect(image) << endl;
ImageRGB32 image("screenshot-20231005-203932147068.png");
SummaryStatsReader reader;
// cout << detector.detect(image) << endl;
auto nature = reader.read_nature(env.logger(), image);

cout << (int)nature.attack << endl;
cout << (int)nature.defense << endl;
cout << (int)nature.spatk << endl;
cout << (int)nature.spdef << endl;
cout << (int)nature.speed << endl;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ NatureAdjustments StatHexagonReader::read_nature(Logger& logger, const ImageView
return ret;
}
if (non_neutral.size() != 2){
throw OperationFailedException(ErrorReport::SEND_ERROR_REPORT, logger, "Unable to read nature.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT,
logger,
"Unable to read nature."
);
}

if (*non_neutral[0].first != *non_neutral[1].first){
Expand All @@ -163,7 +167,11 @@ NatureAdjustments StatHexagonReader::read_nature(Logger& logger, const ImageView
return ret;
}

throw OperationFailedException(ErrorReport::SEND_ERROR_REPORT, logger, "Unable to read nature.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT,
logger,
"Unable to read nature."
);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ StatsResetBloodmoon::StatsResetBloodmoon()
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
, NOTIFICATIONS({
&NOTIFICATION_STATUS_UPDATE,
& NOTIFICATION_PROGRAM_FINISH,
& NOTIFICATION_ERROR_FATAL,
&NOTIFICATION_PROGRAM_FINISH,
&NOTIFICATION_ERROR_RECOVERABLE,
&NOTIFICATION_ERROR_FATAL,
})
{
#if 0
Expand Down Expand Up @@ -499,7 +500,17 @@ bool StatsResetBloodmoon::check_stats_after_win(SingleSwitchProgramEnvironment&
context.wait_for_all_requests();

auto snapshot = env.console.video().snapshot();
IvRanges ivs = reader.calc_ivs(env.logger(), snapshot, {113, 70, 120, 135, 65, 52});
IvRanges ivs;
try{
ivs = reader.calc_ivs(env.logger(), snapshot, {113, 70, 120, 135, 65, 52});
}catch (OperationFailedException& e){
send_program_recoverable_error_notification(
env, NOTIFICATION_ERROR_RECOVERABLE,
e.message(),
snapshot
);
return false;
}

CALCULATED_IVS.set(ivs);

Expand Down Expand Up @@ -578,7 +589,7 @@ void StatsResetBloodmoon::program(SingleSwitchProgramEnvironment& env, BotBaseCo
true
);
}

}
}
}

0 comments on commit 402bb0b

Please sign in to comment.