mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-19 08:18:05 +02:00
Allow a script to set a resource override.
This commit is contained in:
parent
a5c19c04e5
commit
07531353e4
5 changed files with 66 additions and 5 deletions
|
@ -47,6 +47,7 @@
|
|||
#include <gl/Config.h>
|
||||
#include <gl/QOpenGLContextWrapper.h>
|
||||
|
||||
#include <ResourceScriptingInterface.h>
|
||||
#include <AccountManager.h>
|
||||
#include <AddressManager.h>
|
||||
#include <ApplicationVersion.h>
|
||||
|
@ -337,6 +338,8 @@ bool setupEssentials(int& argc, char** argv) {
|
|||
DependencyManager::set<RecordingScriptingInterface>();
|
||||
DependencyManager::set<WindowScriptingInterface>();
|
||||
DependencyManager::set<HMDScriptingInterface>();
|
||||
DependencyManager::set<ResourceScriptingInterface>();
|
||||
|
||||
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||
DependencyManager::set<SpeechRecognizer>();
|
||||
|
|
|
@ -23,16 +23,27 @@ QMutex ResourceManager::_prefixMapLock;
|
|||
|
||||
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
|
||||
QMutexLocker locker(&_prefixMapLock);
|
||||
_prefixMap[prefix] = replacement;
|
||||
if (replacement.isEmpty()) {
|
||||
_prefixMap.erase(prefix);
|
||||
} else {
|
||||
_prefixMap[prefix] = replacement;
|
||||
}
|
||||
}
|
||||
|
||||
QString ResourceManager::normalizeURL(const QString& urlString) {
|
||||
QString result = urlString;
|
||||
QMutexLocker locker(&_prefixMapLock);
|
||||
foreach(const auto& entry, _prefixMap) {
|
||||
PrefixMap copy;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&_prefixMapLock);
|
||||
copy = _prefixMap;
|
||||
}
|
||||
|
||||
foreach(const auto& entry, copy) {
|
||||
const auto& prefix = entry.first;
|
||||
const auto& replacement = entry.second;
|
||||
if (result.startsWith(prefix)) {
|
||||
qDebug() << "Replacing " << prefix << " with " << replacement;
|
||||
result.replace(0, prefix.size(), replacement);
|
||||
}
|
||||
}
|
||||
|
|
15
libraries/networking/src/ResourceScriptingInterface.cpp
Normal file
15
libraries/networking/src/ResourceScriptingInterface.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// Created by Bradley Austin Davis on 2015/12/29
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "ResourceScriptingInterface.h"
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
void ResourceScriptingInterface::overrideUrlPrefix(const QString& prefix, const QString& replacement) {
|
||||
ResourceManager::setUrlPrefixOverride(prefix, replacement);
|
||||
}
|
31
libraries/networking/src/ResourceScriptingInterface.h
Normal file
31
libraries/networking/src/ResourceScriptingInterface.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// AssetClient.h
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Ryan Huffman on 2015/07/21
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
#ifndef hifi_networking_ResourceScriptingInterface_h
|
||||
#define hifi_networking_ResourceScriptingInterface_h
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
class ResourceScriptingInterface : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE void overrideUrlPrefix(const QString& prefix, const QString& replacement);
|
||||
|
||||
Q_INVOKABLE void restoreUrlPrefix(const QString& prefix) {
|
||||
overrideUrlPrefix(prefix, "");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -26,6 +26,7 @@
|
|||
#include <EntityScriptingInterface.h>
|
||||
#include <MessagesClient.h>
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <ResourceScriptingInterface.h>
|
||||
#include <NodeList.h>
|
||||
#include <udt/PacketHeaders.h>
|
||||
#include <UUID.h>
|
||||
|
@ -391,7 +392,7 @@ void ScriptEngine::init() {
|
|||
registerGlobalObject("Recording", recordingInterface.data());
|
||||
|
||||
registerGlobalObject("Assets", &_assetScriptingInterface);
|
||||
|
||||
registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
|
||||
}
|
||||
|
||||
void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) {
|
||||
|
@ -1296,4 +1297,4 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS
|
|||
entityScript.property(methodName).call(entityScript, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue