From ecf22cd8b8835b71e0915d9ddac084c301d7d6c0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 18:22:20 -0800 Subject: [PATCH] update toybox toys to use changed grab entityMethod calls --- examples/controllers/handControllerGrab.js | 45 ++++++-------------- examples/toybox/bow/bow.js | 12 +++--- examples/toybox/bubblewand/wand.js | 3 +- examples/toybox/doll/doll.js | 22 ++++------ examples/toybox/flashlight/flashlight.js | 19 +++------ examples/toybox/ping_pong_gun/pingPongGun.js | 45 ++++++-------------- examples/toybox/pistol/pistol.js | 6 +-- examples/toybox/spray_paint/sprayPaintCan.js | 14 ++---- 8 files changed, 55 insertions(+), 111 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index cc486802ff..e2f88ccb3b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -334,9 +334,8 @@ function MyController(hand) { }; this.callEntityMethodOnGrabbed = function(entityMethodName) { - // print("Entity Method: " + entityMethodName + ", hand: " + this.hand); - Entities.callEntityMethod(this.grabbedEntity, entityMethodName, [JSON.stringify(this.hand), - JSON.stringify(MyAvatar.SessionUUID)]); + var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; + Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); } this.setState = function(newState) { @@ -1089,9 +1088,7 @@ function MyController(hand) { this.continueDistanceHolding = function() { if (this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } @@ -1325,9 +1322,7 @@ function MyController(hand) { if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } @@ -1413,9 +1408,7 @@ function MyController(hand) { this.continueNearGrabbing = function() { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); return; } 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()) { this.setState(STATE_CONTINUE_EQUIP_BD); - if (this.isInitialGrab) { - this.callEntityMethodOnGrabbed("releaseGrab"); - } + this.callEntityMethodOnGrabbed("releaseGrab"); this.callEntityMethodOnGrabbed("startEquip"); return; } @@ -1467,10 +1458,8 @@ function MyController(hand) { if (this.state === STATE_CONTINUE_EQUIP) { this.callEntityMethodOnGrabbed("continueEquip"); } - if (this.isInitialGrab) { - if (this.state == STATE_CONTINUE_NEAR_GRABBING) { - this.callEntityMethodOnGrabbed("continueNearGrab"); - } + if (this.state == STATE_CONTINUE_NEAR_GRABBING) { + this.callEntityMethodOnGrabbed("continueNearGrab"); } if (this.actionID && this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { @@ -1654,19 +1643,11 @@ function MyController(hand) { this.actionID = null; this.setState(STATE_OFF); - if (this.isInitialGrab) { - Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ - action: 'release', - grabbedEntity: this.grabbedEntity, - 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" - })); - } + Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ + action: 'release', + grabbedEntity: this.grabbedEntity, + joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" + })); this.grabbedEntity = null; }; diff --git a/examples/toybox/bow/bow.js b/examples/toybox/bow/bow.js index cd52a8ed5b..c947b59518 100644 --- a/examples/toybox/bow/bow.js +++ b/examples/toybox/bow/bow.js @@ -125,13 +125,13 @@ Entities.deleteEntity(this.arrow); }, - startEquip: function(hand, avatarID) { - this.hand = hand; - - print('START BOW GRAB') + startEquip: function(entityID, args) { + this.hand = args[0]; + avatarID = args[1]; //disable the opposite hand in handControllerGrab.js by message var handToDisable = this.hand === 'right' ? 'left' : 'right'; + print("disabling hand: " + handToDisable); Messages.sendMessage('Hifi-Hand-Disabler', handToDisable); var data = getEntityCustomData('grabbableKey', this.entityID, {}); @@ -139,7 +139,7 @@ setEntityCustomData('grabbableKey', this.entityID, data); }, - continueEquip: function(hand, avatarID) { + continueEquip: function(entityID, args) { this.deltaTime = checkInterval(); //debounce during debugging -- maybe we're updating too fast? @@ -168,7 +168,7 @@ this.checkStringHand(); }, - releaseEquip: function(hand, avatarID) { + releaseEquip: function(entityID, args) { // print('RELEASE GRAB EVENT') Messages.sendMessage('Hifi-Hand-Disabler', "none") diff --git a/examples/toybox/bubblewand/wand.js b/examples/toybox/bubblewand/wand.js index d0ef2871f8..379e94333f 100644 --- a/examples/toybox/bubblewand/wand.js +++ b/examples/toybox/bubblewand/wand.js @@ -119,7 +119,8 @@ //wait to make the bubbles collidable, so that they dont hit each other and the wand 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(); return; } else { diff --git a/examples/toybox/doll/doll.js b/examples/toybox/doll/doll.js index c7661af610..15c587ba4c 100644 --- a/examples/toybox/doll/doll.js +++ b/examples/toybox/doll/doll.js @@ -24,15 +24,11 @@ Doll.prototype = { audioInjector: null, isGrabbed: false, - setLeftHand: function() { - this.hand = 'left'; - }, - setRightHand: function() { - this.hand = 'right'; - }, + startNearGrab: function(entityID, args) { + this.hand = args[0]; + avatarID = args[1]; - startNearGrab: function() { Entities.editEntity(this.entityID, { animation: { url: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", @@ -53,18 +49,18 @@ this.startNearGrab(id, params); }, - continueNearGrab: function() { + continueNearGrab: function(entityID, args) { var props = Entities.getEntityProperties(this.entityID, ["position"]); var audioOptions = { position: props.position }; this.audioInjector.options = audioOptions; }, - continueEquip: function() { - this.continueNearGrab(); + continueEquip: function(entityID, args) { + this.continueNearGrab(entityID, args); }, - releaseGrab: function() { + releaseGrab: function(entityID, args) { if (this.isGrabbed === true && this.hand === this.initialHand) { this.audioInjector.stop(); Entities.editEntity(this.entityID, { @@ -79,8 +75,8 @@ this.isGrabbed = false; } }, - releaseEquip: function() { - this.releaseGrab(); + releaseEquip: function(entityID, args) { + this.releaseGrab(entityID, args); }, preload: function(entityID) { diff --git a/examples/toybox/flashlight/flashlight.js b/examples/toybox/flashlight/flashlight.js index 1a85af695d..19cbc422f4 100644 --- a/examples/toybox/flashlight/flashlight.js +++ b/examples/toybox/flashlight/flashlight.js @@ -77,15 +77,10 @@ whichHand: null, hasSpotlight: false, spotlight: null, - setRightHand: function() { - this.hand = 'RIGHT'; - }, - setLeftHand: function() { - this.hand = 'LEFT'; - }, + startNearGrab: function(entityID, args) { + this.hand = args[0]; - startNearGrab: function(entityID) { print("FLASHLIGHT startNearGrab"); if (!this.hasSpotlight) { @@ -161,11 +156,11 @@ this.changeLightWithTriggerPressure(this.whichHand); } }, - continueEquip: function() { - this.continueNearGrab(); + continueEquip: function(entityID, args) { + this.continueNearGrab(entityID, args); }, - releaseGrab: function() { + releaseGrab: function(entityID, args) { //delete the lights and reset state if (this.hasSpotlight) { Entities.deleteEntity(this.spotlight); @@ -177,8 +172,8 @@ this.lightOn = false; } }, - releaseEquip: function() { - this.releaseGrab(); + releaseEquip: function(entityID, args) { + this.releaseGrab(entityID, args); }, changeLightWithTriggerPressure: function(flashLightHand) { diff --git a/examples/toybox/ping_pong_gun/pingPongGun.js b/examples/toybox/ping_pong_gun/pingPongGun.js index bcb793746b..29eb2e3057 100644 --- a/examples/toybox/ping_pong_gun/pingPongGun.js +++ b/examples/toybox/ping_pong_gun/pingPongGun.js @@ -54,47 +54,26 @@ PingPongGun.prototype = { hand: null, - whichHand: null, gunTipPosition: null, canShoot: false, canShootTimeout: null, - setRightHand: function() { - this.hand = 1; + + startEquip: function(entityID, args) { + this.hand = args[0] == "left" ? 0 : 1; }, - setLeftHand: function() { - this.hand = 0; - }, - - 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); + continueEquip: function(entityID, args) { + if (this.canShootTimeout !== null) { + Script.clearTimeout(this.canShootTimeout); } + this.checkTriggerPressure(this.hand); }, - releaseEquip: function() { + releaseEquip: function(entityID, args) { var _this = this; - - if (this.whichHand === this.hand) { - this.whichHand = null; - this.canShootTimeout = Script.setTimeout(function() { - _this.canShoot = false; - }, 250); - } + this.canShootTimeout = Script.setTimeout(function() { + _this.canShoot = false; + }, 250); }, checkTriggerPressure: function(gunHand) { @@ -102,7 +81,7 @@ if (this.triggerValue < RELOAD_THRESHOLD) { // print('RELOAD'); 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"]); this.shootBall(gunProperties); this.canShoot = false; diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index 87e2f57780..99b7503cba 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -49,10 +49,10 @@ startEquip: function(id, params) { 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) { return; } @@ -111,7 +111,7 @@ }); }, - unequip: function() { + releaseEquip: function(id, params) { this.hand = null; this.equipped = false; Overlays.editOverlay(this.laser, { diff --git a/examples/toybox/spray_paint/sprayPaintCan.js b/examples/toybox/spray_paint/sprayPaintCan.js index 60fd12b975..14e1f328f8 100644 --- a/examples/toybox/spray_paint/sprayPaintCan.js +++ b/examples/toybox/spray_paint/sprayPaintCan.js @@ -38,20 +38,12 @@ Controller.Standard.RT, ]; - this.setRightHand = function () { - this.hand = 1; - } - - this.setLeftHand = function () { - this.hand = 0; - } - - this.startNearGrab = function () { - this.whichHand = this.hand; + this.startNearGrab = function (entityID, args) { + this.hand = args[0] == "left" ? 0 : 1; } 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) { this.spraying = false; this.disableStream();