mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Make individual reload buttons reload scripts
This commit is contained in:
parent
2a00586e21
commit
67206332e6
8 changed files with 53 additions and 30 deletions
|
@ -4062,6 +4062,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
|
||||
|
||||
connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));
|
||||
connect(scriptEngine, SIGNAL(reloadScript(const QString&, bool)), this, SLOT(reloadScript(const QString&, bool)));
|
||||
|
||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
||||
qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
|
||||
|
@ -4277,7 +4278,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
|||
}
|
||||
|
||||
ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
|
||||
bool loadScriptFromEditor, bool activateMainWindow) {
|
||||
bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
|
||||
|
||||
if (isAboutToQuit()) {
|
||||
return NULL;
|
||||
|
@ -4306,7 +4307,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
|||
connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);
|
||||
|
||||
// get the script engine object to load the script at the designated script URL
|
||||
scriptEngine->loadURL(scriptUrl);
|
||||
scriptEngine->loadURL(scriptUrl, reload);
|
||||
}
|
||||
|
||||
// restore the main window's active state
|
||||
|
@ -4317,17 +4318,8 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser
|
|||
return scriptEngine;
|
||||
}
|
||||
|
||||
void Application::reloadScript(const QString& scriptFilename) {
|
||||
DependencyManager::get<ScriptCache>()->deleteScript(scriptFilename);
|
||||
|
||||
ScriptEngine* scriptEngine = _scriptEnginesHash.value(scriptFilename);
|
||||
connect(scriptEngine, SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));
|
||||
scriptEngine->stop();
|
||||
|
||||
// HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
|
||||
// whenever a script stops in case it happened to have been setting joint rotations.
|
||||
// TODO: expose animation priorities and provide a layered animation control system.
|
||||
_myAvatar->clearScriptableSettings();
|
||||
void Application::reloadScript(const QString& scriptName, bool isUserLoaded) {
|
||||
loadScript(scriptName, isUserLoaded, false, false, true);
|
||||
}
|
||||
|
||||
void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
|
||||
|
@ -4375,7 +4367,7 @@ void Application::stopAllScripts(bool restart) {
|
|||
continue;
|
||||
}
|
||||
if (restart && it.value()->isUserLoaded()) {
|
||||
connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));
|
||||
connect(it.value(), SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
|
||||
}
|
||||
it.value()->stop();
|
||||
qCDebug(interfaceapp) << "stopping script..." << it.key();
|
||||
|
@ -4387,10 +4379,16 @@ void Application::stopAllScripts(bool restart) {
|
|||
_myAvatar->clearScriptableSettings();
|
||||
}
|
||||
|
||||
void Application::stopScript(const QString &scriptName) {
|
||||
void Application::stopScript(const QString &scriptName, bool restart) {
|
||||
const QString& scriptURLString = QUrl(scriptName).toString();
|
||||
if (_scriptEnginesHash.contains(scriptURLString)) {
|
||||
_scriptEnginesHash.value(scriptURLString)->stop();
|
||||
ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString];
|
||||
if (restart) {
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->deleteScript(scriptName);
|
||||
connect(scriptEngine, SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
|
||||
}
|
||||
scriptEngine->stop();
|
||||
qCDebug(interfaceapp) << "stopping script..." << scriptName;
|
||||
// HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
|
||||
// whenever a script stops in case it happened to have been setting joint rotations.
|
||||
|
@ -4406,6 +4404,10 @@ void Application::reloadAllScripts() {
|
|||
stopAllScripts(true);
|
||||
}
|
||||
|
||||
void Application::reloadOneScript(const QString& scriptName) {
|
||||
stopScript(scriptName, true);
|
||||
}
|
||||
|
||||
void Application::loadDefaultScripts() {
|
||||
if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {
|
||||
loadScript(DEFAULT_SCRIPTS_JS_URL);
|
||||
|
|
|
@ -398,16 +398,19 @@ public slots:
|
|||
bool acceptSnapshot(const QString& urlString);
|
||||
bool askToSetAvatarUrl(const QString& url);
|
||||
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
||||
|
||||
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
||||
bool loadScriptFromEditor = false, bool activateMainWindow = false);
|
||||
void reloadScript(const QString& scriptFilename);
|
||||
bool loadScriptFromEditor = false, bool activateMainWindow = false, bool reload = false);
|
||||
void reloadScript(const QString& scriptName, bool isUserLoaded = true);
|
||||
void scriptFinished(const QString& scriptName);
|
||||
void stopAllScripts(bool restart = false);
|
||||
void stopScript(const QString& scriptName);
|
||||
void stopScript(const QString& scriptName, bool restart = false);
|
||||
void reloadAllScripts();
|
||||
void reloadOneScript(const QString& scriptName);
|
||||
void loadDefaultScripts();
|
||||
void toggleRunningScriptsWidget();
|
||||
void saveScripts();
|
||||
|
||||
void showFriendsWindow();
|
||||
void friendsWindowClosed();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) :
|
|||
Application::getInstance(), &Application::loadDialog);
|
||||
connect(ui->loadScriptFromURLButton, &QPushButton::clicked,
|
||||
Application::getInstance(), &Application::loadScriptURLDialog);
|
||||
connect(&_reloadSignalMapper, SIGNAL(mapped(QString)), Application::getInstance(), SLOT(reloadScript(const QString&)));
|
||||
connect(&_reloadSignalMapper, SIGNAL(mapped(QString)), Application::getInstance(), SLOT(reloadOneScript(const QString&)));
|
||||
connect(&_stopSignalMapper, SIGNAL(mapped(QString)), Application::getInstance(), SLOT(stopScript(const QString&)));
|
||||
|
||||
UIUtil::scaleWidgetFontSizes(this);
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
const ScriptsModel* getScriptsModel() { return &_scriptsModel; }
|
||||
|
||||
signals:
|
||||
void stopScriptName(const QString& name);
|
||||
void stopScriptName(const QString& name, bool restart = false);
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject* sender, QEvent* event);
|
||||
|
|
|
@ -16,16 +16,20 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QObject>
|
||||
|
||||
#include <assert.h>
|
||||
#include <NetworkAccessManager.h>
|
||||
#include <SharedUtil.h>
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
#include "ScriptCache.h"
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
ScriptCache::ScriptCache(QObject* parent) {
|
||||
// nothing to do here...
|
||||
}
|
||||
|
||||
QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending) {
|
||||
QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending, bool redownload) {
|
||||
assert(!_scriptCache.contains(url) || !redownload);
|
||||
|
||||
QString scriptContents;
|
||||
if (_scriptCache.contains(url)) {
|
||||
qCDebug(scriptengine) << "Found script in cache:" << url.toString();
|
||||
|
@ -43,8 +47,13 @@ QString ScriptCache::getScript(const QUrl& url, ScriptUser* scriptUser, bool& is
|
|||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
if (redownload) {
|
||||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
|
||||
qCDebug(scriptengine) << "Redownloading script at:" << url.toString();
|
||||
} else {
|
||||
qCDebug(scriptengine) << "Downloading script at:" << url.toString();
|
||||
}
|
||||
|
||||
qCDebug(scriptengine) << "Downloading script at:" << url.toString();
|
||||
QNetworkReply* reply = networkAccessManager.get(networkRequest);
|
||||
connect(reply, &QNetworkReply::finished, this, &ScriptCache::scriptDownloaded);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ScriptCache : public QObject, public Dependency {
|
|||
SINGLETON_DEPENDENCY
|
||||
|
||||
public:
|
||||
QString getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending);
|
||||
QString getScript(const QUrl& url, ScriptUser* scriptUser, bool& isPending, bool redownload = false);
|
||||
void deleteScript(const QUrl& url);
|
||||
void addScriptToBadScriptList(const QUrl& url) { _badScripts.insert(url); }
|
||||
bool isInBadScriptList(const QUrl& url) { return _badScripts.contains(url); }
|
||||
|
|
|
@ -94,6 +94,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
|
|||
_vec3Library(),
|
||||
_uuidLibrary(),
|
||||
_isUserLoaded(false),
|
||||
_isReloading(false),
|
||||
_arrayBufferClass(new ArrayBufferClass(this))
|
||||
{
|
||||
_allScriptsMutex.lock();
|
||||
|
@ -251,12 +252,13 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents, const QStrin
|
|||
return true;
|
||||
}
|
||||
|
||||
void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
||||
void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) {
|
||||
if (_isRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fileNameString = scriptURL.toString();
|
||||
_isReloading = reload;
|
||||
|
||||
QUrl url(scriptURL);
|
||||
|
||||
|
@ -283,8 +285,7 @@ void ScriptEngine::loadURL(const QUrl& scriptURL) {
|
|||
} else {
|
||||
bool isPending;
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->getScript(url, this, isPending);
|
||||
|
||||
scriptCache->getScript(url, this, isPending, reload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -901,7 +902,13 @@ void ScriptEngine::load(const QString& loadFile) {
|
|||
}
|
||||
|
||||
QUrl url = resolvePath(loadFile);
|
||||
emit loadScript(url.toString(), false);
|
||||
if (_isReloading) {
|
||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||
scriptCache->deleteScript(url.toString());
|
||||
emit reloadScript(url.toString(), false);
|
||||
} else {
|
||||
emit loadScript(url.toString(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::nodeKilled(SharedNodePointer node) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public:
|
|||
Q_INVOKABLE void removeEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler);
|
||||
|
||||
public slots:
|
||||
void loadURL(const QUrl& scriptURL);
|
||||
void loadURL(const QUrl& scriptURL, bool reload);
|
||||
void stop();
|
||||
|
||||
QScriptValue evaluate(const QString& program, const QString& fileName = QString(), int lineNumber = 1);
|
||||
|
@ -132,6 +132,7 @@ signals:
|
|||
void runningStateChanged();
|
||||
void evaluationFinished(QScriptValue result, bool isException);
|
||||
void loadScript(const QString& scriptName, bool isUserLoaded);
|
||||
void reloadScript(const QString& scriptName, bool isUserLoaded);
|
||||
void doneRunning();
|
||||
|
||||
protected:
|
||||
|
@ -165,6 +166,7 @@ private:
|
|||
Vec3 _vec3Library;
|
||||
ScriptUUID _uuidLibrary;
|
||||
bool _isUserLoaded;
|
||||
bool _isReloading;
|
||||
|
||||
ArrayBufferClass* _arrayBufferClass;
|
||||
|
||||
|
|
Loading…
Reference in a new issue