mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 14:24:22 +02:00
Add Script.load() JavaScript method
This commit is contained in:
parent
8be42bf305
commit
f3b4f708a5
3 changed files with 13 additions and 4 deletions
|
@ -3674,6 +3674,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
|||
|
||||
connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
|
||||
|
||||
connect(scriptEngine, SIGNAL(loadScript(const QString&)), this, SLOT(loadScript(const QString&)));
|
||||
|
||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
||||
|
||||
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
|
||||
|
|
|
@ -156,7 +156,7 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL,
|
|||
} else {
|
||||
NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url));
|
||||
qDebug() << "Downloading included script at" << url;
|
||||
qDebug() << "Downloading script at" << url;
|
||||
QEventLoop loop;
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
@ -681,12 +681,12 @@ void ScriptEngine::include(const QString& includeFile) {
|
|||
#endif
|
||||
QFile scriptFile(fileName);
|
||||
if (scriptFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qDebug() << "Loading file:" << fileName;
|
||||
qDebug() << "Including file:" << fileName;
|
||||
QTextStream in(&scriptFile);
|
||||
includeContents = in.readAll();
|
||||
} else {
|
||||
qDebug() << "ERROR Loading file:" << fileName;
|
||||
emit errorMessage("ERROR Loading file:" + fileName);
|
||||
qDebug() << "ERROR Including file:" << fileName;
|
||||
emit errorMessage("ERROR Including file:" + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,6 +699,11 @@ void ScriptEngine::include(const QString& includeFile) {
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::load(const QString& loadFile) {
|
||||
QUrl url = resolveInclude(loadFile);
|
||||
emit loadScript(url.toString());
|
||||
}
|
||||
|
||||
void ScriptEngine::nodeKilled(SharedNodePointer node) {
|
||||
_outgoingScriptAudioSequenceNumbers.remove(node->getUUID());
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ public slots:
|
|||
void clearInterval(QObject* timer) { stopTimer(reinterpret_cast<QTimer*>(timer)); }
|
||||
void clearTimeout(QObject* timer) { stopTimer(reinterpret_cast<QTimer*>(timer)); }
|
||||
void include(const QString& includeFile);
|
||||
void load(const QString& loadfile);
|
||||
void print(const QString& message);
|
||||
|
||||
void nodeKilled(SharedNodePointer node);
|
||||
|
@ -115,6 +116,7 @@ signals:
|
|||
void errorMessage(const QString& message);
|
||||
void runningStateChanged();
|
||||
void evaluationFinished(QScriptValue result, bool isException);
|
||||
void loadScript(const QString& scriptName);
|
||||
|
||||
protected:
|
||||
QString _scriptContents;
|
||||
|
|
Loading…
Reference in a new issue