finished equiping locked clone-able entities

This commit is contained in:
Dante Ruiz 2017-08-29 15:18:28 -07:00
parent 4b592687b7
commit ed52136fc5
2 changed files with 53 additions and 22 deletions

View file

@ -15,6 +15,7 @@
Script.include("/~/system/libraries/Xform.js"); Script.include("/~/system/libraries/Xform.js");
Script.include("/~/system/controllers/controllerDispatcherUtils.js"); Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js"); Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/libraries/cloneEntityUtils.js");
var DEFAULT_SPHERE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/equip-Fresnel-3.fbx"; var DEFAULT_SPHERE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/equip-Fresnel-3.fbx";
@ -321,7 +322,8 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
if (props.parentID === NULL_UUID) { if (props.parentID === NULL_UUID) {
hasParent = false; hasParent = false;
} }
if (hasParent || props.locked || entityHasActions(hotspot.entityID)) {
if (hasParent || entityHasActions(hotspot.entityID)) {
return false; return false;
} }
@ -370,6 +372,16 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
return equippableHotspots; return equippableHotspots;
}; };
this.cloneHotspot = function(props, controllerData) {
if (entityIsCloneable(props)) {
var worldEntityProps = controllerData.nearbyEntityProperties[this.hand];
var cloneID = cloneEntity(props, worldEntityProps);
return cloneID
}
return null;
};
this.chooseBestEquipHotspot = function(candidateEntityProps, controllerData) { this.chooseBestEquipHotspot = function(candidateEntityProps, controllerData) {
var equippableHotspots = this.chooseNearEquipHotspots(candidateEntityProps, controllerData); var equippableHotspots = this.chooseNearEquipHotspots(candidateEntityProps, controllerData);
if (equippableHotspots.length > 0) { if (equippableHotspots.length > 0) {
@ -434,11 +446,12 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
}; };
this.startEquipEntity = function (controllerData) { this.startEquipEntity = function (controllerData) {
print("------> starting to equip entity <-------");
this.dropGestureReset(); this.dropGestureReset();
this.clearEquipHaptics(); this.clearEquipHaptics();
Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
var grabbedProperties = Entities.getEntityProperties(this.targetEntityID);
// if an object is "equipped" and has a predefined offset, use it. // if an object is "equipped" and has a predefined offset, use it.
var offsets = getAttachPointForHotspotFromSettings(this.grabbedHotspot, this.hand); var offsets = getAttachPointForHotspotFromSettings(this.grabbedHotspot, this.hand);
if (offsets) { if (offsets) {
@ -467,7 +480,19 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
localPosition: this.offsetPosition, localPosition: this.offsetPosition,
localRotation: this.offsetRotation localRotation: this.offsetRotation
}; };
Entities.editEntity(this.targetEntityID, reparentProps); var isClone = false;
if (entityIsCloneable(grabbedProperties)) {
var cloneID = this.cloneHotspot(grabbedProperties, controllerData);
this.targetEntityID = cloneID;
Entities.editEntity(this.targetEntityID, reparentProps);
isClone = true;
} else if (!grabbedProperties.locked) {
Entities.editEntity(this.targetEntityID, reparentProps);
} else {
this.grabbedHotspot = null;
this.targetEntityID = null;
return;
}
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.targetEntityID, "startEquip", args); Entities.callEntityMethod(this.targetEntityID, "startEquip", args);
@ -477,6 +502,18 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
grabbedEntity: this.targetEntityID, grabbedEntity: this.targetEntityID,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
})); }));
var _this = this;
var grabEquipCheck = function() {
var args = [_this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(_this.targetEntityID, "startEquip", args);
};
if (isClone) {
// 100 ms seems to be sufficient time to force the check even occur after the object has been initialized.
Script.setTimeout(grabEquipCheck, 100);
}
}; };
this.endEquipEntity = function () { this.endEquipEntity = function () {
@ -523,6 +560,9 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
equipHotspotBuddy.update(deltaTime, timestamp, controllerData); equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
//if the potentialHotspot is cloneable, clone it and return it
// if the potentialHotspot os not cloneable and locked return null
if (potentialEquipHotspot) { if (potentialEquipHotspot) {
if (this.triggerSmoothedSqueezed() && !this.waitForTriggerRelease) { if (this.triggerSmoothedSqueezed() && !this.waitForTriggerRelease) {
this.grabbedHotspot = potentialEquipHotspot; this.grabbedHotspot = potentialEquipHotspot;

View file

@ -39,13 +39,9 @@ entityIsCloneable = function(props) {
} }
cloneEntity = function(cloneableProps, worldEntityProps) { cloneEntity = function(props, worldEntityProps) {
if (!cloneableProps) {
return null;
}
// we need all the properties, for this // we need all the properties, for this
cloneableProps = Entities.getEntityProperties(cloneableProps.id); var cloneableProps = Entities.getEntityProperties(props.id);
var count = 0; var count = 0;
worldEntityProps.forEach(function(itemWE) { worldEntityProps.forEach(function(itemWE) {
@ -55,7 +51,6 @@ cloneEntity = function(cloneableProps, worldEntityProps) {
}); });
var grabInfo = getGrabbableData(cloneableProps); var grabInfo = getGrabbableData(cloneableProps);
var limit = grabInfo.cloneLimit ? grabInfo.cloneLimit : 0; var limit = grabInfo.cloneLimit ? grabInfo.cloneLimit : 0;
if (count >= limit && limit !== 0) { if (count >= limit && limit !== 0) {
return null; return null;
@ -64,23 +59,19 @@ cloneEntity = function(cloneableProps, worldEntityProps) {
cloneableProps.name = cloneableProps.name + '-clone-' + cloneableProps.id; cloneableProps.name = cloneableProps.name + '-clone-' + cloneableProps.id;
var lifetime = grabInfo.cloneLifetime ? grabInfo.cloneLifetime : 300; var lifetime = grabInfo.cloneLifetime ? grabInfo.cloneLifetime : 300;
var dynamic = grabInfo.cloneDynamic ? grabInfo.cloneDynamic : false; var dynamic = grabInfo.cloneDynamic ? grabInfo.cloneDynamic : false;
var cUserData = Object.assign({}, cloneableProps.userData); var cUserData = Object.assign({}, JSON.parse(cloneableProps.userData));
var cProperties = Object.assign({}, cloneableProps); var cProperties = Object.assign({}, cloneableProps);
try {
delete cUserData.grabbableKey.cloneLifetime; delete cUserData.grabbableKey.cloneLifetime;
delete cUserData.grabbableKey.cloneable; delete cUserData.grabbableKey.cloneable;
delete cUserData.grabbableKey.cloneDynamic; delete cUserData.grabbableKey.cloneDynamic;
delete cUserData.grabbableKey.cloneLimit; delete cUserData.grabbableKey.cloneLimit;
delete cProperties.id; delete cProperties.id;
} catch(e) {
}
cProperties.dynamic = dynamic; cProperties.dynamic = dynamic;
cProperties.locked = false; cProperties.locked = false;
if (!cUserData.grabbableKey) {
cUserData.grabbableKey = {};
}
cUserData.grabbableKey.triggerable = true; cUserData.grabbableKey.triggerable = true;
cUserData.grabbableKey.grabbable = true; cUserData.grabbableKey.grabbable = true;
cProperties.lifetime = lifetime; cProperties.lifetime = lifetime;