Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
usergamestatistics.cpp
1#include "usergamestatistics.h"
2#include <utility>
3
4UserGameStatistics::UserGameStatistics() = default;
5
6UserGameStatistics::UserGameStatistics(QString _game_id,
7 int _time_played_sec,
8 int _games_played,
9 double _win_rate)
10 : game_id(std::move(_game_id)),
11 time_played_sec(_time_played_sec),
12 games_played(_games_played),
13 win_rate(_win_rate) {
14}
15
16void UserGameStatistics::read(const QJsonObject &json) {
17 if (json.contains(GAME_ID) && json[GAME_ID].isString()) {
18 game_id = json[GAME_ID].toString();
19 }
20 if (json.contains(TIME_PLAYED_SEC) && json[TIME_PLAYED_SEC].isDouble()) {
21 time_played_sec = json[TIME_PLAYED_SEC].toInt();
22 }
23 if (json.contains(GAMES_PLAYED) && json[GAMES_PLAYED].isDouble()) {
24 games_played = json[GAMES_PLAYED].toInt();
25 }
26 if (json.contains(WIN_RATE) && json[WIN_RATE].isDouble()) {
27 win_rate = json[WIN_RATE].toDouble();
28 }
29}
30
31void UserGameStatistics::write(QJsonObject &json) {
32 assert(false); // Should not be used
33}