3GameInfo::GameInfo() =
default;
4GameInfo::GameInfo(QString _id,
8 QVector<QString> _role_names)
10 display_name(std::move(_display_name)),
11 description(std::move(_description)),
12 players_num(_players_num),
13 role_names(std::move(_role_names)) {
15void GameInfo::read(
const QJsonObject &json) {
16 if (json.contains(ID) && json[ID].isString())
17 id = json[ID].toString();
19 if (json.contains(DISPLAY_NAME) && json[DISPLAY_NAME].isString())
20 display_name = json[DISPLAY_NAME].toString();
22 if (json.contains(DESCRIPTION) && json[DESCRIPTION].isString())
23 description = json[DESCRIPTION].toString();
25 if (json.contains(PLAYERS_NUM) && json[PLAYERS_NUM].isDouble())
26 players_num = json[PLAYERS_NUM].toInt();
28 if (json.contains(ROLE_NAMES) && json[ROLE_NAMES].isArray()) {
29 auto objects = json[ROLE_NAMES].toArray();
30 std::transform(objects.begin(), objects.end(),
31 std::back_inserter(role_names),
32 [](
const QJsonValueRef &obj) { return obj.toString(); });
35void GameInfo::write(QJsonObject &json)
const {
37 json[DISPLAY_NAME] = display_name;
38 json[DESCRIPTION] = description;
39 json[PLAYERS_NUM] = players_num;