mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Low level support for URL overrides when loading content
This commit is contained in:
parent
700c11563c
commit
e5fc2e5525
4 changed files with 40 additions and 5 deletions
|
@ -704,7 +704,9 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const
|
||||||
if (_tree && !_shuttingDown) {
|
if (_tree && !_shuttingDown) {
|
||||||
EntityItemPointer entity = getTree()->findEntityByEntityItemID(entityID);
|
EntityItemPointer entity = getTree()->findEntityByEntityItemID(entityID);
|
||||||
if (entity && !entity->getScript().isEmpty()) {
|
if (entity && !entity->getScript().isEmpty()) {
|
||||||
_entitiesScriptEngine->loadEntityScript(entityID, entity->getScript(), reload);
|
QString scriptUrl = entity->getScript();
|
||||||
|
scriptUrl = ResourceManager::normalizeURL(scriptUrl);
|
||||||
|
_entitiesScriptEngine->loadEntityScript(entityID, scriptUrl, reload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,37 @@
|
||||||
|
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
QUrl ResourceManager::normalizeURL(const QUrl& url) {
|
|
||||||
|
using PrefixMap = std::map<QString, QString>;
|
||||||
|
static PrefixMap PREFIX_MAP;
|
||||||
|
static QMutex PREFIX_MAP_LOCK;
|
||||||
|
|
||||||
|
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
|
||||||
|
QMutexLocker locker(&PREFIX_MAP_LOCK);
|
||||||
|
PREFIX_MAP[prefix] = replacement;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ResourceManager::normalizeURL(const QString& urlString) {
|
||||||
|
QString result = urlString;
|
||||||
|
QMutexLocker locker(&PREFIX_MAP_LOCK);
|
||||||
|
bool modified{ false };
|
||||||
|
foreach(const auto& entry, PREFIX_MAP) {
|
||||||
|
const auto& prefix = entry.first;
|
||||||
|
const auto& replacement = entry.second;
|
||||||
|
if (result.startsWith(prefix)) {
|
||||||
|
qDebug() << prefix;
|
||||||
|
result.replace(0, prefix.size(), replacement);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (modified) {
|
||||||
|
qDebug() << result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) {
|
||||||
|
QUrl url = QUrl(normalizeURL(originalUrl.toString()));
|
||||||
auto scheme = url.scheme();
|
auto scheme = url.scheme();
|
||||||
if (!(scheme == URL_SCHEME_FILE ||
|
if (!(scheme == URL_SCHEME_FILE ||
|
||||||
scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP ||
|
scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP ||
|
||||||
|
@ -37,11 +67,11 @@ ResourceRequest* ResourceManager::createResourceRequest(QObject* parent, const Q
|
||||||
auto normalizedURL = normalizeURL(url);
|
auto normalizedURL = normalizeURL(url);
|
||||||
auto scheme = normalizedURL.scheme();
|
auto scheme = normalizedURL.scheme();
|
||||||
if (scheme == URL_SCHEME_FILE) {
|
if (scheme == URL_SCHEME_FILE) {
|
||||||
return new FileResourceRequest(parent, url);
|
return new FileResourceRequest(parent, normalizedURL);
|
||||||
} else if (scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP) {
|
} else if (scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP) {
|
||||||
return new HTTPResourceRequest(parent, url);
|
return new HTTPResourceRequest(parent, normalizedURL);
|
||||||
} else if (scheme == URL_SCHEME_ATP) {
|
} else if (scheme == URL_SCHEME_ATP) {
|
||||||
return new AssetResourceRequest(parent, url);
|
return new AssetResourceRequest(parent, normalizedURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Unknown scheme (" << scheme << ") for URL: " << url.url();
|
qDebug() << "Unknown scheme (" << scheme << ") for URL: " << url.url();
|
||||||
|
|
|
@ -24,6 +24,8 @@ const QString URL_SCHEME_ATP = "atp";
|
||||||
|
|
||||||
class ResourceManager {
|
class ResourceManager {
|
||||||
public:
|
public:
|
||||||
|
static void setUrlPrefixOverride(const QString& prefix, const QString& replacement);
|
||||||
|
static QString normalizeURL(const QString& urlString);
|
||||||
static QUrl normalizeURL(const QUrl& url);
|
static QUrl normalizeURL(const QUrl& url);
|
||||||
static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url);
|
static ResourceRequest* createResourceRequest(QObject* parent, const QUrl& url);
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,6 +88,7 @@ void Procedural::parse(const QJsonObject& proceduralData) {
|
||||||
// Get the path to the shader
|
// Get the path to the shader
|
||||||
{
|
{
|
||||||
QString shaderUrl = proceduralData[URL_KEY].toString();
|
QString shaderUrl = proceduralData[URL_KEY].toString();
|
||||||
|
shaderUrl = ResourceManager::normalizeURL(shaderUrl);
|
||||||
_shaderUrl = QUrl(shaderUrl);
|
_shaderUrl = QUrl(shaderUrl);
|
||||||
if (!_shaderUrl.isValid()) {
|
if (!_shaderUrl.isValid()) {
|
||||||
qWarning() << "Invalid shader URL: " << shaderUrl;
|
qWarning() << "Invalid shader URL: " << shaderUrl;
|
||||||
|
|
Loading…
Reference in a new issue