From 608b0ddcfb4f9d7f566283745227605434869e81 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:01:40 -0300 Subject: [PATCH] New Command: 2054 - GetTime Gets current date information and attach it to a variable. Usage: ```js @raw 2054, "Type_of_Date", targetVar_IsVar, targerVat ``` ```js // "set year to variable 1:" @raw 2054, "getYear", 0, 1 // "set month to variable 2:" @raw 2054, "getMonth", 0, 2 // "set day to variable 3:" @raw 2054, "getDay", 0, 3 // "set hour to variable 4:" @raw 2054, "getHour", 0, 4 // "set minute to variable 5:" @raw 2054, "getMinute", 0, 5 // "set second to variable 6:" @raw 2054, "getSecond", 0, 6 // "set day of week to variable 7:" @raw 2054, "getWeekDay", 0, 7 // "set days in year to variable 8:" @raw 2054, "getYearDay", 0, 8 ``` --- src/game_interpreter.cpp | 30 ++++++++++++++++++++++++++++++ src/game_interpreter.h | 1 + 2 files changed, 31 insertions(+) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 353d66fa9fa..cd035d42fd2 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -821,6 +821,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) { return CommandManiacSetGameOption(com); case Cmd::Maniac_CallCommand: return CommandManiacCallCommand(com); + case static_cast(2054): //Cmd::EasyRpg_GetTime + return CommandGetTime(com); default: return true; } @@ -4643,6 +4645,34 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) { return true; } +bool Game_Interpreter::CommandGetTime(lcf::rpg::EventCommand const& com) { + + std::string periodName = Utils::LowerCase(ToString(com.string)); + int32_t outputVariable = ValueOrVariable(com.parameters[0], com.parameters[1]); + + lcf::rpg::EventCommand outputCommand; + outputCommand.code = int(Cmd::ControlVars); + + std::time_t t = std::time(nullptr); + std::tm* tm = std::localtime(&t); + + int32_t dateOutput{}; + + if (periodName == "getyear") dateOutput = tm->tm_year + 1900; + if (periodName == "getmonth") dateOutput = tm->tm_mon + 1; + if (periodName == "getday") dateOutput = tm->tm_mday; + if (periodName == "gethour") dateOutput = tm->tm_hour; + if (periodName == "getminute") dateOutput = tm->tm_min; + if (periodName == "getsecond") dateOutput = tm->tm_sec; + if (periodName == "getweekday") dateOutput = tm->tm_wday +1; + if (periodName == "getyearday") dateOutput = tm->tm_yday +1; + + std::vector updateVarParams = { 0, outputVariable, 0, 0, 0, dateOutput }; + outputCommand.parameters = lcf::DBArray(updateVarParams.begin(), updateVarParams.end()); + + return ExecuteCommand(outputCommand); +} + Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() { return Game_Battle::IsBattleRunning() ? Game_Battle::GetInterpreter() diff --git a/src/game_interpreter.h b/src/game_interpreter.h index a436cbfaed1..085fda3e7c8 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -284,6 +284,7 @@ class Game_Interpreter bool CommandManiacChangePictureId(lcf::rpg::EventCommand const& com); bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com); bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com); + bool CommandGetTime(lcf::rpg::EventCommand const& com); int DecodeInt(lcf::DBArray::const_iterator& it); const std::string DecodeString(lcf::DBArray::const_iterator& it);