From 2e1ebac03ffcfb7b7180330c1d51b9ecd6b226e9 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 9 Apr 2018 18:07:03 -0700 Subject: [PATCH] clean up functionality --- .../controllerModules/equipEntity.js | 4 +- .../highlightNearbyEntities.js | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 252f6efa9e..8ad5c80cb8 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -10,7 +10,7 @@ getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, makeDispatcherModuleParameters, makeRunningValues, Settings, entityHasActions, Vec3, Overlays, flatten, Xform, getControllerWorldLocation, ensureDynamic, entityIsCloneable, - cloneEntity, DISPATCHER_PROPERTIES, TEAR_AWAY_DISTANCE, Uuid + cloneEntity, DISPATCHER_PROPERTIES, TEAR_AWAY_DISTANCE, Uuid, unhighlightTargetEntity */ Script.include("/~/system/libraries/Xform.js"); @@ -483,7 +483,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.dropGestureReset(); this.clearEquipHaptics(); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - + unhighlightTargetEntity(this.targetEntityID); 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 2b9b79578f..44d48138d2 100644 --- a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js +++ b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js @@ -17,8 +17,21 @@ Script.include("/~/system/libraries/controllers.js"); Script.include("/~/system/libraries/cloneEntityUtils.js"); 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; + }); + + return differenceArray; + } + function HighlightNearbyEntities(hand) { this.hand = hand; + this.otherHand = hand === dispatcherUtils.RIGHT_HAND ? dispatcherUtils.LEFT_HAND : + dispatcherUtils.RIGHT_HAND; this.highlightedEntities = []; this.parameters = dispatcherUtils.makeDispatcherModuleParameters( @@ -44,13 +57,20 @@ return (props.href !== "" && props.href !== undefined); }; - this.highlightEntities = function(controllerData) { - if (this.highlightedEntities.length > 0) { - dispatcherUtils.clearHighlightedEntities(); - this.highlightedEntities = []; - } + this.getOtherModule = function() { + var otherModule = this.hand === dispatcherUtils.RIGHT_HAND ? leftHighlightNearbyEntities : + rightHighlightNearbyEntities; + return otherModule; + }; + this.getOtherHandHighlightedEntities = function() { + return this.getOtherModule().highlightedEntities; + }; + + this.highlightEntities = function(controllerData) { var nearbyEntitiesProperties = controllerData.nearbyEntityProperties[this.hand]; + var otherHandHighlightedEntities = this.getOtherHandHighlightedEntities(); + var newHighlightedEntities = []; var sensorScaleFactor = MyAvatar.sensorToWorldScale; for (var i = 0; i < nearbyEntitiesProperties.length; i++) { var props = nearbyEntitiesProperties[i]; @@ -59,9 +79,18 @@ } if (this.isGrabable(controllerData, props) || this.hasHyperLink(props)) { dispatcherUtils.highlightTargetEntity(props.id); - this.highlightedEntities.push(props.id); + newHighlightedEntities.push(props.id); } } + + var unhighlightEntities = differenceInArrays(this.highlightedEntities, newHighlightedEntities); + + unhighlightEntities.forEach(function(entityID) { + if (otherHandHighlightedEntities.indexOf(entityID) < 0 ) { + dispatcherUtils.unhighlightTargetEntity(entityID); + } + }); + this.highlightedEntities = newHighlightedEntities; }; this.isReady = function(controllerData) {