update toybox toys to use changed grab entityMethod calls

This commit is contained in:
Seth Alves 2016-02-10 18:22:20 -08:00
parent 3e71efcdbb
commit ecf22cd8b8
8 changed files with 55 additions and 111 deletions

View file

@ -334,9 +334,8 @@ function MyController(hand) {
}; };
this.callEntityMethodOnGrabbed = function(entityMethodName) { this.callEntityMethodOnGrabbed = function(entityMethodName) {
// print("Entity Method: " + entityMethodName + ", hand: " + this.hand); var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand), Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args);
JSON.stringify(MyAvatar.SessionUUID)]);
} }
this.setState = function(newState) { this.setState = function(newState) {
@ -1089,9 +1088,7 @@ function MyController(hand) {
this.continueDistanceHolding = function() { this.continueDistanceHolding = function() {
if (this.triggerSmoothedReleased()) { if (this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("releaseGrab");
}
return; return;
} }
@ -1325,9 +1322,7 @@ function MyController(hand) {
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("releaseGrab");
}
return; return;
} }
@ -1413,9 +1408,7 @@ function MyController(hand) {
this.continueNearGrabbing = function() { this.continueNearGrabbing = function() {
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
this.setState(STATE_RELEASE); this.setState(STATE_RELEASE);
if (this.isInitialGrab) { this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("releaseGrab");
}
return; return;
} }
if (this.state == STATE_CONTINUE_EQUIP_BD && this.bumperReleased()) { if (this.state == STATE_CONTINUE_EQUIP_BD && this.bumperReleased()) {
@ -1429,9 +1422,7 @@ function MyController(hand) {
} }
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) {
this.setState(STATE_CONTINUE_EQUIP_BD); this.setState(STATE_CONTINUE_EQUIP_BD);
if (this.isInitialGrab) { this.callEntityMethodOnGrabbed("releaseGrab");
this.callEntityMethodOnGrabbed("releaseGrab");
}
this.callEntityMethodOnGrabbed("startEquip"); this.callEntityMethodOnGrabbed("startEquip");
return; return;
} }
@ -1467,10 +1458,8 @@ function MyController(hand) {
if (this.state === STATE_CONTINUE_EQUIP) { if (this.state === STATE_CONTINUE_EQUIP) {
this.callEntityMethodOnGrabbed("continueEquip"); this.callEntityMethodOnGrabbed("continueEquip");
} }
if (this.isInitialGrab) { if (this.state == STATE_CONTINUE_NEAR_GRABBING) {
if (this.state == STATE_CONTINUE_NEAR_GRABBING) { this.callEntityMethodOnGrabbed("continueNearGrab");
this.callEntityMethodOnGrabbed("continueNearGrab");
}
} }
if (this.actionID && this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { if (this.actionID && this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) {
@ -1654,19 +1643,11 @@ function MyController(hand) {
this.actionID = null; this.actionID = null;
this.setState(STATE_OFF); this.setState(STATE_OFF);
if (this.isInitialGrab) { Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ action: 'release',
action: 'release', grabbedEntity: this.grabbedEntity,
grabbedEntity: this.grabbedEntity, joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" }));
}));
} else {
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'shared-release',
grabbedEntity: this.grabbedEntity,
joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"
}));
}
this.grabbedEntity = null; this.grabbedEntity = null;
}; };

View file

