From 7ba42f0e76ec8269b5b6cd7a35deb625c09a870b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 11 Jan 2018 15:52:56 +1300 Subject: [PATCH 1/4] Update JSDoc per recent changes in Window API --- interface/src/scripting/WindowScriptingInterface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index af9c03a218..6d7a10c580 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -42,7 +42,7 @@ void CustomPromptResultFromScriptValue(const QScriptValue& object, CustomPromptR * @property {number} innerWidth - The width of the drawable area of the Interface window (i.e., without borders or other * chrome), in pixels. Read-only. * @property {number} innerHeight - The height of the drawable area of the Interface window (i.e., without borders or other - * chrome) plus the height of the menu bar, in pixels. Read-only. + * chrome), in pixels. Read-only. * @property {object} location - Provides facilities for working with your current metaverse location. See {@link location}. * @property {number} x - The x coordinate of the top left corner of the Interface window on the display. Read-only. * @property {number} y - The y coordinate of the top left corner of the Interface window on the display. Read-only. @@ -555,7 +555,7 @@ signals: /**jsdoc * Triggered when a still snapshot has been taken by calling {@link Window.takeSnapshot|takeSnapshot} with - * includeAnimated = false. + * includeAnimated = false or {@link Window.takeSecondaryCameraSnapshot|takeSecondaryCameraSnapshot}. * @function Window.stillSnapshotTaken * @param {string} pathStillSnapshot - The path and name of the snapshot image file. * @param {boolean} notify - The value of the notify parameter that {@link Window.takeSnapshot|takeSnapshot} From a543d90090968a0457d7b9e65eaf21ad69fb92d3 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 11 Jan 2018 15:53:45 +1300 Subject: [PATCH 2/4] Miscellaneous fixes --- interface/src/scripting/WindowScriptingInterface.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 6d7a10c580..bfad5644bf 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -301,7 +301,7 @@ public slots: /**jsdoc * Get Interface's build number. * @function Window.checkVersion - * @returns {string} - Interface's build number. + * @returns {string} Interface's build number. */ QString checkVersion(); @@ -327,7 +327,7 @@ public slots: * full resolution is used (window dimensions in desktop mode; HMD display dimensions in HMD mode), otherwise one of the * dimensions is adjusted in order to match the aspect ratio. * @example Using the snapshot function and signals. - * function onStillSnapshottaken(path, notify) { + * function onStillSnapshotTaken(path, notify) { * print("Still snapshot taken: " + path); * print("Notify: " + notify); * } @@ -340,7 +340,7 @@ public slots: * print("Animated snapshot taken: " + animatedPath); * } * - * Window.stillSnapshotTaken.connect(onStillSnapshottaken); + * Window.stillSnapshotTaken.connect(onStillSnapshotTaken); * Window.processingGifStarted.connect(onProcessingGifStarted); * Window.processingGifCompleted.connect(onProcessingGifCompleted); * From 3e7d30366125d8ec004ac57c400680c7ca65b2b9 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 15 Jan 2018 09:18:22 -0800 Subject: [PATCH 3/4] export atp GetMappingRequest to js --- .../src/AssetScriptingInterface.cpp | 24 ++++++++++++++++++- .../src/AssetScriptingInterface.h | 18 +++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/AssetScriptingInterface.cpp b/libraries/script-engine/src/AssetScriptingInterface.cpp index 25e8c0dcf3..1c5a7ff7ba 100644 --- a/libraries/script-engine/src/AssetScriptingInterface.cpp +++ b/libraries/script-engine/src/AssetScriptingInterface.cpp @@ -16,9 +16,11 @@ #include #include #include -#include #include +#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()->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:"; return; } diff --git a/libraries/script-engine/src/AssetScriptingInterface.h b/libraries/script-engine/src/AssetScriptingInterface.h index 2812be65f9..0964a4f5e2 100644 --- a/libraries/script-engine/src/AssetScriptingInterface.h +++ b/libraries/script-engine/src/AssetScriptingInterface.h @@ -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) From 76048f3c308d7ca39712c18093c39a16e6eecdc2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 15 Jan 2018 10:48:12 -0800 Subject: [PATCH 4/4] error handling --- libraries/script-engine/src/AssetScriptingInterface.cpp | 6 ++++-- libraries/script-engine/src/AssetScriptingInterface.h | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/script-engine/src/AssetScriptingInterface.cpp b/libraries/script-engine/src/AssetScriptingInterface.cpp index 1c5a7ff7ba..e0e04a1e25 100644 --- a/libraries/script-engine/src/AssetScriptingInterface.cpp +++ b/libraries/script-engine/src/AssetScriptingInterface.cpp @@ -61,13 +61,15 @@ void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) { auto result = request->getError(); if (callback.isFunction()) { if (result == GetMappingRequest::NotFound) { - QScriptValueList args { "" }; + QScriptValueList args { "", true }; callback.call(_engine->currentContext()->thisObject(), args); } else if (result == GetMappingRequest::NoError) { - QScriptValueList args { request->getHash() }; + QScriptValueList args { request->getHash(), true }; callback.call(_engine->currentContext()->thisObject(), args); } else { qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString(); + QScriptValueList args { "", false }; + callback.call(_engine->currentContext()->thisObject(), args); } request->deleteLater(); } diff --git a/libraries/script-engine/src/AssetScriptingInterface.h b/libraries/script-engine/src/AssetScriptingInterface.h index 0964a4f5e2..dded2ef21d 100644 --- a/libraries/script-engine/src/AssetScriptingInterface.h +++ b/libraries/script-engine/src/AssetScriptingInterface.h @@ -85,9 +85,10 @@ public: */ /**jsdoc - * Called when getMapping is complete + * Called when getMapping is complete. * @callback Assets~getMappingCallback - * @param {string} assetID + * @param assetID {string} hash value if found, else an empty string + * @param success {boolean} false for errors other than "not found", else true */ Q_INVOKABLE void getMapping(QString path, QScriptValue callback);