mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-21 11:29:10 +02:00
Merge pull request #672 from ctrlaltdavid/fix/relative-json-tidy
Tidy JSON relative URLs importing code
This commit is contained in:
commit
04aabff8c7
3 changed files with 11 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,13 +240,15 @@ 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",
|
||||||
"animation.url",
|
"animation.url",
|
||||||
|
// FIXME: Handle models' "textures" and "originalTextures" properties which include URLs. Note that Particles
|
||||||
|
// also has a "textures" property.
|
||||||
// image
|
// image
|
||||||
"imageURL",
|
"imageURL",
|
||||||
// web
|
// web
|
||||||
|
@ -280,9 +282,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 +295,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