|
| 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 | + |
0 commit comments