-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmumeclock.h
More file actions
171 lines (141 loc) · 4.27 KB
/
mumeclock.h
File metadata and controls
171 lines (141 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#pragma once
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2019 The MMapper Authors
// Author: Nils Schimmelmann <nschimme@gmail.com> (Jahara)
#include "../global/Signal2.h"
#include "../global/macros.h"
#include "../observer/gameobserver.h"
#include "mumemoment.h"
#include <cstdint>
#include <QList>
#include <QMetaEnum>
#include <QObject>
#include <QString>
#include <QtCore>
class GmcpMessage;
class QMetaEnum;
struct MsspTime;
enum class NODISCARD MumeClockPrecisionEnum : int8_t { UNSET = -1, DAY, HOUR, MINUTE };
#define XFOREACH_WestronMonthNamesEnum(X) \
X(Afteryule) \
X(Solmath) \
X(Rethe) \
X(Astron) \
X(Thrimidge) \
X(Forelithe) \
X(Afterlithe) \
X(Wedmath) \
X(Halimath) \
X(Winterfilth) \
X(Blotmath) \
X(Foreyule)
#define XFOREACH_SindarinMonthNamesEnum(X) \
X(Narwain) \
X(Ninui) \
X(Gwaeron) \
X(Gwirith) \
X(Lothron) \
X(Norui) \
X(Cerveth) \
X(Urui) \
X(Ivanneth) \
X(Narbeleth) \
X(Hithui) \
X(Girithron)
#define XFOREACH_WestronWeekDayNamesEnum(X) \
X(Sunday) \
X(Monday) \
X(Trewsday) \
X(Hevensday) \
X(Mersday) \
X(Highday) \
X(Sterday)
#define XFOREACH_SindarinWeekDayNamesEnum(X) \
X(Oranor) \
X(Orithil) \
X(Orgaladhad) \
X(Ormenel) \
X(Orbelain) \
X(Oraearon) \
X(Orgilion)
class NODISCARD_QOBJECT MumeClock final : public QObject
{
Q_OBJECT
private:
friend class TestClock;
private:
int64_t m_lastSyncEpoch = 0;
int64_t m_mumeStartEpoch = 0;
MumeClockPrecisionEnum m_precision = MumeClockPrecisionEnum::UNSET;
GameObserver &m_observer;
Signal2Lifetime m_lifetime;
public:
static inline constexpr const int NUM_MONTHS = 12;
struct NODISCARD DawnDusk
{
int dawnHour = 6;
int duskHour = 18;
};
NODISCARD static DawnDusk getDawnDusk(int month);
public:
explicit MumeClock(int64_t mumeEpoch, GameObserver &observer, QObject *parent);
// For use only in test cases.
explicit MumeClock(GameObserver &observer);
NODISCARD MumeMoment getMumeMoment() const;
NODISCARD MumeMoment getMumeMoment(int64_t secsSinceUnixEpoch) const;
// REVISIT: This can't be const because it logs.
NODISCARD MumeClockPrecisionEnum getPrecision();
NODISCARD QString toMumeTime(const MumeMoment &moment) const;
NODISCARD QString toCountdown(const MumeMoment &moment) const;
NODISCARD int64_t getMumeStartEpoch() const { return m_mumeStartEpoch; }
NODISCARD int64_t getLastSyncEpoch() const { return m_lastSyncEpoch; }
#define X_DECL(X) X,
enum class NODISCARD_QOBJECT WestronMonthNamesEnum : int8_t {
Invalid = -1,
XFOREACH_WestronMonthNamesEnum(X_DECL)
};
Q_ENUM(WestronMonthNamesEnum)
enum class NODISCARD_QOBJECT SindarinMonthNamesEnum : int8_t {
Invalid = -1,
XFOREACH_SindarinMonthNamesEnum(X_DECL)
};
Q_ENUM(SindarinMonthNamesEnum)
enum class NODISCARD_QOBJECT WestronWeekDayNamesEnum : int8_t {
Invalid = -1,
XFOREACH_WestronWeekDayNamesEnum(X_DECL)
};
Q_ENUM(WestronWeekDayNamesEnum)
enum class NODISCARD_QOBJECT SindarinWeekDayNamesEnum : int8_t {
Invalid = -1,
XFOREACH_SindarinWeekDayNamesEnum(X_DECL)
};
Q_ENUM(SindarinWeekDayNamesEnum)
#undef X_DECL
private:
void log(const QString &msg)
{
emit sig_log("MumeClock", msg);
}
public:
void setPrecision(MumeClockPrecisionEnum state);
void setLastSyncEpoch(int64_t epoch)
{
m_lastSyncEpoch = epoch;
}
NODISCARD static int getMumeMonth(const QString &monthName);
NODISCARD static int getMumeWeekday(const QString &weekdayName);
void parseMSSP(const MsspTime &gameTime);
protected:
void parseMumeTime(const QString &mumeTime, int64_t secsSinceEpoch);
void parseClockTime(const QString &clockTime, int64_t secsSinceEpoch);
void parseWeather(MumeTimeEnum time, int64_t secsSinceEpoch);
private:
void onUserGmcp(const GmcpMessage &msg);
MumeSeasonEnum m_lastSeasonEmitted = MumeSeasonEnum::UNKNOWN;
signals:
void sig_log(const QString &, const QString &);
void sig_seasonChanged(MumeSeasonEnum newSeason);
public slots:
void parseMumeTime(const QString &mumeTime);
void parseClockTime(const QString &clockTime);
};