Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* BBQ Failure Snapshots
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <sstream>
#include "Common/Cpp/PrettyPrint.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "PokemonSV_BBQSnapshot.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


std::string bbq_snapshot_directory(){
return DEBUG_PATH() + "BBQ/";
}

std::string save_bbq_snapshot(
Logger& logger, const ImageViewRGB32& frame,
const std::string& directory, BBQuests quest, std::string_view reason
){
const std::string& slug = BBQuests_enum_to_string(quest);
std::ostringstream path;
path << directory << now_to_filestring() << '-'
<< (slug.empty() ? "unknown" : slug) << '-' << reason << ".png";
const std::string filename = path.str();

const bool saved = frame.save(filename);
std::ostringstream out;
out << "BBQ event=snapshot saved=" << saved << " path=" << filename;
logger.log(out.str());
return saved ? filename : std::string();
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* BBQ Failure Snapshots
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonSV_BBQSnapshot_H
#define PokemonAutomation_PokemonSV_BBQSnapshot_H

#include <string>
#include <string_view>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "VideoGames/PokemonSV/Options/PokemonSV_BBQuests.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


// Where BBQ failure screenshots are saved: DEBUG_PATH()/BBQ/.
std::string bbq_snapshot_directory();

// Save a screenshot of a failed quest attempt into `directory` (created if
// missing) as <timestamp>-<quest>-<reason>.png, and log the outcome as a
// "BBQ event=snapshot" line. Unlike dump_image(), this stays on the local
// machine and sends nothing to telemetry.
// Returns the path written, or an empty string if the image was not saved.
std::string save_bbq_snapshot(
Logger& logger, const ImageViewRGB32& frame,
const std::string& directory, BBQuests quest, std::string_view reason
);


}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
*
*/

#include <filesystem>
#include <fstream>
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Tests/ImageUnitTest.h"
#include "VideoGames/PokemonSV/Inference/PokemonSV_BlueberryPointsReader.h"
#include "VideoGames/PokemonSV/Options/PokemonSV_BBQuests.h"
#include "PokemonSV_BBQLogger.h"
#include "PokemonSV_BBQSnapshot.h"
#include "PokemonSV_BlueberryQuests.h"
#include "PokemonSV_BBQTests.h"

Expand Down Expand Up @@ -206,6 +210,92 @@
}


namespace{

// A fresh folder under the system temp folder, removed afterwards.
class TempFolder{
public:
TempFolder()
: path(std::filesystem::temp_directory_path() / ("bbq-snapshot-test-" + now_to_filestring()))

Check failure on line 219 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: std::filesystem is banned; use the Common/Cpp/Filesystem wrappers (Path, Filesystem::, FileIO) (upstream AGENTS.md "Filesystem")
{
std::filesystem::create_directories(path);

Check failure on line 221 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: std::filesystem is banned; use the Common/Cpp/Filesystem wrappers (Path, Filesystem::, FileIO) (upstream AGENTS.md "Filesystem")
}
~TempFolder(){
std::error_code error;
std::filesystem::remove_all(path, error);

Check failure on line 225 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: std::filesystem is banned; use the Common/Cpp/Filesystem wrappers (Path, Filesystem::, FileIO) (upstream AGENTS.md "Filesystem")
}
const std::filesystem::path path;

Check failure on line 227 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: std::filesystem is banned; use the Common/Cpp/Filesystem wrappers (Path, Filesystem::, FileIO) (upstream AGENTS.md "Filesystem")
};

ImageRGB32 small_frame(){
ImageRGB32 frame(4, 4);
frame.fill(0xff00ff00);
return frame;
}

class Test_BBQSnapshotSaved : public UnitTest{
public:
Test_BBQSnapshotSaved() : UnitTest("PokemonSV::BBQSnapshot - saves into a new folder") {}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
TempFolder temp;
const std::string directory = (temp.path / "BBQ").string() + "/";
BBQTestLogger logger;

const std::string path = save_bbq_snapshot(
logger, small_frame(), directory, BBQuests::make_tm, "verification-failed"
);

const std::string suffix = "-make-tm-verification-failed.png";
if (path.rfind(directory, 0) != 0 || path.size() < suffix.size()
|| path.compare(path.size() - suffix.size(), suffix.size(), suffix) != 0
){
return "Unexpected snapshot path: " + path;
}
if (!std::filesystem::exists(path)){

Check failure on line 255 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

style: std::filesystem is banned; use the Common/Cpp/Filesystem wrappers (Path, Filesystem::, FileIO) (upstream AGENTS.md "Filesystem")
return "Snapshot was not written: " + path;
}
if (logger.messages != std::vector<std::string>{"BBQ event=snapshot saved=1 path=" + path}){
return "Unexpected snapshot log.";
}
return true;
}
};

