Skip to content

Commit

Permalink
Draft Auto Item Printer
Browse files Browse the repository at this point in the history
  • Loading branch information
NympheaR authored Dec 28, 2023
1 parent c3155e4 commit 1f1744e
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_FastCodeEntry.h
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_VideoFastCodeEntry.cpp
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_VideoFastCodeEntry.h
Source/PokemonSV/Programs/General/PokemonSV_AutoItemPrinter.cpp
Source/PokemonSV/Programs/General/PokemonSV_AutoItemPrinter.h
Source/PokemonSV/Programs/General/PokemonSV_AutonomousBallThrower.cpp
Source/PokemonSV/Programs/General/PokemonSV_AutonomousBallThrower.h
Source/PokemonSV/Programs/General/PokemonSV_ClothingBuyer.cpp
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/SerialPrograms.pro
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ SOURCES += \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_CodeEntry.cpp \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_FastCodeEntry.cpp \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_VideoFastCodeEntry.cpp \
Source/PokemonSV/Programs/General/PokemonSV_AutoItemPrinter.cpp \
Source/PokemonSV/Programs/General/PokemonSV_AutonomousBallThrower.cpp \
Source/PokemonSV/Programs/General/PokemonSV_ClothingBuyer.cpp \
Source/PokemonSV/Programs/General/PokemonSV_MassPurchase.cpp \
Expand Down Expand Up @@ -1768,6 +1769,7 @@ HEADERS += \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_CodeEntry.h \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_FastCodeEntry.h \
Source/PokemonSV/Programs/FastCodeEntry/PokemonSV_VideoFastCodeEntry.h \
Source/PokemonSV/Programs/General/PokemonSV_AutoItemPrinter.h \
Source/PokemonSV/Programs/General/PokemonSV_AutonomousBallThrower.h \
Source/PokemonSV/Programs/General/PokemonSV_ClothingBuyer.h \
Source/PokemonSV/Programs/General/PokemonSV_MassPurchase.h \
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonSV/PokemonSV_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Programs/General/PokemonSV_ClothingBuyer.h"
#include "Programs/General/PokemonSV_AutonomousBallThrower.h"
#include "Programs/General/PokemonSV_SizeChecker.h"
#include "Programs/General/PokemonSV_AutoItemPrinter.h"

#include "Programs/Boxes/PokemonSV_MassRelease.h"
#include "Programs/Boxes/PokemonSV_MassAttachItems.h"
Expand Down Expand Up @@ -78,6 +79,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
ret.emplace_back(make_single_switch_program<ClothingBuyer_Descriptor, ClothingBuyer>());
ret.emplace_back(make_single_switch_program<AutonomousBallThrower_Descriptor, AutonomousBallThrower>());
ret.emplace_back(make_single_switch_program<SizeChecker_Descriptor, SizeChecker>());
ret.emplace_back(make_single_switch_program<AutoItemPrinter_Descriptor, AutoItemPrinter>());

// ret.emplace_back("---- Trading ----");
ret.emplace_back(make_multi_switch_program<SelfBoxTrade_Descriptor, SelfBoxTrade>());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* Auto Item Printer
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/Inference/BlackScreenDetector.h"
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Tools/StatsTracking.h"
#include "CommonFramework/Tools/VideoResolutionCheck.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
#include "PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h"
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
#include "PokemonSV_AutoItemPrinter.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

using namespace Pokemon;


AutoItemPrinter_Descriptor::AutoItemPrinter_Descriptor()
: SingleSwitchProgramDescriptor(
"PokemonSV:AutoItemPrinter",
STRING_POKEMON + " SV", "Auto Item Printer",
"ComputerControl/blob/master/Wiki/Programs/PokemonSV/AutoItemPrinter.md",
"Automate the Item Printer for rare items.",
FeedbackType::REQUIRED,
AllowCommandsWhenRunning::DISABLE_COMMANDS,
PABotBaseLevel::PABOTBASE_12KB
)
{}
struct AutoItemPrinter_Descriptor::Stats : public StatsTracker{
Stats()
: m_rounds(m_stats["Rounds"])
{
m_display_order.emplace_back("Rounds");
}
std::atomic<uint64_t>& m_rounds;
};
std::unique_ptr<StatsTracker> AutoItemPrinter_Descriptor::make_stats() const{
return std::unique_ptr<StatsTracker>(new Stats());
}



AutoItemPrinter::AutoItemPrinter()
: GO_HOME_WHEN_DONE(false)
, NUM_ROUNDS(
"<b>Number of Rounds to Run:</b>",
LockMode::UNLOCK_WHILE_RUNNING,
100
)
, NOTIFICATIONS({
&NOTIFICATION_PROGRAM_FINISH,
&NOTIFICATION_ERROR_FATAL,
})
{
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
PA_ADD_OPTION(NUM_ROUNDS);
PA_ADD_OPTION(NOTIFICATIONS);
}




void AutoItemPrinter::program(SingleSwitchProgramEnvironment& env, BotBaseContext& context){
assert_16_9_720p_min(env.logger(), env.console);

AutoItemPrinter_Descriptor::Stats& stats = env.current_stats<AutoItemPrinter_Descriptor::Stats>();

// Connect the controller.
pbf_press_button(context, BUTTON_L, 10, 0);

stats.m_trials++;
env.update_stats();

send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
GO_HOME_WHEN_DONE.run_end_of_program(context);
}



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Auto Item Printer
*
* From: https://github.com/PokemonAutomation/Arduino-Source
*
*/

#ifndef PokemonAutomation_PokemonSV_AutoItemPrinter_H
#define PokemonAutomation_PokemonSV_AutoItemPrinter_H

#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

class AutoItemPrinter_Descriptor : public SingleSwitchProgramDescriptor{
public:
AutoItemPrinter_Descriptor();

struct Stats;
virtual std::unique_ptr<StatsTracker> make_stats() const override;

};




class AutoItemPrinter : public SingleSwitchProgramInstance{
public:
AutoItemPrinter();
virtual void program(SingleSwitchProgramEnvironment& env, BotBaseContext& context) override;

private:
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
SimpleIntegerOption<uint16_t> NUM_ROUNDS;

EventNotificationsOption NOTIFICATIONS;
};



}
}
}
#endif

0 comments on commit 1f1744e

Please sign in to comment.