60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "runepage.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "json.h"
|
|
|
|
RunePage::RunePage() {}
|
|
|
|
bool RunePage::operator==(const RunePage& rp) const {
|
|
if(primaryStyle == rp.primaryStyle && secondaryStyle == rp.secondaryStyle && selectedAspects.size() == rp.selectedAspects.size()) {
|
|
return std::is_permutation(selectedAspects.begin(), selectedAspects.end(), rp.selectedAspects.begin());
|
|
}
|
|
return false;
|
|
}
|
|
|
|
RunePage::operator bool() const {
|
|
return primaryStyle != 0 && secondaryStyle != 0 && selectedAspects.size() == 9;
|
|
}
|
|
|
|
RunePage::operator QJsonObject() const {
|
|
QJsonObject obj;
|
|
|
|
obj.insert("primary", (int) primaryStyle);
|
|
obj.insert("secondary", (int) secondaryStyle);
|
|
|
|
QJsonArray aspects;
|
|
for(uint32_t aspect : selectedAspects) {
|
|
aspects.push_back((int) aspect);
|
|
}
|
|
obj.insert("aspects", aspects);
|
|
|
|
return obj;
|
|
}
|
|
|
|
RunePage::RunePage(const QJsonObject& obj) :
|
|
primaryStyle(getValue(obj, "primary", 0)),
|
|
secondaryStyle(getValue(obj, "secondary", 0))
|
|
{
|
|
if(obj.contains("aspects") && obj["aspects"].isArray() && obj["aspects"].toArray().size() == 9) {
|
|
selectedAspects.clear();
|
|
selectedAspects.reserve(9);
|
|
QJsonArray arr = obj["aspects"].toArray();
|
|
for(QJsonValueRef aspect : arr) {
|
|
if(aspect.isDouble()) {
|
|
selectedAspects.push_back(aspect.toDouble());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& str, const RunePage& rp) {
|
|
return str << "Primary: " << rp.primaryStyle << " Secondary: " << rp.secondaryStyle << " aspects: " << rp.selectedAspects.size();
|
|
}
|
|
|
|
QDebug operator<<(QDebug str, const RunePage& rp) {
|
|
return str << "Primary: " << rp.primaryStyle << " Secondary: " << rp.secondaryStyle << " aspects: " << rp.selectedAspects.size();
|
|
}
|