From ee8898568d21ffc44173c207399670aa109640c1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Jan 2017 14:36:01 -0800 Subject: [PATCH 1/4] Remove const from getScript & getServerScripts --- libraries/entities/src/EntityItem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index cb696dd91d..2fb91d0d77 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -254,13 +254,13 @@ public: using SpatiallyNestable::getQueryAACube; virtual AACube getQueryAACube(bool& success) const override; - const QString getScript() const { return _script; } + QString getScript() const { return _script; } void setScript(const QString& value) { _script = value; } quint64 getScriptTimestamp() const { return _scriptTimestamp; } void setScriptTimestamp(const quint64 value) { _scriptTimestamp = value; } - const QString getServerScripts() const { return _serverScripts; } + QString getServerScripts() const { return _serverScripts; } void setServerScripts(const QString& serverScripts) { _serverScripts = serverScripts; } const QString& getCollisionSoundURL() const { return _collisionSoundURL; } From 4e358f76fee0fb31c75f5ec2bf1e25cef90fae4c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Jan 2017 14:36:45 -0800 Subject: [PATCH 2/4] Remove trailing whitespace from EntityItemProperties.cpp --- .../entities/src/EntityItemProperties.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 572ca661a5..d95f162061 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -920,9 +920,9 @@ QScriptValue EntityItemProperties::entityPropertyFlagsToScriptValue(QScriptEngin static QHash _propertyStringsToEnums; void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue& object, EntityPropertyFlags& flags) { - + static std::once_flag initMap; - + std::call_once(initMap, [](){ ADD_PROPERTY_TO_MAP(PROP_VISIBLE, Visible, visible, bool); ADD_PROPERTY_TO_MAP(PROP_POSITION, Position, position, glm::vec3); @@ -1021,22 +1021,22 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_X_P_NEIGHBOR_ID, XPNeighborID, xPNeighborID, EntityItemID); ADD_PROPERTY_TO_MAP(PROP_Y_P_NEIGHBOR_ID, YPNeighborID, yPNeighborID, EntityItemID); ADD_PROPERTY_TO_MAP(PROP_Z_P_NEIGHBOR_ID, ZPNeighborID, zPNeighborID, EntityItemID); - + ADD_PROPERTY_TO_MAP(PROP_PARENT_ID, ParentID, parentID, QUuid); ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, uint16_t); - + ADD_PROPERTY_TO_MAP(PROP_LOCAL_POSITION, LocalPosition, localPosition, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_LOCAL_ROTATION, LocalRotation, localRotation, glm::quat); ADD_PROPERTY_TO_MAP(PROP_LOCAL_VELOCITY, LocalVelocity, localVelocity, glm::vec3); ADD_PROPERTY_TO_MAP(PROP_LOCAL_ANGULAR_VELOCITY, LocalAngularVelocity, localAngularVelocity, glm::vec3); - + ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS_SET, JointRotationsSet, jointRotationsSet, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_ROTATIONS, JointRotations, jointRotations, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_TRANSLATIONS_SET, JointTranslationsSet, jointTranslationsSet, QVector); ADD_PROPERTY_TO_MAP(PROP_JOINT_TRANSLATIONS, JointTranslations, jointTranslations, QVector); - + ADD_PROPERTY_TO_MAP(PROP_SHAPE, Shape, shape, QString); - + ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_URL, Animation, animation, URL, url); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_FPS, Animation, animation, FPS, fps); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_FRAME_INDEX, Animation, animation, CurrentFrame, currentFrame); @@ -1045,10 +1045,10 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_FIRST_FRAME, Animation, animation, FirstFrame, firstFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_LAST_FRAME, Animation, animation, LastFrame, lastFrame); ADD_GROUP_PROPERTY_TO_MAP(PROP_ANIMATION_HOLD, Animation, animation, Hold, hold); - + ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_COLOR, Skybox, skybox, Color, color); ADD_GROUP_PROPERTY_TO_MAP(PROP_SKYBOX_URL, Skybox, skybox, URL, url); - + ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_SUN_MODEL_ENABLED, Stage, stage, SunModelEnabled, sunModelEnabled); ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_LATITUDE, Stage, stage, Latitude, latitude); ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_LONGITUDE, Stage, stage, Longitude, longitude); @@ -1056,15 +1056,15 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_DAY, Stage, stage, Day, day); ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_HOUR, Stage, stage, Hour, hour); ADD_GROUP_PROPERTY_TO_MAP(PROP_STAGE_AUTOMATIC_HOURDAY, Stage, stage, AutomaticHourDay, automaticHourDay); - + ADD_PROPERTY_TO_MAP(PROP_FLYING_ALLOWED, FlyingAllowed, flyingAllowed, bool); ADD_PROPERTY_TO_MAP(PROP_GHOSTING_ALLOWED, GhostingAllowed, ghostingAllowed, bool); - + ADD_PROPERTY_TO_MAP(PROP_DPI, DPI, dpi, uint16_t); - + // FIXME - these are not yet handled //ADD_PROPERTY_TO_MAP(PROP_CREATED, Created, created, quint64); - + }); if (object.isString()) { @@ -1634,7 +1634,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int // NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE // when encoding/decoding edits because otherwise they can't polymorph to other shape types - if (properties.getType() == EntityTypes::Shape || + if (properties.getType() == EntityTypes::Shape || properties.getType() == EntityTypes::Box || properties.getType() == EntityTypes::Sphere) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHAPE, QString, setShape); From 888d7ab03d62cc73f7ebb849773eb7858853dc2f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Jan 2017 15:33:48 -0800 Subject: [PATCH 3/4] Add exception information to script status --- libraries/script-engine/src/ScriptEngine.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index cedf5a4ed8..2dd95aedac 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -147,19 +147,19 @@ static bool hasCorrectSyntax(const QScriptProgram& program, ScriptEngine* report return true; } -static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine) { +static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName, ScriptEngine* reportingEngine, QString& exceptionMessage = QString()) { if (engine.hasUncaughtException()) { const auto backtrace = engine.uncaughtExceptionBacktrace(); const auto exception = engine.uncaughtException().toString(); const auto line = QString::number(engine.uncaughtExceptionLineNumber()); engine.clearExceptions(); - auto message = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line); + exceptionMessage = QString(SCRIPT_EXCEPTION_FORMAT).arg(exception, fileName, line); if (!backtrace.empty()) { static const auto lineSeparator = "\n "; - message += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); + exceptionMessage += QString("\n[Backtrace]%1%2").arg(lineSeparator, backtrace.join(lineSeparator)); } - reportingEngine->scriptErrorMessage(qPrintable(message)); + reportingEngine->scriptErrorMessage(qPrintable(exceptionMessage)); return true; } return false; @@ -1472,9 +1472,11 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co }); testConstructor = sandbox.evaluate(program); } - if (hadUncaughtExceptions(sandbox, program.fileName(), this)) { + + QString exceptionMessage; + if (hadUncaughtExceptions(sandbox, program.fileName(), this, exceptionMessage)) { newDetails.status = ERROR_RUNNING_SCRIPT; - newDetails.errorInfo = "Exception"; + newDetails.errorInfo = exceptionMessage; _entityScripts[entityID] = newDetails; return; From ad70431c26056c706855ab29fb7b764866214fd1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Jan 2017 15:34:22 -0800 Subject: [PATCH 4/4] Fix edit.js server script status getting reset when changing properties --- scripts/system/edit.js | 31 ++++++++++--------- .../system/libraries/entitySelectionTool.js | 12 +++---- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 50bf22a565..29396614a6 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1443,7 +1443,6 @@ var PropertiesTool = function (opts) { }; function updateScriptStatus(info) { - print("Got status: ", info); info.type = "server_script_status"; webView.emitScriptEvent(JSON.stringify(info)); }; @@ -1457,26 +1456,28 @@ var PropertiesTool = function (opts) { }); } - selectionManager.addEventListener(function () { + selectionManager.addEventListener(function (selectionUpdated) { var data = { type: 'update' }; - resetScriptStatus(); + if (selectionUpdated) { + resetScriptStatus(); - if (selectionManager.selections.length !== 1) { - if (statusMonitor !== null) { - statusMonitor.stop(); - statusMonitor = null; + if (selectionManager.selections.length !== 1) { + if (statusMonitor !== null) { + statusMonitor.stop(); + statusMonitor = null; + } + currentSelectedEntityID = null; + } else if (currentSelectedEntityID != selectionManager.selections[0]) { + if (statusMonitor !== null) { + statusMonitor.stop(); + } + var entityID = selectionManager.selections[0]; + currentSelectedEntityID = entityID; + statusMonitor = new ServerScriptStatusMonitor(entityID, updateScriptStatus); } - currentSelectedEntityID = null; - } else if (currentSelectedEntityID != selectionManager.selections[0]) { - if (statusMonitor !== null) { - statusMonitor.stop(); - } - var entityID = selectionManager.selections[0]; - currentSelectedEntityID = entityID; - statusMonitor = new ServerScriptStatusMonitor(entityID, updateScriptStatus); } var selections = []; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index d31f4cb722..7fe29bec67 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -113,7 +113,7 @@ SelectionManager = (function() { that.selections.push(entityID); } - that._update(); + that._update(true); }; that.addEntity = function(entityID, toggleSelection) { @@ -132,7 +132,7 @@ SelectionManager = (function() { } } - that._update(); + that._update(true); }; that.removeEntity = function(entityID) { @@ -140,15 +140,15 @@ SelectionManager = (function() { if (idx >= 0) { that.selections.splice(idx, 1); } - that._update(); + that._update(true); }; that.clearSelections = function() { that.selections = []; - that._update(); + that._update(true); }; - that._update = function() { + that._update = function(selectionUpdated) { if (that.selections.length == 0) { that.localDimensions = null; that.localPosition = null; @@ -205,7 +205,7 @@ SelectionManager = (function() { for (var i = 0; i < listeners.length; i++) { try { - listeners[i](); + listeners[i](selectionUpdated === true); } catch (e) { print("EntitySelectionTool got exception: " + JSON.stringify(e)); }