Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
validationresult.cpp
1#include "validationresult.h"
2#include <utility>
3ValidationResult::ValidationResult() = default;
4ValidationResult::ValidationResult(bool _success, QString _message)
5 : success(_success), message(std::move(_message)) {
6}
7
8void ValidationResult::read(const QJsonObject &json) {
9 if (json.contains(SUCCESS) && json[SUCCESS].isBool()) {
10 success = json[SUCCESS].toBool();
11 }
12 if (success) {
13 message = "Now you can start the game!";
14 }
15 if (!success && json.contains(MESSAGE) && json[MESSAGE].isString()) {
16 message = json[MESSAGE].toString();
17 }
18}
19
20void ValidationResult::write(QJsonObject &json) const {
21 json[SUCCESS] = success;
22 if (!success) {
23 json[MESSAGE] = message;
24 }
25}