@ -125,13 +125,13 @@
Entities.deleteEntity(this.arrow); Entities.deleteEntity(this.arrow);
}, },
startEquip: function(hand, avatarID) { startEquip: function(entityID, args) {
this.hand = hand; this.hand = args[0];
avatarID = args[1];
print('START BOW GRAB')
//disable the opposite hand in handControllerGrab.js by message //disable the opposite hand in handControllerGrab.js by message
var handToDisable = this.hand === 'right' ? 'left' : 'right'; var handToDisable = this.hand === 'right' ? 'left' : 'right';
print("disabling hand: " + handToDisable);
Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); Messages.sendMessage('Hifi-Hand-Disabler', handToDisable);
var data = getEntityCustomData('grabbableKey', this.entityID, {}); var data = getEntityCustomData('grabbableKey', this.entityID, {});
@ -139,7 +139,7 @@
setEntityCustomData('grabbableKey', this.entityID, data); setEntityCustomData('grabbableKey', this.entityID, data);
}, },
continueEquip: function(hand, avatarID) { continueEquip: function(entityID, args) {
this.deltaTime = checkInterval(); this.deltaTime = checkInterval();
//debounce during debugging -- maybe we're updating too fast? //debounce during debugging -- maybe we're updating too fast?
@ -168,7 +168,7 @@
this.checkStringHand(); this.checkStringHand();
}, },
releaseEquip: function(hand, avatarID) { releaseEquip: function(entityID, args) {
// print('RELEASE GRAB EVENT') // print('RELEASE GRAB EVENT')
Messages.sendMessage('Hifi-Hand-Disabler', "none") Messages.sendMessage('Hifi-Hand-Disabler', "none")

View file

@ -119,7 +119,8 @@
//wait to make the bubbles collidable, so that they dont hit each other and the wand //wait to make the bubbles collidable, so that they dont hit each other and the wand
Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2); Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2);
//release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble //release the bubble -- when we create a new bubble, it will carry on and this update loop will
// affect the new bubble
this.createBubbleAtTipOfWand(); this.createBubbleAtTipOfWand();
return; return;
} else { } else {

View file

@ -24,15 +24,11 @@
Doll.prototype = { Doll.prototype = {
audioInjector: null, audioInjector: null,
isGrabbed: false, isGrabbed: false,
setLeftHand: function() {
this.hand = 'left';
},
setRightHand: function() { startNearGrab: function(entityID, args) {
this.hand = 'right'; this.hand = args[0];
}, avatarID = args[1];
startNearGrab: function() {
Entities.editEntity(this.entityID, { Entities.editEntity(this.entityID, {
animation: { animation: {
url: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", url: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx",
@ -53,18 +49,18 @@
this.startNearGrab(id, params); this.startNearGrab(id, params);
}, },
continueNearGrab: function() { continueNearGrab: function(entityID, args) {
var props = Entities.getEntityProperties(this.entityID, ["position"]); var props = Entities.getEntityProperties(this.entityID, ["position"]);
var audioOptions = { var audioOptions = {
position: props.position position: props.position
}; };
this.audioInjector.options = audioOptions; this.audioInjector.options = audioOptions;
}, },
continueEquip: function() { continueEquip: function(entityID, args) {
this.continueNearGrab(); this.continueNearGrab(entityID, args);
}, },
releaseGrab: function() { releaseGrab: function(entityID, args) {
if (this.isGrabbed === true && this.hand === this.initialHand) { if (this.isGrabbed === true && this.hand === this.initialHand) {
this.audioInjector.stop(); this.audioInjector.stop();
Entities.editEntity(this.entityID, { Entities.editEntity(this.entityID, {
@ -79,8 +75,8 @@
this.isGrabbed = false; this.isGrabbed = false;
} }
}, },
releaseEquip: function() { releaseEquip: function(entityID, args) {
this.releaseGrab(); this.releaseGrab(entityID, args);
}, },
preload: function(entityID) { preload: function(entityID) {

View file

@ -77,15 +77,10 @@
whichHand: null, whichHand: null,
hasSpotlight: false, hasSpotlight: false,
spotlight: null, spotlight: null,
setRightHand: function() {
this.hand = 'RIGHT';
},
setLeftHand: function() { startNearGrab: function(entityID, args) {
this.hand = 'LEFT'; this.hand = args[0];
},
startNearGrab: function(entityID) {
print("FLASHLIGHT startNearGrab"); print("FLASHLIGHT startNearGrab");
if (!this.hasSpotlight) { if (!this.hasSpotlight) {
@ -161,11 +156,11 @@
this.changeLightWithTriggerPressure(this.whichHand); this.changeLightWithTriggerPressure(this.whichHand);
} }
}, },
continueEquip: function() { continueEquip: function(entityID, args) {
this.continueNearGrab(); this.continueNearGrab(entityID, args);
}, },
releaseGrab: function() { releaseGrab: function(entityID, args) {
//delete the lights and reset state //delete the lights and reset state
if (this.hasSpotlight) { if (this.hasSpotlight) {
Entities.deleteEntity(this.spotlight); Entities.deleteEntity(this.spotlight);
@ -177,8 +172,8 @@
this.lightOn = false; this.lightOn = false;
} }
}, },
releaseEquip: function() { releaseEquip: function(entityID, args) {
this.releaseGrab(); this.releaseGrab(entityID, args);
}, },
changeLightWithTriggerPressure: function(flashLightHand) { changeLightWithTriggerPressure: function(flashLightHand) {

View file

@ -54,47 +54,26 @@
PingPongGun.prototype = { PingPongGun.prototype = {
hand: null, hand: null,
whichHand: null,
gunTipPosition: null, gunTipPosition: null,
canShoot: false, canShoot: false,
canShootTimeout: null, canShootTimeout: null,
setRightHand: function() {
this.hand = 1; startEquip: function(entityID, args) {
this.hand = args[0] == "left" ? 0 : 1;
}, },
setLeftHand: function() { continueEquip: function(entityID, args) {
this.hand = 0; if (this.canShootTimeout !== null) {
}, Script.clearTimeout(this.canShootTimeout);
startEquip: function() {
this.setWhichHand();
},
setWhichHand: function() {
this.whichHand = this.hand;
},
continueEquip: function() {
if (this.whichHand === null) {
//only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten
this.setWhichHand();
} else {
if (this.canShootTimeout !== null) {
Script.clearTimeout(this.canShootTimeout);
}
this.checkTriggerPressure(this.whichHand);
} }
this.checkTriggerPressure(this.hand);
}, },
releaseEquip: function() { releaseEquip: function(entityID, args) {
var _this = this; var _this = this;
this.canShootTimeout = Script.setTimeout(function() {
if (this.whichHand === this.hand) { _this.canShoot = false;
this.whichHand = null; }, 250);
this.canShootTimeout = Script.setTimeout(function() {
_this.canShoot = false;
}, 250);
}
}, },
checkTriggerPressure: function(gunHand) { checkTriggerPressure: function(gunHand) {
@ -102,7 +81,7 @@
if (this.triggerValue < RELOAD_THRESHOLD) { if (this.triggerValue < RELOAD_THRESHOLD) {
// print('RELOAD'); // print('RELOAD');
this.canShoot = true; this.canShoot = true;
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true && this.hand === this.whichHand) { } else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) {
var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
this.shootBall(gunProperties); this.shootBall(gunProperties);
this.canShoot = false; this.canShoot = false;

View file

@ -49,10 +49,10 @@
startEquip: function(id, params) { startEquip: function(id, params) {
this.equipped = true; this.equipped = true;
this.hand = JSON.parse(params[0]); this.hand = params[0] == "left" ? 0 : 1;
}, },
continueEquip: function() { continueEquip: function(id, params) {
if (!this.equipped) { if (!this.equipped) {
return; return;
} }
@ -111,7 +111,7 @@
}); });
}, },
unequip: function() { releaseEquip: function(id, params) {
this.hand = null; this.hand = null;
this.equipped = false; this.equipped = false;
Overlays.editOverlay(this.laser, { Overlays.editOverlay(this.laser, {

View file

@ -38,20 +38,12 @@
Controller.Standard.RT, Controller.Standard.RT,
]; ];
this.setRightHand = function () { this.startNearGrab = function (entityID, args) {
this.hand = 1; this.hand = args[0] == "left" ? 0 : 1;
}
this.setLeftHand = function () {
this.hand = 0;
}
this.startNearGrab = function () {
this.whichHand = this.hand;
} }
this.toggleWithTriggerPressure = function () { this.toggleWithTriggerPressure = function () {
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.whichHand]); this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]);
if (this.triggerValue < DISABLE_SPRAY_THRESHOLD && this.spraying === true) { if (this.triggerValue < DISABLE_SPRAY_THRESHOLD && this.spraying === true) {
this.spraying = false; this.spraying = false;
this.disableStream(); this.disableStream();