-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HistoryItem.cpp
119 lines (92 loc) · 3.37 KB
/
HistoryItem.cpp
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
/*
* QtSssSNibblers: SwissalpS Nibbles written with Qt-Framework
* Copyright (C) 2018-2019 Luke J. Zimmermann aka SwissalpS <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HistoryItem.h"
#include <QDateTime>
namespace SwissalpS { namespace QtNibblers {
HistoryItem::HistoryItem(QObject *pParent) :
QObject(pParent),
bFakes(false),
sName("Null"),
ubCountAI(0xFFu),
ubCountHuman(0xFFu),
ubLevelsDone(0xFFu),
ubLevelStart(0xFFu),
ubLivesLost(0xFFu),
ubSpeedIndex(0xFFu),
ulScore(0xFFFFFFFFu),
illTimeStamp(0xFFFFFFFFFFFFFFFF) {
} // construct
HistoryItem::HistoryItem(const QJsonObject oJSON, QObject *pParent) :
QObject(pParent),
bFakes(false),
sName(""),
ubCountAI(0u),
ubCountHuman(0u),
ubLevelsDone(0u),
ubLevelStart(0u),
ubLivesLost(0u),
ubSpeedIndex(0u),
ulScore(0u),
illTimeStamp(0) {
this->bFakes = oJSON.value(sTagFakes).toBool();
this->sName = oJSON.value(sTagName).toString();
this->ubCountAI = quint8(oJSON.value(sTagCountAI).toInt());
this->ubCountHuman = quint8(oJSON.value(sTagCountHuman).toInt());
this->ubLevelsDone = quint8(oJSON.value(sTagLevelsDone).toInt());
this->ubLevelStart = quint8(oJSON.value(sTagLevelStart).toInt());
this->ubLivesLost = quint8(oJSON.value(sTagLivesLost).toInt());
this->ubSpeedIndex = quint8(oJSON.value(sTagSpeedIndex).toInt());
this->ulScore = quint32(oJSON.value(sTagScore).toInt());
this->illTimeStamp = qint64(oJSON.value(sTagTimeStamp).toDouble());
} // construct
HistoryItem::HistoryItem(const bool bFakes, const QString sName,
const quint8 ubCountAI, const quint8 ubCountHuman,
const quint8 ubLevelsDone, const quint8 ubLevelStart,
const quint8 ubLivesLost, const quint8 ubSpeedIndex,
const quint32 ulScore, const qint64 illTimeStamp,
QObject *pParent) :
QObject(pParent),
bFakes(bFakes),
sName(sName),
ubCountAI(ubCountAI),
ubCountHuman(ubCountHuman),
ubLevelsDone(ubLevelsDone),
ubLevelStart(ubLevelStart),
ubLivesLost(ubLivesLost),
ubSpeedIndex(ubSpeedIndex),
ulScore(ulScore),
illTimeStamp(illTimeStamp) {
if (0 == illTimeStamp) this->illTimeStamp = QDateTime::currentSecsSinceEpoch();
} // construct
HistoryItem::~HistoryItem() {
} // dealloc
QJsonObject HistoryItem::toJSON() const {
QJsonObject oOut;
oOut.insert(sTagCountAI, this->ubCountAI);
oOut.insert(sTagCountHuman, this->ubCountHuman);
oOut.insert(sTagFakes, this->bFakes);
oOut.insert(sTagLevelsDone, this->ubLevelsDone);
oOut.insert(sTagLevelStart, this->ubLevelStart);
oOut.insert(sTagLivesLost, this->ubLivesLost);
oOut.insert(sTagName, this->sName);
oOut.insert(sTagScore, qint32(this->ulScore));
oOut.insert(sTagSpeedIndex, this->ubSpeedIndex);
oOut.insert(sTagTimeStamp, qint64(this->illTimeStamp));
return oOut;
} // toJSON
} } // namespace SwissalpS::QtNibblers