1#include "sessioninfo.h"
3SessionInfo::SessionInfo() =
default;
4SessionInfo::SessionInfo(QString _session_id,
6 SessionInfo::Status _status,
8 QVector<Player> _players)
9 : session_id(std::move(_session_id)),
10 game_id(std::move(_game_id)),
12 host_id(std::move(_host_id)),
13 players(std::move(_players)) {
15void SessionInfo::read(
const QJsonObject &json) {
16 if (json.contains(SESSION_ID) && json[SESSION_ID].isString()) {
17 session_id = json[SESSION_ID].toString();
20 if (json.contains(GAME_ID) && json[GAME_ID].isString()) {
21 game_id = json[GAME_ID].toString();
24 if (json.contains(STATUS) && json[STATUS].isDouble()) {
25 switch (json[STATUS].toInt()) {
27 status = Status::NOT_STARTED;
30 status = Status::RUNNING;
33 status = Status::FINISHED;
38 if (json.contains(HOST_ID) && json[HOST_ID].isString()) {
39 host_id = json[HOST_ID].toString();
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());
49void SessionInfo::write(QJsonObject &json)
const {