Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
sessioninfo.cpp
1#include "sessioninfo.h"
2#include <utility>
3SessionInfo::SessionInfo() = default;
4SessionInfo::SessionInfo(QString _session_id,
5 QString _game_id,
6 SessionInfo::Status _status,
7 QString _host_id,
8 QVector<Player> _players)
9 : session_id(std::move(_session_id)),
10 game_id(std::move(_game_id)),
11 status(_status),
12 host_id(std::move(_host_id)),
13 players(std::move(_players)) {
14}
15void SessionInfo::read(const QJsonObject &json) {
16 if (json.contains(SESSION_ID) && json[SESSION_ID].isString()) {
17 session_id = json[SESSION_ID].toString();
18 }
19
20 if (json.contains(GAME_ID) && json[GAME_ID].isString()) {
21 game_id = json[GAME_ID].toString();
22 }
23
24 if (json.contains(STATUS) && json[STATUS].isDouble()) {
25 switch (json[STATUS].toInt()) {
26 case 0:
27 status = Status::NOT_STARTED;
28 break;
29 case 1:
30 status = Status::RUNNING;
31 break;
32 case 2:
33 status = Status::FINISHED;
34 break;
35 }
36 }
37
38 if (json.contains(HOST_ID) && json[HOST_ID].isString()) {
39 host_id = json[HOST_ID].toString();
40 }
41
42 if (json.contains(PLAYERS) && json[PLAYERS].isArray()) {
43 for (auto obj : json[PLAYERS].toArray()) {
44 players.push_back(Player());
45 players.back().read(obj.toObject());
46 }
47 }
48}
49void SessionInfo::write(QJsonObject &json) const {
50 assert(false); // Should not be used
51}
Definition: player.h:7