mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 15:30:11 +02:00
export atp GetMappingRequest to js
This commit is contained in:
parent
0a54241fe3
commit
3e7d303661
2 changed files with 40 additions and 2 deletions
|
@ -16,9 +16,11 @@
|
|||
#include <AssetRequest.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <MappingRequest.h>
|
||||
#include <NetworkLogging.h>
|
||||
#include <NodeList.h>
|
||||
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
|
||||
AssetScriptingInterface::AssetScriptingInterface(QScriptEngine* engine) :
|
||||
_engine(engine)
|
||||
{
|
||||
|
@ -53,10 +55,30 @@ void AssetScriptingInterface::setMapping(QString path, QString hash, QScriptValu
|
|||
setMappingRequest->start();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) {
|
||||
auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(path);
|
||||
QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable {
|
||||
auto result = request->getError();
|
||||
if (callback.isFunction()) {
|
||||
if (result == GetMappingRequest::NotFound) {
|
||||
QScriptValueList args { "" };
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
} else if (result == GetMappingRequest::NoError) {
|
||||
QScriptValueList args { request->getHash() };
|
||||
callback.call(_engine->currentContext()->thisObject(), args);
|
||||
} else {
|
||||
qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString();
|
||||
}
|
||||
request->deleteLater();
|
||||
}
|
||||
});
|
||||
request->start();
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callback) {
|
||||
|
||||
if (!urlString.startsWith(ATP_SCHEME)) {
|
||||
qCDebug(scriptengine) << "AssetScriptingInterface::downloadData url must be of form atp:<hash-value>";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,23 @@ public:
|
|||
* @param {string} error
|
||||
*/
|
||||
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
|
||||
|
||||
|
||||
/**jsdoc
|
||||
* Look up a path to hash mapping within the connected domain's asset server
|
||||
* @function Assets.getMapping
|
||||
* @static
|
||||
* @param path {string}
|
||||
* @param callback {Assets~getMappingCallback}
|
||||
*/
|
||||
|
||||
/**jsdoc
|
||||
* Called when getMapping is complete
|
||||
* @callback Assets~getMappingCallback
|
||||
* @param {string} assetID
|
||||
*/
|
||||
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);
|
||||
|
||||
|
||||
Q_INVOKABLE void setBakingEnabled(QString path, bool enabled, QScriptValue callback);
|
||||
|
||||
#if (PR_BUILD || DEV_BUILD)
|
||||
|
|
Loading…
Reference in a new issue