Skip to content

Commit 9cca2cc

Browse files
committed
donut options test program
1 parent 34fb511 commit 9cca2cc

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h"
4949
#include "Programs/TestPrograms/PokemonLZA_TestBoxCellInfo.h"
5050
#include "InferenceTraining/PokemonLZA_GenerateLocationNameOCR.h"
51+
#include "Programs/TestPrograms/PokemonLZA_DonutOptionsTest.h"
5152

5253
namespace PokemonAutomation{
5354
namespace NintendoSwitch{
@@ -114,6 +115,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
114115
ret.emplace_back(make_single_switch_program<MoveBoxArrow_Descriptor, MoveBoxArrow>());
115116
ret.emplace_back(make_single_switch_program<TestBoxCellInfo_Descriptor, TestBoxCellInfo>());
116117
ret.emplace_back(make_single_switch_program<GenerateLocationNameOCR_Descriptor, GenerateLocationNameOCR>());
118+
ret.emplace_back(make_single_switch_program<DonutOptionsTest_Descriptor, DonutOptionsTest>());
117119
}
118120
return ret;
119121
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* Donut Options Test
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Notifications/ProgramNotifications.h"
8+
#include "CommonFramework/Exceptions/OperationFailedException.h"
9+
#include "CommonTools/Async/InferenceRoutines.h"
10+
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
11+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
12+
#include "Pokemon/Pokemon_Strings.h"
13+
#include "PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h"
14+
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
15+
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" //TODO: change/remove later
16+
#include "PokemonLZA_DonutOptionsTest.h"
17+
18+
namespace PokemonAutomation{
19+
namespace NintendoSwitch{
20+
namespace PokemonLZA{
21+
22+
using namespace Pokemon;
23+
24+
DonutOptionsTest_Descriptor::DonutOptionsTest_Descriptor()
25+
: SingleSwitchProgramDescriptor(
26+
"PokemonLZA:DonutOptionsTest",
27+
STRING_POKEMON + " LZA", "Donut Options Test",
28+
"Programs/PokemonLZA/DonutOptionsTest.html",
29+
"Testing options layout for donut making.",
30+
ProgramControllerClass::StandardController_NoRestrictions,
31+
FeedbackType::REQUIRED,
32+
AllowCommandsWhenRunning::DISABLE_COMMANDS
33+
)
34+
{}
35+
36+
DonutOptionsTest::DonutOptionsTest()
37+
: LANGUAGE(
38+
"<b>Game Language:</b>",
39+
PokemonSwSh::IV_READER().languages(), //TODO: replace?
40+
LockMode::LOCK_WHILE_RUNNING,
41+
true
42+
)
43+
, BERRIES("<b>Berries:</b><br>The berries used to make the donut. Minimum 3 berries, maximum 8 berries.")
44+
, NUM_DONUTS(
45+
"<b>Number of Donuts:</b><br>The number of donuts to make.",
46+
LockMode::LOCK_WHILE_RUNNING,
47+
1, 1
48+
)
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_FATAL,
55+
})
56+
{
57+
PA_ADD_OPTION(LANGUAGE);
58+
PA_ADD_OPTION(BERRIES);
59+
PA_ADD_OPTION(NUM_DONUTS);
60+
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
61+
PA_ADD_OPTION(NOTIFICATIONS);
62+
}
63+
64+
void DonutOptionsTest::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
65+
assert_16_9_720p_min(env.logger(), env.console);
66+
67+
const Language language = LANGUAGE;
68+
if (language == Language::None){
69+
throw UserSetupError(env.console, "Must set game language option to read ingredient lists.");
70+
}
71+
72+
//Validate number of selected berries
73+
env.log("Checking berry count.");
74+
75+
size_t num_berries = 0;
76+
std::vector<std::unique_ptr<DonutBerriesTableRow>> berries_table = BERRIES.copy_snapshot();
77+
num_berries = berries_table.size();
78+
79+
if (num_berries < 3 || num_berries > 8) {
80+
throw UserSetupError(env.console, "Must have at least 3 berries and no more than 8 berries.");
81+
}
82+
env.log("Number of berries validated.", COLOR_BLACK);
83+
84+
85+
GO_HOME_WHEN_DONE.run_end_of_program(context);
86+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
87+
}
88+
89+
90+
}
91+
}
92+
}
93+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Donut Options Test
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_DonutOptionsTest_H
8+
#define PokemonAutomation_PokemonLZA_DonutOptionsTest_H
9+
10+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
11+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
12+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
13+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
14+
#include "CommonTools/Options/LanguageOCROption.h"
15+
#include "PokemonLZA/Options/PokemonLZA_DonutBerriesOption.h"
16+
17+
namespace PokemonAutomation{
18+
namespace NintendoSwitch{
19+
namespace PokemonLZA{
20+
21+
class DonutOptionsTest_Descriptor : public SingleSwitchProgramDescriptor{
22+
public:
23+
DonutOptionsTest_Descriptor();
24+
};
25+
26+
class DonutOptionsTest : public SingleSwitchProgramInstance{
27+
public:
28+
DonutOptionsTest();
29+
30+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
31+
32+
private:
33+
OCR::LanguageOCROption LANGUAGE;
34+
DonutBerriesTable BERRIES;
35+
SimpleIntegerOption<uint8_t> NUM_DONUTS;
36+
37+
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
38+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
39+
EventNotificationsOption NOTIFICATIONS;
40+
};
41+
42+
43+
44+
45+
46+
}
47+
}
48+
}
49+
#endif

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,8 @@ file(GLOB LIBRARY_SOURCES
16921692
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneCafe.h
16931693
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.cpp
16941694
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h
1695+
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_DonutOptionsTest.cpp
1696+
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_DonutOptionsTest.h
16951697
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.cpp
16961698
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h
16971699
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_OverworldWatcher.cpp

0 commit comments

Comments
 (0)