Player12
An open source football management simulator
Loading...
Searching...
No Matches
gamedate.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10#include <cstdint>
11#include <string>
12
13#include "global/types.h"
14
20{
21 uint16_t year;
22 uint8_t month;
23 uint8_t day;
24
35 explicit GameDateValue(uint16_t y = 2025, uint8_t m = 7, uint8_t d = 1)
36 : year(y), month(m), day(d)
37 {
38 }
39
40 // ----------------------
41 // Date arithmetic
42 // ----------------------
44 void nextDay();
46 void nextWeek();
48 void nextMonth();
54 GameDateValue operator[](size_t i) const;
60 GameDateValue operator+(size_t days) const;
66 GameDateValue operator-(size_t days) const;
67
68 // ----------------------
69 // Comparisons
70 // ----------------------
76 bool operator<(const GameDateValue& other) const;
82 bool operator==(const GameDateValue& other) const;
83
84 // ----------------------
85 // String/DB conversion
86 // ----------------------
91 std::string toString() const;
97 static GameDateValue fromString(const std::string& str);
98
99 // ----------------------
100 // Game logic
101 // ----------------------
106 SeasonPhase checkPhase() const;
107
108 private:
109 static bool isLeapYear(uint16_t y);
110 static uint8_t daysInMonth(uint8_t m, uint16_t y);
111};
112
118{
119 public:
125 {
126 static GameDate _instance;
127 return _instance;
128 }
129
134 GameDateValue getCurrent() const { return current; }
140
142 void nextDay() { current.nextDay(); }
147
148 private:
149 GameDate() : current(2025, 7, 1) {}
150 GameDate(const GameDate&) = delete;
151 GameDate& operator=(const GameDate&) = delete;
152
154};
Singleton class that manages the current date in the game.
Definition gamedate.h:118
GameDate(const GameDate &)=delete
GameDate & operator=(const GameDate &)=delete
void nextMonth()
Advances the current date by one month.
Definition gamedate.h:146
static GameDate & instance()
Gets the singleton instance.
Definition gamedate.h:124
GameDateValue getCurrent() const
Gets the current date.
Definition gamedate.h:134
void nextDay()
Advances the current date by one day.
Definition gamedate.h:142
GameDateValue current
Definition gamedate.h:153
GameDate()
Definition gamedate.h:149
void setCurrent(GameDateValue d)
Sets the current date.
Definition gamedate.h:139
void nextWeek()
Advances the current date by one week.
Definition gamedate.h:144
float d
Definition match_stadium_3d.cpp:369
Represents a specific date in the game world.
Definition gamedate.h:20
uint16_t year
Definition gamedate.h:21
GameDateValue operator+(size_t days) const
Adds a specified number of days to the date.
Definition gamedate.cpp:77
void nextDay()
Advances the date by one day.
Definition gamedate.cpp:45
GameDateValue(uint16_t y=2025, uint8_t m=7, uint8_t d=1)
Constructs a GameDateValue.
Definition gamedate.h:35
GameDateValue operator[](size_t i) const
Accesses the date part by index (0=year, 1=month, 2=day).
Definition gamedate.cpp:70
bool operator==(const GameDateValue &other) const
Checks if this date is equal to another.
Definition gamedate.cpp:111
static uint8_t daysInMonth(uint8_t m, uint16_t y)
Definition gamedate.cpp:38
bool operator<(const GameDateValue &other) const
Checks if this date is earlier than another.
Definition gamedate.cpp:104
std::string toString() const
Converts the date to a string representation.
Definition gamedate.cpp:116
uint8_t day
Definition gamedate.h:23
void nextWeek()
Advances the date by one week.
Definition gamedate.cpp:55
SeasonPhase checkPhase() const
Checks the current phase of the season.
Definition gamedate.cpp:141
void nextMonth()
Advances the date by one month.
Definition gamedate.cpp:60
static bool isLeapYear(uint16_t y)
Definition gamedate.cpp:33
static GameDateValue fromString(const std::string &str)
Parses a date from a string.
Definition gamedate.cpp:121
GameDateValue operator-(size_t days) const
Subtracts a specified number of days from the date.
Definition gamedate.cpp:82
uint8_t month
Definition gamedate.h:22
SeasonPhase
Represents the different phases of a season.
Definition types.h:28