Skip to content

Commit

Permalink
Fix build. Migrate more RPCs to CC.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Dec 20, 2023
1 parent af78c05 commit c67cc68
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
26 changes: 26 additions & 0 deletions Common/Cpp/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,36 @@
*
*/

#include <ctime>
#include "Time.h"

namespace PokemonAutomation{



uint16_t current_year(){
#if 0
// This requires C++20. (https://stackoverflow.com/a/58152002)
return (uint16_t)std::atoi(
std::format("{:%Y}", std::chrono::system_clock::now())
);
#endif

#if 1
// This is not thread-safe. (https://stackoverflow.com/a/58153628)
// (Thread-safe on Windows because it uses TLS, but unclear on other platforms.)
std::time_t t = std::time(nullptr);
std::tm* info = std::localtime(&t);
return (uint16_t)(info->tm_year + 1900);
#endif

#if 0
// This is wrong. (https://stackoverflow.com/a/67459754)
time_t current_time = time(nullptr);
return (uint16_t)(1970 + current_time / 31537970);
#endif
}



}
2 changes: 2 additions & 0 deletions Common/Cpp/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ inline WallClock current_time(){
}


uint16_t current_year();


}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@

#include <sstream>
#include "ClientSource/Libraries/MessageConverter.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
#include "NintendoSwitch_Commands_Routines.h"
#include "NintendoSwitch_Messages_Routines.h"
//#include "NintendoSwitch_Messages_Routines.h"

namespace PokemonAutomation{
namespace NintendoSwitch{


void close_game(BotBaseContext& context){
#if 0
context.issue_request(
DeviceRequest_close_game()
);
#else
// Use mashing to ensure that the X press succeeds. If it fails, the SR
// will fail and can kill a den for the autohosts.
ssf_mash1_button(context, BUTTON_X, 100); // Close game
ssf_mash2_button(context, BUTTON_X, BUTTON_A, 50); // Confirm close game
ssf_mash1_button(context, BUTTON_X, 50);
ssf_mash1_button(context, BUTTON_B, 350);
#endif
}



#if 0
int register_message_converters_routines(){
register_message_converter(
PABB_MSG_COMMAND_CLOSE_GAME,
Expand All @@ -38,6 +46,7 @@ int register_message_converters_routines(){
return 0;
}
int init_NintendoSwitchRoutines = register_message_converters_routines();
#endif


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ DaySkipperEU::DaySkipperEU()
, REAL_LIFE_YEAR(
"<b>Real Life Year:</b>",
LockMode::LOCK_WHILE_RUNNING,
std::min(
(uint16_t)std::atoi(std::format("{:%Y}", current_time()).c_str()),
(uint16_t)2060
),
std::min(current_year(), (uint16_t)2060),
2000, 2060
)
, NOTIFICATION_PROGRESS_UPDATE("Progress Update", true, false, std::chrono::seconds(3600))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ DaySkipperUS::DaySkipperUS()
, REAL_LIFE_YEAR(
"<b>Real Life Year:</b>",
LockMode::LOCK_WHILE_RUNNING,
std::min(
(uint16_t)std::atoi(std::format("{:%Y}", current_time()).c_str()),
(uint16_t)2060
),
std::min(current_year(), (uint16_t)2060),
2000, 2060
)
, NOTIFICATION_PROGRESS_UPDATE("Progress Update", true, false, std::chrono::seconds(3600))
Expand Down

0 comments on commit c67cc68

Please sign in to comment.