Added another light switch- the garage light switch controls the three lights closest to it, and hallway light controls the two near hall

This commit is contained in:
ericrius1 2015-09-23 10:07:59 -07:00
parent 9d9de61afa
commit 573cdc5271
3 changed files with 207 additions and 68 deletions

View file

@ -18,7 +18,7 @@
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
// our this object, so we can access it in cases where we're called without a this (like in the case of various global signals)
LightSwitch = function() {
LightSwitchGarage = function() {
_this = this;
this.lightStateKey = "lightStateKey";
@ -28,7 +28,7 @@
};
LightSwitch.prototype = {
LightSwitchGarage.prototype = {
clickReleaseOnEntity: function(entityId, mouseEvent) {
if (!mouseEvent.isLeftButton) {
@ -64,7 +64,7 @@
var self = this;
entities.forEach(function(entity) {
var resetData = getEntityCustomData(self.resetKey, entity, {})
if (resetData.resetMe === true && resetData.lightType === "Sconce Light") {
if (resetData.resetMe === true && resetData.lightType === "Sconce Light Garage") {
Entities.deleteEntity(entity);
}
});
@ -75,57 +75,7 @@
},
createLights: function() {
var sconceLight1 = Entities.addEntity({
type: "Light",
position: {
x: 543.62,
y: 496.24,
z: 511.23
},
name: "Sconce 1 Light",
dimensions: {
x: 2.545,
y: 2.545,
z: 2.545
},
cutoff: 90,
color: {
red: 217,
green: 146,
blue: 24
}
});
setEntityCustomData(this.resetKey, sconceLight1, {
resetMe: true,
lightType: "Sconce Light"
});
var sconceLight2 = Entities.addEntity({
type: "Light",
position: {
x: 539.87,
y: 496.24,
z: 505.77
},
name: "Sconce 2 Light",
dimensions: {
x: 2.545,
y: 2.545,
z: 2.545
},
cutoff: 90,
color: {
red: 217,
green: 146,
blue: 24
}
});
setEntityCustomData(this.resetKey, sconceLight2, {
resetMe: true,
lightType: "Sconce Light"
});
var sconceLight3 = Entities.addEntity({
type: "Light",
@ -151,7 +101,7 @@
setEntityCustomData(this.resetKey, sconceLight3, {
resetMe: true,
lightType: "Sconce Light"
lightType: "Sconce Light Garage"
});
var sconceLight4 = Entities.addEntity({
@ -178,7 +128,7 @@
setEntityCustomData(this.resetKey, sconceLight4, {
resetMe: true,
lightType: "Sconce Light"
lightType: "Sconce Light Garage"
});
var sconceLight5 = Entities.addEntity({
@ -204,7 +154,7 @@
setEntityCustomData(this.resetKey, sconceLight5, {
resetMe: true,
lightType: "Sconce Light"
lightType: "Sconce Light Garage"
});
@ -236,5 +186,5 @@
};
// entity scripts always need to return a newly constructed object of our type
return new LightSwitch();
return new LightSwitchGarage();
})

View file

@ -0,0 +1,158 @@
//
// detectGrabExample.js
// examples/entityScripts
//
// Created by Eric Levin on 9/21/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var _this;
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
// our this object, so we can access it in cases where we're called without a this (like in the case of various global signals)
LightSwitchHall = function() {
_this = this;
this.lightStateKey = "lightStateKey";
this.resetKey = "resetMe";
this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav");
};
LightSwitchHall.prototype = {
clickReleaseOnEntity: function(entityId, mouseEvent) {
if (!mouseEvent.isLeftButton) {
return;
}
this.toggleLights();
},
startNearTouch: function() {
this.toggleLights();
},
toggleLights: function() {
var defaultLightData = {
on: false
};
var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
if (lightState.on === true) {
this.clearLights();
} else if (lightState.on === false) {
this.createLights();
}
Audio.playSound(this.switchSound, {
volume: 0.5,
position: this.position
});
},
clearLights: function() {
var entities = Entities.findEntities(MyAvatar.position, 100);
var self = this;
entities.forEach(function(entity) {
var resetData = getEntityCustomData(self.resetKey, entity, {})
if (resetData.resetMe === true && resetData.lightType === "Sconce Light Hall") {
Entities.deleteEntity(entity);
}
});
setEntityCustomData(this.lightStateKey, this.entityID, {
on: false
});
},
createLights: function() {
var sconceLight1 = Entities.addEntity({
type: "Light",
position: {
x: 543.75,
y: 496.24,
z: 511.13
},
name: "Sconce 1 Light",
dimensions: {
x: 2.545,
y: 2.545,
z: 2.545
},
cutoff: 90,
color: {
red: 217,
green: 146,
blue: 24
}
});
setEntityCustomData(this.resetKey, sconceLight1, {
resetMe: true,
lightType: "Sconce Light Hall"
});
var sconceLight2 = Entities.addEntity({
type: "Light",
position: {
x: 540.1 ,
y: 496.24,
z: 505.57
},
name: "Sconce 2 Light",
dimensions: {
x: 2.545,
y: 2.545,
z: 2.545
},
cutoff: 90,
color: {
red: 217,
green: 146,
blue: 24
}
});
setEntityCustomData(this.resetKey, sconceLight2, {
resetMe: true,
lightType: "Sconce Light Hall"
});
setEntityCustomData(this.lightStateKey, this.entityID, {
on: true
});
},
// preload() will be called when the entity has become visible (or known) to the interface
// it gives us a chance to set our local JavaScript object up. In this case it means:
preload: function(entityID) {
this.entityID = entityID;
//The light switch is static, so just cache its position once
this.position = Entities.getEntityProperties(this.entityID, "position").position;
var defaultLightData = {
on: false
};
var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
//If light is off, then we create two new lights- at the position of the sconces
if (lightState.on === false) {
this.createLights();
}
//If lights are on, do nothing!
},
};
// entity scripts always need to return a newly constructed object of our type
return new LightSwitchHall();
})

View file

@ -55,11 +55,7 @@ function createAllToys() {
});
//Handles toggling of all sconce lights
createLightSwitch({
x: 543.27764892578125,
y: 495.67999267578125,
z: 511.00564575195312
});
createLightSwitches();
}
function deleteAllToys() {
@ -109,15 +105,20 @@ function createFlashlight(position) {
}
function createLightSwitch(position) {
function createLightSwitches() {
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx";
var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v2");
var lightSwitch = Entities.addEntity({
var scriptURL = Script.resolvePath("entityScripts/lightSwitchHall.js?v1");
var lightSwitchHall = Entities.addEntity({
type: "Model",
modelURL: modelURL,
name: "Light Switch Hall",
script: scriptURL,
position: position,
position: {
x: 543.27764892578125,
y: 495.67999267578125,
z: 511.00564575195312
},
rotation: {
w: 0.63280689716339111,
x: 0.63280689716339111,
@ -131,9 +132,39 @@ function createLightSwitch(position) {
}
});
setEntityCustomData(resetKey, lightSwitch, {
setEntityCustomData(resetKey, lightSwitchHall, {
resetMe: true
});
scriptURL = Script.resolvePath("entityScripts/lightSwitchGarage.js?v1");
var lightSwitchGarage = Entities.addEntity({
type: "Model",
modelURL: modelURL,
name: "Light Switch Garage",
script: scriptURL,
position: {
x: 545.62,
y: 495.68,
z: 500.21
},
rotation: {
w: 0.20082402229309082,
x: 0.20082402229309082,
y: -0.67800414562225342,
z: 0.67797362804412842
},
dimensions: {
x: 0.10546875,
y: 0.032372996211051941,
z: 0.16242524981498718
}
});
setEntityCustomData(resetKey, lightSwitchGarage, {
resetMe: true
});
}
function createDice() {