Skip to content

Commit

Permalink
New Command: 2054 - GetTime
Browse files Browse the repository at this point in the history
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

```
  • Loading branch information
jetrotal committed Oct 25, 2023
1 parent ad6e823 commit 1daf444
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Game_Interpreter::Cmd>(2054): //Cmd::EasyRpg_GetTime
return CommandGetTime(com);
default:
return true;
}
Expand Down Expand Up @@ -4643,6 +4645,32 @@ 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]);

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;
if (periodName == "gettimestamp") dateOutput = t;

Main_Data::game_variables->Set(outputVariable, dateOutput);
Game_Map::SetNeedRefresh(true);

return true;
}

Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
return Game_Battle::IsBattleRunning()
? Game_Battle::GetInterpreter()
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t>::const_iterator& it);
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);
Expand Down

0 comments on commit 1daf444

Please sign in to comment.