Skip to content

Commit 272dc77

Browse files
author
Gin
committed
Add boiler plate ThreeSegmentDudunsparceFinder
1 parent a5da87a commit 272dc77

File tree

9 files changed

+159
-12
lines changed

9 files changed

+159
-12
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,8 @@ file(GLOB MAIN_SOURCES
17861786
Source/PokemonSV/Programs/PokemonSV_SaveGame.h
17871787
Source/PokemonSV/Programs/PokemonSV_Terarium.cpp
17881788
Source/PokemonSV/Programs/PokemonSV_Terarium.h
1789+
Source/PokemonSV/Programs/PokemonSV_ThreeSegmentDudunsparceFinder.cpp
1790+
Source/PokemonSV/Programs/PokemonSV_ThreeSegmentDudunsparceFinder.h
17891791
Source/PokemonSV/Programs/Sandwiches/PokemonSV_IngredientSession.cpp
17901792
Source/PokemonSV/Programs/Sandwiches/PokemonSV_IngredientSession.h
17911793
Source/PokemonSV/Programs/Sandwiches/PokemonSV_SandwichMaker.cpp

SerialPrograms/Scripts/CodeTemplates/Program/GameName_ProgramName.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*
55
*/
66

7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
78
#include "CommonFramework/Notifications/ProgramNotifications.h"
89
#include "CommonFramework/ProgramStats/StatsTracking.h"
910
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
1011
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
12+
#include "GameName_ProgramName.h"
1113

1214
namespace PokemonAutomation{
1315
namespace NintendoSwitch{

SerialPrograms/Scripts/CodeTemplates/Program/GameName_ProgramName.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1313

1414
namespace PokemonAutomation{
15-
16-
class OperationFailedException;
17-
1815
namespace NintendoSwitch{
1916
namespace GameName{
2017

SerialPrograms/Scripts/add_new_file.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def get_code_file_range(file_lines: List[str], starting_line: str, ending_line:
7575

7676

7777

78-
cmakelists_path = code_root_path + os.sep + "SerialPrograms" + os.sep + "CMakeLists.txt"
79-
pro_path = code_root_path + os.sep + "SerialPrograms" + os.sep + "SerialPrograms.pro"
80-
print(f"Found CMakeLists path {cmakelists_path}")
81-
print(f"Found QT Pro project file path {pro_path}")
78+
cmakelists_path = os.path.join(code_root_path, "SerialPrograms", "CMakeLists.txt")
79+
pro_path = os.path.join(code_root_path, "SerialPrograms", "SerialPrograms.pro")
80+
print(f"CMakeLists path: {cmakelists_path}")
81+
print(f"QT Pro project file path: {pro_path}")
8282

8383
file_lines = read_lines(cmakelists_path)
8484
old_file_lines = file_lines
@@ -105,6 +105,9 @@ def get_code_file_range(file_lines: List[str], starting_line: str, ending_line:
105105
f.writelines(file_lines)
106106
print(f"Writed changes back to {cmakelists_path}")
107107

108+
if not os.path.exists(pro_path):
109+
print(f"Pro file not found. End.")
110+
exit(0)
108111

109112
file_lines = read_lines(pro_path)
110113

SerialPrograms/Source/PokemonSV/PokemonSV_Panels.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
#include "Programs/TestPrograms/PokemonSV_SoundListener.h"
6363

64+
#include "Programs/PokemonSV_ThreeSegmentDudunsparceFinder.h"
65+
6466
#ifdef PA_OFFICIAL
6567
#include "../../Internal/SerialPrograms/NintendoSwitch_TestPrograms.h"
6668
#endif
@@ -150,13 +152,11 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
150152
}
151153
if (IS_BETA_VERSION){
152154
// ret.emplace_back("---- Story Automation ----");
153-
}
154-
if (PreloadSettings::instance().DEVELOPER_MODE){
155-
156155
}
157156
if (PreloadSettings::instance().DEVELOPER_MODE){
158157
ret.emplace_back("---- Developer Tools ----");
159158
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
159+
ret.emplace_back(make_single_switch_program<ThreeSegmentDudunsparceFinder_Descriptor, ThreeSegmentDudunsparceFinder>());
160160
}
161161

162162
#ifdef PA_OFFICIAL

SerialPrograms/Source/PokemonSV/Programs/Eggs/PokemonSV_EggAutonomous.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void EggAutonomous::program(SingleSwitchProgramEnvironment& env, ProControllerCo
185185
assert_16_9_720p_min(env.logger(), env.console);
186186

187187
// Connect the controller.
188-
pbf_press_button(context, BUTTON_L, 10, 0);
188+
pbf_press_button(context, BUTTON_L, 10, 100);
189189

190190
{
191191
// reset_position_to_flying_spot(env, context);

SerialPrograms/Source/PokemonSV/Programs/Eggs/PokemonSV_EggFetcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void EggFetcher::program(SingleSwitchProgramEnvironment& env, ProControllerConte
9191
EggFetcher_Descriptor::Stats& stats = env.current_stats<EggFetcher_Descriptor::Stats>();
9292

9393
// Connect the controller.
94-
pbf_press_button(context, BUTTON_L, 10, 0);
94+
pbf_press_button(context, BUTTON_L, 10, 100);
9595

9696
size_t num_eggs_collected = 0;
9797

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* Three-Segment Dudunsparce Finder
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
8+
#include "CommonFramework/Notifications/ProgramNotifications.h"
9+
#include "CommonFramework/ProgramStats/StatsTracking.h"
10+
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
11+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
12+
#include "PokemonSV_ThreeSegmentDudunsparceFinder.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonSV{
17+
18+
19+
ThreeSegmentDudunsparceFinder_Descriptor::ThreeSegmentDudunsparceFinder_Descriptor()
20+
: SingleSwitchProgramDescriptor(
21+
"PokemonSV:ThreeSegmentDudunsparceFinder",
22+
"Game Name", "Three-Segment Dudunsparce Finder",
23+
"ComputerControl/blob/master/Wiki/Programs/PokemonSV/ThreeSegmentDudunsparceFinder.md",
24+
"<Description of this program>.",
25+
FeedbackType::REQUIRED,
26+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
27+
{ControllerFeature::NintendoSwitch_ProController},
28+
FasterIfTickPrecise::NOT_FASTER
29+
)
30+
{}
31+
struct ThreeSegmentDudunsparceFinder_Descriptor::Stats : public StatsTracker{
32+
Stats()
33+
: m_attempts(m_stats["Attempts"])
34+
, m_errors(m_stats["Errors"])
35+
{
36+
m_display_order.emplace_back("Attempts");
37+
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
38+
}
39+
std::atomic<uint64_t>& m_attempts;
40+
std::atomic<uint64_t>& m_errors;
41+
};
42+
std::unique_ptr<StatsTracker> ThreeSegmentDudunsparceFinder_Descriptor::make_stats() const{
43+
return std::unique_ptr<StatsTracker>(new Stats());
44+
}
45+
46+
47+
48+
ThreeSegmentDudunsparceFinder::ThreeSegmentDudunsparceFinder()
49+
: GO_HOME_WHEN_DONE(false)
50+
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
51+
, NOTIFICATIONS({
52+
&NOTIFICATION_STATUS_UPDATE,
53+
&NOTIFICATION_PROGRAM_FINISH,
54+
&NOTIFICATION_ERROR_RECOVERABLE,
55+
&NOTIFICATION_ERROR_FATAL,
56+
})
57+
{
58+
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
59+
PA_ADD_OPTION(NOTIFICATIONS);
60+
}
61+
62+
63+
void ThreeSegmentDudunsparceFinder::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
64+
assert_16_9_720p_min(env.logger(), env.console);
65+
66+
ThreeSegmentDudunsparceFinder_Descriptor::Stats& stats = env.current_stats<ThreeSegmentDudunsparceFinder_Descriptor::Stats>();
67+
68+
// Connect the controller.
69+
pbf_press_button(context, BUTTON_L, 10, 100);
70+
71+
try{
72+
73+
} catch(OperationFailedException&){
74+
stats.m_errors++;
75+
env.update_stats();
76+
throw;
77+
}
78+
79+
env.update_stats();
80+
GO_HOME_WHEN_DONE.run_end_of_program(context);
81+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
82+
}
83+
84+
85+
86+
87+
88+
89+
}
90+
}
91+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Three-Segment Dudunsparce Finder
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_ThreeSegmentDudunsparceFinder_H
8+
#define PokemonAutomation_PokemonSV_ThreeSegmentDudunsparceFinder_H
9+
10+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
11+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
12+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonSV{
17+
18+
19+
20+
class ThreeSegmentDudunsparceFinder_Descriptor : public SingleSwitchProgramDescriptor{
21+
public:
22+
ThreeSegmentDudunsparceFinder_Descriptor();
23+
24+
struct Stats;
25+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
26+
};
27+
28+
29+
30+
class ThreeSegmentDudunsparceFinder : public SingleSwitchProgramInstance{
31+
public:
32+
ThreeSegmentDudunsparceFinder();
33+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
34+
35+
private:
36+
37+
private:
38+
39+
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
40+
41+
42+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
43+
EventNotificationsOption NOTIFICATIONS;
44+
};
45+
46+
47+
48+
49+
}
50+
}
51+
}
52+
#endif

0 commit comments

Comments
 (0)