mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 18:03:27 +02:00
Tidy JSON relative URLs importing
This commit is contained in:
parent
f2cc30d6d9
commit
4214182b2f
3 changed files with 9 additions and 8 deletions
|
@ -867,7 +867,7 @@ bool Octree::readJSONFromStream(
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeEntitiesFileParser octreeParser;
|
OctreeEntitiesFileParser octreeParser;
|
||||||
octreeParser.relativeURL = relativeURL;
|
octreeParser.setRelativeURL(relativeURL);
|
||||||
octreeParser.setEntitiesString(jsonBuffer);
|
octreeParser.setEntitiesString(jsonBuffer);
|
||||||
|
|
||||||
QVariantMap asMap;
|
QVariantMap asMap;
|
||||||
|
|
|
@ -240,9 +240,9 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
||||||
QJsonObject entityObject = entity.object();
|
QJsonObject entityObject = entity.object();
|
||||||
|
|
||||||
// resolve urls starting with ./ or ../
|
// resolve urls starting with ./ or ../
|
||||||
if (relativeURL.isEmpty() == false) {
|
if (!_relativeURL.isEmpty()) {
|
||||||
bool isDirty = false;
|
bool isDirty = false;
|
||||||
|
|
||||||
const QStringList urlKeys {
|
const QStringList urlKeys {
|
||||||
// model
|
// model
|
||||||
"modelURL",
|
"modelURL",
|
||||||
|
@ -280,9 +280,9 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
||||||
|
|
||||||
if (childObject.contains(childKey) && childObject[childKey].isString()) {
|
if (childObject.contains(childKey) && childObject[childKey].isString()) {
|
||||||
const QString url = childObject[childKey].toString();
|
const QString url = childObject[childKey].toString();
|
||||||
|
|
||||||
if (url.startsWith("./") || url.startsWith("../")) {
|
if (url.startsWith("./") || url.startsWith("../")) {
|
||||||
childObject[childKey] = relativeURL.resolved(url).toString();
|
childObject[childKey] = _relativeURL.resolved(url).toString();
|
||||||
entityObject[entityKey] = childObject;
|
entityObject[entityKey] = childObject;
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
||||||
const QString url = entityObject[key].toString();
|
const QString url = entityObject[key].toString();
|
||||||
|
|
||||||
if (url.startsWith("./") || url.startsWith("../")) {
|
if (url.startsWith("./") || url.startsWith("../")) {
|
||||||
entityObject[key] = relativeURL.resolved(url).toString();
|
entityObject[key] = _relativeURL.resolved(url).toString();
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,15 @@
|
||||||
#define hifi_OctreeEntitiesFileParser_h
|
#define hifi_OctreeEntitiesFileParser_h
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QVariant>
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
class OctreeEntitiesFileParser {
|
class OctreeEntitiesFileParser {
|
||||||
public:
|
public:
|
||||||
void setEntitiesString(const QByteArray& entitiesContents);
|
void setEntitiesString(const QByteArray& entitiesContents);
|
||||||
|
void setRelativeURL(const QUrl& relativeURL) { _relativeURL = relativeURL; }
|
||||||
bool parseEntities(QVariantMap& parsedEntities);
|
bool parseEntities(QVariantMap& parsedEntities);
|
||||||
std::string getErrorString() const;
|
std::string getErrorString() const;
|
||||||
QUrl relativeURL;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int nextToken();
|
int nextToken();
|
||||||
|
@ -33,6 +33,7 @@ private:
|
||||||
int findMatchingBrace() const;
|
int findMatchingBrace() const;
|
||||||
|
|
||||||
QByteArray _entitiesContents;
|
QByteArray _entitiesContents;
|
||||||
|
QUrl _relativeURL;
|
||||||
int _position { 0 };
|
int _position { 0 };
|
||||||
int _line { 1 };
|
int _line { 1 };
|
||||||
int _entitiesLength { 0 };
|
int _entitiesLength { 0 };
|
||||||
|
|
Loading…
Reference in a new issue