Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
roominfo.cpp
1#include "roominfo.h"
2#include <utility>
3RoomInfo::RoomInfo() = default;
4RoomInfo::RoomInfo(QString _room_id,
5 QString _display_name,
6 QString _invite_code,
7 QString _session_id,
8 QString _host_id,
9 QVector<User> _members,
10 SessionInfo _session)
11 : room_id(std::move(_room_id)),
12 display_name(std::move(_display_name)),
13 invite_code(std::move(_invite_code)),
14 session_id(std::move(_session_id)),
15 host_id(std::move(_host_id)),
16 members(std::move(_members)),
17 session(std::move(_session)) {
18}
19void RoomInfo::read(const QJsonObject &json) {
20 if (json.contains(ROOM_ID) && json[ROOM_ID].isString()) {
21 room_id = json[ROOM_ID].toString();
22 }
23
24 if (json.contains(DISPLAY_NAME) && json[DISPLAY_NAME].isString()) {
25 display_name = json[DISPLAY_NAME].toString();
26 }
27
28 if (json.contains(INVITE_CODE) && json[INVITE_CODE].isString()) {
29 invite_code = json[INVITE_CODE].toString();
30 }
31
32 if (json.contains(SESSION_ID) && json[SESSION_ID].isString()) {
33 session_id = json[SESSION_ID].toString();
34 }
35
36 if (json.contains(HOST_ID) && json[HOST_ID].isString()) {
37 host_id = json[HOST_ID].toString();
38 }
39
40 if (json.contains(MEMBERS) && json[MEMBERS].isArray()) {
41 for (auto obj : json[MEMBERS].toArray()) {
42 members.push_back(User());
43 members.back().read(obj.toObject());
44 }
45 }
46
47 if (json.contains(SESSION) && json[SESSION].isObject()) {
48 session.read(json[SESSION].toObject());
49 isSessionAlive = true;
50 }
51}
52void RoomInfo::write(QJsonObject &json) const {
53 assert(false); // Should not be used
54}
Definition: user.h:6