Skip to content

Commit 1daf444

Browse files
committed
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 ```
1 parent ad6e823 commit 1daf444

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/game_interpreter.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
821821
return CommandManiacSetGameOption(com);
822822
case Cmd::Maniac_CallCommand:
823823
return CommandManiacCallCommand(com);
824+
case static_cast<Game_Interpreter::Cmd>(2054): //Cmd::EasyRpg_GetTime
825+
return CommandGetTime(com);
824826
default:
825827
return true;
826828
}
@@ -4643,6 +4645,32 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) {
46434645
return true;
46444646
}
46454647

4648+
bool Game_Interpreter::CommandGetTime(lcf::rpg::EventCommand const& com) {
4649+
4650+
std::string periodName = Utils::LowerCase(ToString(com.string));
4651+
int32_t outputVariable = ValueOrVariable(com.parameters[0], com.parameters[1]);
4652+
4653+
std::time_t t = std::time(nullptr);
4654+
std::tm* tm = std::localtime(&t);
4655+
4656+
int32_t dateOutput{};
4657+
4658+
if (periodName == "getyear") dateOutput = tm->tm_year + 1900;
4659+
if (periodName == "getmonth") dateOutput = tm->tm_mon + 1;
4660+
if (periodName == "getday") dateOutput = tm->tm_mday;
4661+
if (periodName == "gethour") dateOutput = tm->tm_hour;
4662+
if (periodName == "getminute") dateOutput = tm->tm_min;
4663+
if (periodName == "getsecond") dateOutput = tm->tm_sec;
4664+
if (periodName == "getweekday") dateOutput = tm->tm_wday +1;
4665+
if (periodName == "getyearday") dateOutput = tm->tm_yday +1;
4666+
if (periodName == "gettimestamp") dateOutput = t;
4667+
4668+
Main_Data::game_variables->Set(outputVariable, dateOutput);
4669+
Game_Map::SetNeedRefresh(true);
4670+
4671+
return true;
4672+
}
4673+
46464674
Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
46474675
return Game_Battle::IsBattleRunning()
46484676
? Game_Battle::GetInterpreter()

src/game_interpreter.h

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class Game_Interpreter
284284
bool CommandManiacChangePictureId(lcf::rpg::EventCommand const& com);
285285
bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com);
286286
bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com);
287+
bool CommandGetTime(lcf::rpg::EventCommand const& com);
287288

288289
int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
289290
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);

0 commit comments

Comments
 (0)