Light switches work properly now; no extra lights

This commit is contained in:
ericrius1 2015-10-02 16:17:54 -07:00
parent e6e60e5e7a
commit 1ac1fcaf69
2 changed files with 12 additions and 8 deletions

View file

@ -16,10 +16,11 @@
/*global LightSwitch */
(function () {
var _this;
var utilitiesScript = Script.resolvePath("../libraries/utils.js");
Script.include(utilitiesScript);
LightSwitch = function () {
_this = this;
this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav");
}
@ -38,23 +39,27 @@
toggleLights: function () {
var lightData = getEntityCustomData(this.resetKey, this.entityID, {});
var on = lightData.on;
var on = !lightData.on;
var lightType = lightData.type;
var lights = Entities.findEntities(this.position, 20);
lights.forEach(function (light) {
var type = getEntityCustomData(this.resetKey, light, {}).type;
if (type === lightType) {
var type = getEntityCustomData(_this.resetKey, light, {}).type;
if (type === lightType && JSON.stringify(light) !== JSON.stringify(_this.entityID)) {
Entities.editEntity(light, {
visible: on
});
}
});
this.flipSwitch();
Audio.playSound(this.switchSound, {
volume: 0.5,
position: this.position
});
setEntityCustomData(this.resetKey, this.entityID, {
on: !on
on: on,
type: lightType,
resetMe: true
});
@ -79,7 +84,6 @@
this.resetKey = "resetMe";
//The light switch is static, so just cache its position once
this.position = Entities.getEntityProperties(this.entityID, "position").position;
this.lightType = getEntityCustomData(this.resetKey, this.entityID, {}).type;
}
};

View file

@ -218,7 +218,7 @@ function createLights() {
var lightSwitchGarage = Entities.addEntity({
type: "Model",
modelURL: modelURL,
name: "Garage",
name: "Light Switch Garage",
script: scriptURL,
position: {
x: 545.62,