update version from json in toByteArray

This commit is contained in:
David Back 2018-05-31 09:24:16 -07:00
parent 6095a3b319
commit ac33f33828
3 changed files with 10 additions and 9 deletions

View file

@ -40,9 +40,10 @@ bool readOctreeFile(QString path, QJsonDocument* doc) {
}
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
if (root.contains("Id") && root.contains("DataVersion")) {
if (root.contains("Id") && root.contains("DataVersion") && root.contains("Version")) {
id = root["Id"].toVariant().toUuid();
version = root["DataVersion"].toInt();
dataVersion = root["DataVersion"].toInt();
version = root["Version"].toInt();
}
readSubclassData(root);
return true;
@ -76,11 +77,10 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
}
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
const auto protocolVersion = (int)versionForPacketType((PacketTypeEnum::Value)dataPacketType());
QJsonObject obj {
{ "DataVersion", QJsonValue((qint64)version) },
{ "DataVersion", QJsonValue((qint64)dataVersion) },
{ "Id", QJsonValue(id.toString()) },
{ "Version", protocolVersion },
{ "Version", QJsonValue((qint64)version) },
};
writeSubclassData(obj);
@ -111,8 +111,8 @@ PacketType OctreeUtils::RawOctreeData::dataPacketType() const {
void OctreeUtils::RawOctreeData::resetIdAndVersion() {
id = QUuid::createUuid();
version = OctreeUtils::INITIAL_VERSION;
qDebug() << "Reset octree data to: " << id << version;
dataVersion = OctreeUtils::INITIAL_VERSION;
qDebug() << "Reset octree data to: " << id << dataVersion;
}
void OctreeUtils::RawEntityData::readSubclassData(const QJsonObject& root) {

View file

@ -28,6 +28,7 @@ constexpr Version INITIAL_VERSION = 0;
class RawOctreeData {
public:
QUuid id { QUuid() };
Version dataVersion { -1 };
Version version { -1 };
virtual PacketType dataPacketType() const;

View file

@ -179,8 +179,8 @@ bool OctreePersistThread::process() {
OctreeUtils::RawOctreeData data;
if (data.readOctreeDataInfoFromFile(_filename)) {
qDebug() << "Setting entity version info to: " << data.id << data.version;
_tree->setOctreeVersionInfo(data.id, data.version);
qDebug() << "Setting entity version info to: " << data.id << data.dataVersion;
_tree->setOctreeVersionInfo(data.id, data.dataVersion);
}
bool persistentFileRead;