mirror of
https://github.com/lubosz/overte.git
synced 2025-04-14 03:06:20 +02:00
Merge pull request #6478 from samcake/controllers
Let the AssertClient JS interface use global vars
This commit is contained in:
commit
28435b6d43
3 changed files with 14 additions and 5 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QStandardPaths>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtNetwork/QNetworkDiskCache>
|
||||
|
||||
#include "AssetRequest.h"
|
||||
|
@ -374,16 +375,21 @@ void AssetScriptingInterface::uploadData(QString data, QString extension, QScrip
|
|||
return;
|
||||
}
|
||||
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [callback, extension](AssetUpload* upload, const QString& hash) mutable {
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [this, callback, extension](AssetUpload* upload, const QString& hash) mutable {
|
||||
if (callback.isFunction()) {
|
||||
QString url = "atp://" + hash + "." + extension;
|
||||
QScriptValueList args { url };
|
||||
callback.call(QScriptValue(), args);
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
}
|
||||
});
|
||||
upload->start();
|
||||
}
|
||||
|
||||
AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
|
||||
_engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
||||
const QString ATP_SCHEME { "atp://" };
|
||||
|
||||
|
@ -410,14 +416,14 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
|
|||
|
||||
_pendingRequests << assetRequest;
|
||||
|
||||
connect(assetRequest, &AssetRequest::finished, [this, callback](AssetRequest* request) mutable {
|
||||
connect(assetRequest, &AssetRequest::finished, this, [this, callback](AssetRequest* request) mutable {
|
||||
Q_ASSERT(request->getState() == AssetRequest::Finished);
|
||||
|
||||
if (request->getError() == AssetRequest::Error::NoError) {
|
||||
if (callback.isFunction()) {
|
||||
QString data = QString::fromUtf8(request->getData());
|
||||
QScriptValueList args { data };
|
||||
callback.call(QScriptValue(), args);
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,10 +74,13 @@ private:
|
|||
class AssetScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AssetScriptingInterface(QScriptEngine* engine);
|
||||
|
||||
Q_INVOKABLE void uploadData(QString data, QString extension, QScriptValue callback);
|
||||
Q_INVOKABLE void downloadData(QString url, QScriptValue downloadComplete);
|
||||
protected:
|
||||
QSet<AssetRequest*> _pendingRequests;
|
||||
QScriptEngine* _engine;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ private:
|
|||
|
||||
ArrayBufferClass* _arrayBufferClass;
|
||||
|
||||
AssetScriptingInterface _assetScriptingInterface;
|
||||
AssetScriptingInterface _assetScriptingInterface{ this };
|
||||
|
||||
QHash<EntityItemID, RegisteredEventHandlers> _registeredHandlers;
|
||||
void forwardHandlerCall(const EntityItemID& entityID, const QString& eventName, QScriptValueList eventHanderArgs);
|
||||
|
|
Loading…
Reference in a new issue