class Test_BBQSnapshotFailed : public UnitTest{
public:
Test_BBQSnapshotFailed() : UnitTest("PokemonSV::BBQSnapshot - reports a failed save") {}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
// The folder cannot be created because a file already has its name.
TempFolder temp;
std::ofstream(temp.path / "BBQ") << "not a folder";
const std::string directory = (temp.path / "BBQ").string() + "/";
BBQTestLogger logger;

const std::string path = save_bbq_snapshot(
logger, small_frame(), directory, BBQuests::make_tm, "verification-failed"
);

if (!path.empty()){
return "Expected no path for a failed save, got: " + path;
}
const std::string expected_prefix = "BBQ event=snapshot saved=0 path=" + directory;
if (logger.messages.size() != 1 || logger.messages[0].rfind(expected_prefix, 0) != 0){
return "Unexpected snapshot log.";
}
return true;
}
};

}

static void add_tests_BBQSnapshot(UnitTestDatabase& database){
database.add<Test_BBQSnapshotSaved>();
database.add<Test_BBQSnapshotFailed>();
}


void add_tests_BBQ(UnitTestDatabase& database){
database.add<Test_BBQuestsSlugs>();

Expand All @@ -219,6 +309,7 @@

add_tests_TeraEncounterAction(database);
add_tests_BBQDiagnosticLogs(database);
add_tests_BBQSnapshot(database);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Blueberry Catch Photo

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1064, limit=1000, allowed 1059
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -27,6 +27,7 @@
#include "VideoGames/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h"
#include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h"
#include "PokemonSV_BBQLogger.h"
#include "PokemonSV_BBQSnapshot.h"
#include "PokemonSV_BlueberryCatchPhoto.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -894,7 +895,7 @@
}
}

void quest_catch(

Check failure on line 898 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::quest_catch( const ProgramInfo & info , ConsoleHandle & console , ProControllerContext & context , const BBQOption & BBQ_OPTIONS , BBQuests current_quest): function_lines=82, limit=50, allowed 78
const ProgramInfo& info,
ConsoleHandle& console, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
Expand All @@ -919,6 +920,10 @@
if (ret2 != 0){
console.log("Did not enter battle. Did target spawn?");
BBQLogger(console.logger()).battle_entry_timeout(current_quest);
save_bbq_snapshot(
console.logger(), console.video().snapshot(),
bbq_snapshot_directory(), current_quest, "battle-entry-timeout"
);
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Blueberry Quests

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1335, limit=1000, allowed 1330
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -43,6 +43,7 @@
#include "VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h"
#include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h"
#include "PokemonSV_BBQLogger.h"
#include "PokemonSV_BBQSnapshot.h"

#include "PokemonSV_BlueberryQuests.h"

Expand Down Expand Up @@ -309,7 +310,7 @@
return quests_to_do;
}

bool process_and_do_quest(

Check failure on line 313 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::process_and_do_quest( ProgramEnvironment & env , ConsoleHandle & console , ProControllerContext & context , BBQOption & BBQ_OPTIONS , BBQuests current_quest , uint8_t & eggs_hatched): function_lines=140, limit=50, allowed 136
ProgramEnvironment& env,
ConsoleHandle& console, ProControllerContext& context,
BBQOption& BBQ_OPTIONS,
Expand Down Expand Up @@ -425,6 +426,10 @@
std::vector<BBQuests> quest_list = read_quests(env.program_info(), console, context, BBQ_OPTIONS);
if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){
console.log("Current quest exists on list. Quest did not complete.");
save_bbq_snapshot(
console.logger(), console.video().snapshot(),
bbq_snapshot_directory(), current_quest, "verification-failed"
);
quest_attempts++;
}else{
console.log("Current quest was not found. Quest completed!");
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,8 @@ file(GLOB LIBRARY_SOURCES
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.h
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.cpp
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQLogger.h
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSnapshot.cpp
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSnapshot.h
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h
Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp
Expand Down
Loading