From 447163bd07e40b62bd832ac7271bd71a5e1b8285 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 10 Apr 2018 09:23:40 -0700 Subject: [PATCH] clean up scripts --- .../controllerModules/equipEntity.js | 6 ++++ .../highlightNearbyEntities.js | 33 ++++++++++++++++--- .../controllerModules/nearActionGrabEntity.js | 6 ++++ .../controllerModules/nearParentGrabEntity.js | 6 ++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 8ad5c80cb8..09d64b5d05 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -484,6 +484,12 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.clearEquipHaptics(); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); unhighlightTargetEntity(this.targetEntityID); + var message = { + hand: this.hand, + entityID: this.targetEntityID + }; + + Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var grabbedProperties = Entities.getEntityProperties(this.targetEntityID); // if an object is "equipped" and has a predefined offset, use it. diff --git a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js index 44d48138d2..a102a5d735 100644 --- a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js +++ b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js @@ -9,7 +9,7 @@ /* global Script, Controller, RIGHT_HAND, LEFT_HAND, MyAvatar, getGrabPointSphereOffset, makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters, PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, - DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams, entityIsCloneable + DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams, entityIsCloneable, Messages, print */ (function () { @@ -19,8 +19,6 @@ var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); function differenceInArrays(firstArray, secondArray) { - print("first " + firstArray); - print("second " + secondArray); var differenceArray = firstArray.filter(function(element) { return secondArray.indexOf(element) < 0; }); @@ -57,6 +55,13 @@ return (props.href !== "" && props.href !== undefined); }; + this.removeEntityFromHighlightList = function(entityID) { + var index = this.highlightedEntities.indexOf(entityID); + if (index > -1) { + this.highlightedEntities.splice(index, 1); + } + }; + this.getOtherModule = function() { var otherModule = this.hand === dispatcherUtils.RIGHT_HAND ? leftHighlightNearbyEntities : rightHighlightNearbyEntities; @@ -103,6 +108,25 @@ }; } + var handleMessage = function(channel, message, sender) { + var data; + if (sender === MyAvatar.sessionUUID) { + if (channel === 'Hifi-unhighlight-entity') { + try { + data = JSON.parse(message); + + var hand = data.hand; + if (hand === dispatcherUtils.LEFT_HAND) { + leftHighlightNearbyEntities.removeEntityFromHighlightList(data.entityID); + } else if (hand === dispatcherUtils.RIGHT_HAND) { + rightHighlightNearbyEntities.removeEntityFromHighlightList(data.entityID); + } + } catch (e) { + print("Failed to parse message"); + } + } + } + }; var leftHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.LEFT_HAND); var rightHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.RIGHT_HAND); @@ -113,6 +137,7 @@ dispatcherUtils.disableDispatcherModule("LeftHighlightNearbyEntities"); dispatcherUtils.disableDispatcherModule("RightHighlightNearbyEntities"); } - + Messages.subscribe('Hifi-unhighlight-entity'); + Messages.messageReceived.connect(handleMessage); Script.scriptEnding.connect(cleanup); }()); diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index da9cafbe07..a1e4cff40d 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -115,6 +115,12 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.targetEntityID, "startNearGrab", args); unhighlightTargetEntity(this.targetEntityID); + var message = { + hand: this.hand, + entityID: this.targetEntityID + }; + + Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); }; // this is for when the action is going to time-out diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index 945c091f7e..55dde21f46 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -90,6 +90,12 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.startNearParentingGrabEntity = function (controllerData, targetProps) { Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); unhighlightTargetEntity(this.targetEntityID); + var message = { + hand: this.hand, + entityID: this.targetEntityID + }; + + Messages.sendMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var handJointIndex; // if (this.ignoreIK) { // handJointIndex = this.controllerJointIndex;