mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-21 01:40:17 +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;
|
||||
octreeParser.relativeURL = relativeURL;
|
||||
octreeParser.setRelativeURL(relativeURL);
|
||||
octreeParser.setEntitiesString(jsonBuffer);
|
||||
|
||||
QVariantMap asMap;
|
||||
|
|
|
@ -240,13 +240,15 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
|||
QJsonObject entityObject = entity.object();
|
||||
|
||||
// resolve urls starting with ./ or ../
|
||||
if (relativeURL.isEmpty() == false) {
|
||||
if (!_relativeURL.isEmpty()) {
|
||||
bool isDirty = false;
|
||||
|
||||
const QStringList urlKeys {
|
||||
// model
|
||||
"modelURL",
|
||||
"animation.url",
|
||||
// FIXME: Handle models' "textures" and "originalTextures" properties which include URLs. Note that Particles
|
||||
// also has a "textures" property.
|
||||
// image
|
||||
"imageURL",
|
||||
// web
|
||||
|
@ -282,7 +284,7 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
|||
const QString url = childObject[childKey].toString();
|
||||
|
||||
if (url.startsWith("./") || url.startsWith("../")) {
|
||||
childObject[childKey] = relativeURL.resolved(url).toString();
|
||||
childObject[childKey] = _relativeURL.resolved(url).toString();
|
||||
entityObject[entityKey] = childObject;
|
||||
isDirty = true;
|
||||
}
|
||||
|
@ -293,7 +295,7 @@ bool OctreeEntitiesFileParser::readEntitiesArray(QVariantList& entitiesArray) {
|
|||
const QString url = entityObject[key].toString();
|
||||
|
||||
if (url.startsWith("./") || url.startsWith("../")) {
|
||||
entityObject[key] = relativeURL.resolved(url).toString();
|
||||
entityObject[key] = _relativeURL.resolved(url).toString();
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
#define hifi_OctreeEntitiesFileParser_h
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
|
||||
class OctreeEntitiesFileParser {
|
||||
public:
|
||||
void setEntitiesString(const QByteArray& entitiesContents);
|
||||
void setRelativeURL(const QUrl& relativeURL) { _relativeURL = relativeURL; }
|
||||
bool parseEntities(QVariantMap& parsedEntities);
|
||||
std::string getErrorString() const;
|
||||
QUrl relativeURL;
|
||||
|
||||
private:
|
||||
int nextToken();
|
||||
|
@ -33,6 +33,7 @@ private:
|
|||
int findMatchingBrace() const;
|
||||
|
||||
QByteArray _entitiesContents;
|
||||
QUrl _relativeURL;
|
||||
int _position { 0 };
|
||||
int _line { 1 };
|
||||
int _entitiesLength { 0 };
|
||||
|
|
Loading…
Reference in a new issue