mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 16:18:03 +02:00
Toggling lights
This commit is contained in:
parent
e4d630b1fc
commit
a4e5f707cc
2 changed files with 40 additions and 22 deletions
|
@ -30,25 +30,39 @@
|
||||||
|
|
||||||
|
|
||||||
startNearGrab: function() {
|
startNearGrab: function() {
|
||||||
print("TOGGLE LIGHT")
|
|
||||||
this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
|
var defaultLightData = {
|
||||||
if (this.lightState.on === true) {
|
on: false
|
||||||
//Delete the all the sconce lights
|
};
|
||||||
var entities = Entities.findEntities(MyAvatar.position, 100);
|
var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
|
||||||
entities.forEach(function(entity){
|
if (lightState.on === true) {
|
||||||
var resetData = getEntityCustomData(this.resetKey, entity, {})
|
this.clearLights();
|
||||||
});
|
} else if (lightState.on === false) {
|
||||||
|
this.createLights();
|
||||||
}
|
}
|
||||||
// var position = Entities.getEntityProperties(this.entityID, "position").position;
|
|
||||||
// Audio.playSound(clickSound, {
|
|
||||||
// position: position,
|
|
||||||
// volume: 0.05
|
|
||||||
// });
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearLights: function() {
|
||||||
|
print("CLEAR LIGHTS")
|
||||||
|
var entities = Entities.findEntities(MyAvatar.position, 100);
|
||||||
|
var self = this;0
|
||||||
|
entities.forEach(function(entity) {
|
||||||
|
var resetData = getEntityCustomData(self.resetKey, entity, {})
|
||||||
|
print("NAME OF THING " + Entities.getEntityProperties(entity).name)
|
||||||
|
print("RESET DATA " + JSON.stringify(resetData))
|
||||||
|
if (resetData.resetMe === true && resetData.lightType === "Sconce Light") {
|
||||||
|
print("DELETE LIGHT")
|
||||||
|
Entities.deleteEntity(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setEntityCustomData(this.lightStateKey, this.entityID, {
|
||||||
|
on: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
createLights: function() {
|
createLights: function() {
|
||||||
print("CREATE LIGHTS *******************")
|
|
||||||
this.sconceLight1 = Entities.addEntity({
|
this.sconceLight1 = Entities.addEntity({
|
||||||
type: "Light",
|
type: "Light",
|
||||||
position: {
|
position: {
|
||||||
|
@ -72,8 +86,13 @@
|
||||||
|
|
||||||
setEntityCustomData(this.resetKey, this.sconceLight1, {
|
setEntityCustomData(this.resetKey, this.sconceLight1, {
|
||||||
resetMe: true,
|
resetMe: true,
|
||||||
lightType: "sconceLight"
|
lightType: "Sconce Light"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setEntityCustomData(this.lightStateKey, this.entityID, {
|
||||||
|
on: true
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// clickReleaseOnEntity: function(entityId, mouseEvent) {
|
// clickReleaseOnEntity: function(entityId, mouseEvent) {
|
||||||
|
@ -85,18 +104,18 @@
|
||||||
|
|
||||||
// preload() will be called when the entity has become visible (or known) to the interface
|
// 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:
|
// it gives us a chance to set our local JavaScript object up. In this case it means:
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
var defaultLightData= {
|
var defaultLightData = {
|
||||||
on: false
|
on: false
|
||||||
};
|
};
|
||||||
this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
|
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 light is off, then we create two new lights- at the position of the sconces
|
||||||
if (this.lightState.on === false) {
|
if (lightState.on === false) {
|
||||||
this.createLights();
|
this.createLights();
|
||||||
}
|
}
|
||||||
|
//If lights are on, do nothing!
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ function deleteAllToys() {
|
||||||
entities.forEach(function(entity) {
|
entities.forEach(function(entity) {
|
||||||
//params: customKey, id, defaultValue
|
//params: customKey, id, defaultValue
|
||||||
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
|
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
|
||||||
print("should reset " + JSON.stringify(shouldReset));
|
|
||||||
if (shouldReset === true) {
|
if (shouldReset === true) {
|
||||||
Entities.deleteEntity(entity);
|
Entities.deleteEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue