1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 21:43:06 +01:00

Refactor and clean up date handling (#19666)

* Refactor and clean up date handling

* Remove gDate, remove direct access to days_in_month

* Adjust the MultiLaunch test

* Bump network version

---------

Co-authored-by: ζeh Matt <5415177+ZehMatt@users.noreply.github.com>
This commit is contained in:
Michael Steenbeek
2023-04-02 10:25:41 +02:00
committed by GitHub
parent 9e4099fcdf
commit fd80b4c822
37 changed files with 241 additions and 302 deletions

View File

@@ -10,6 +10,7 @@
#include "InteractiveConsole.h"
#include "../Context.h"
#include "../Date.h"
#include "../EditorObjectSelectionSession.h"
#include "../Game.h"
#include "../OpenRCT2.h"
@@ -18,6 +19,7 @@
#include "../Version.h"
#include "../actions/CheatSetAction.h"
#include "../actions/ClimateSetAction.h"
#include "../actions/ParkSetDateAction.h"
#include "../actions/ParkSetParameterAction.h"
#include "../actions/RideFreezeRatingAction.h"
#include "../actions/RideSetPriceAction.h"
@@ -76,6 +78,7 @@
#endif
using arguments_t = std::vector<std::string>;
using OpenRCT2::Date;
static constexpr const char* ClimateNames[] = {
"cool_and_wet",
@@ -1452,7 +1455,7 @@ static int32_t ConsoleCommandForceDate([[maybe_unused]] InteractiveConsole& cons
// YYYY (no month provided, preserve existing month)
if (argv.size() == 1)
{
month = gDateMonthsElapsed % MONTH_COUNT + 1;
month = GetDate().GetMonth() + 1;
}
// YYYY MM or YYYY MM DD (month provided)
@@ -1469,21 +1472,21 @@ static int32_t ConsoleCommandForceDate([[maybe_unused]] InteractiveConsole& cons
// YYYY OR YYYY MM (no day provided, preserve existing day)
if (argv.size() <= 2)
{
day = std::clamp(
gDateMonthTicks / (TICKS_PER_MONTH / days_in_month[month - 1]) + 1, 1, static_cast<int>(days_in_month[month - 1]));
day = std::clamp(GetDate().GetDay() + 1, 1, static_cast<int>(Date::GetDaysInMonth(month - 1)));
}
// YYYY MM DD (year, month, and day provided)
if (argv.size() == 3)
{
day = atoi(argv[2].c_str());
if (day < 1 || day > days_in_month[month - 1])
if (day < 1 || day > Date::GetDaysInMonth(month - 1))
{
return -1;
}
}
DateSet(year, month, day);
auto setDateAction = ParkSetDateAction(year - 1, month - 1, day - 1);
GameActions::Execute(&setDateAction);
WindowInvalidateByClass(WindowClass::BottomToolbar);
return 1;