Merge pull request #6319 from imgntn/quickgrabfix

Set wantsTrigger correctly on lightswitch.js
This commit is contained in:
Seth Alves 2015-11-05 10:52:18 -08:00
commit 669609d310

View file

@ -15,35 +15,35 @@
/*global LightSwitch */ /*global LightSwitch */
(function () { (function() {
var _this; var _this;
var utilitiesScript = Script.resolvePath("../../libraries/utils.js"); var utilitiesScript = Script.resolvePath("../../libraries/utils.js");
Script.include(utilitiesScript); Script.include(utilitiesScript);
LightSwitch = function () { LightSwitch = function() {
_this = this; _this = this;
this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav");
}; };
LightSwitch.prototype = { LightSwitch.prototype = {
clickReleaseOnEntity: function (entityID, mouseEvent) { clickReleaseOnEntity: function(entityID, mouseEvent) {
if (!mouseEvent.isLeftButton) { if (!mouseEvent.isLeftButton) {
return; return;
} }
this.toggleLights(); this.toggleLights();
}, },
startNearTrigger: function () { startNearTrigger: function() {
this.toggleLights(); this.toggleLights();
}, },
toggleLights: function () { toggleLights: function() {
var lightData = getEntityCustomData(this.resetKey, this.entityID, {}); var lightData = getEntityCustomData(this.resetKey, this.entityID, {});
var on = !lightData.on; var on = !lightData.on;
var lightType = lightData.type; var lightType = lightData.type;
var lights = Entities.findEntities(this.position, 20); var lights = Entities.findEntities(this.position, 20);
lights.forEach(function (light) { lights.forEach(function(light) {
var type = getEntityCustomData(_this.resetKey, light, {}).type; var type = getEntityCustomData(_this.resetKey, light, {}).type;
if (type === lightType && JSON.stringify(light) !== JSON.stringify(_this.entityID)) { if (type === lightType && JSON.stringify(light) !== JSON.stringify(_this.entityID)) {
Entities.editEntity(light, { Entities.editEntity(light, {
@ -61,12 +61,15 @@
setEntityCustomData(this.resetKey, this.entityID, { setEntityCustomData(this.resetKey, this.entityID, {
on: on, on: on,
type: lightType, type: lightType,
resetMe: true, resetMe: true
grabbableKey: {wantsTrigger:true} });
setEntityCustomData('grabbableKey', this.entityID, {
wantsTrigger: true
}); });
}, },
flipSwitch: function () { flipSwitch: function() {
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
var axis = { var axis = {
x: 0, x: 0,
@ -80,7 +83,7 @@
rotation: rotation rotation: rotation
}); });
}, },
preload: function (entityID) { preload: function(entityID) {
this.entityID = entityID; this.entityID = entityID;
this.resetKey = "resetMe"; this.resetKey = "resetMe";
//The light switch is static, so just cache its position once //The light switch is static, so just cache its position once
@ -90,4 +93,4 @@
// entity scripts always need to return a newly constructed object of our type // entity scripts always need to return a newly constructed object of our type
return new LightSwitch(); return new LightSwitch();
}); });