new lightswitches and cleanup old code, also more blocky stuff

This commit is contained in:
James B. Pollack 2016-05-23 11:45:55 -07:00
parent 5211b6ad77
commit 266dfcd8e9
5 changed files with 57 additions and 406 deletions

View file

@ -171,8 +171,27 @@ var TARGET_BLOCKS_POSITION = {
}
},
findBlocks: function() {
var found = [];
var results = Entities.findEntities(this.position, 10);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
print('got result props')
if (properties.name.indexOf('blocky_block') > -1) {
found.push(result);
}
});
return found;
},
cleanup: function() {
print('BLOCKY cleanup');
var blocks = this.findBlocks();
print('BLOCKY cleanup2')
blocks.forEach(function(block) {
Entities.deleteEntity(block);
})
print('BLOCKY after find and delete')
this.targetBlocks.forEach(function(block) {
Entities.deleteEntity(block);
});

View file

@ -9,9 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var ON_MODEL_URL="atp:/switches/fanswitch_on.fbx";
var OFF_MODEL_URL="atp:/switches/fanswitch_off.fbx";
(function() {
var FAN_SOUND_ENTITY_NAME = "home_sfx_ceiling_fan"
var SEARCH_RADIUS = 100;
@ -131,14 +129,21 @@
if (this._switch.state === 'off') {
this.fanRotationOn();
this.fanSoundOn();
setEntityCustomData('home-switch', this.entityID, {
state: 'on'
});
Entities.editEntity(this.entityID, {
modelURL: ON_MODEL_URL
});
"animation": {
"currentFrame": 1,
"firstFrame": 1,
"hold": 1,
"lastFrame": 2,
"url": "atp:/switches/fanswitch.fbx"
},
})
} else {
this.fanRotationOff();
@ -147,10 +152,17 @@
setEntityCustomData('home-switch', this.entityID, {
state: 'off'
});
Entities.editEntity(this.entityID, {
modelURL: OFF_MODEL_URL
"animation": {
"currentFrame": 3,
"firstFrame": 3,
"hold": 1,
"lastFrame": 4,
"url": "atp:/switches/fanswitch.fbx"
},
})
}

View file

@ -1,197 +0,0 @@
//
//
// Created by The Content Team 4/10/216
// Copyright 2016 High Fidelity, Inc.
//
// this finds lights and toggles thier visibility, and flips the emissive texture of some light models
//
// 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 SEARCH_RADIUS = 100;
var _this;
var utilitiesScript = Script.resolvePath('../utils.js');
Script.include(utilitiesScript);
Switch = function() {
_this = this;
this.switchSound = SoundCache.getSound("atp:/switches/lamp_switch_2.wav");
};
Switch.prototype = {
prefix: 'hifi-home-living-room-disc-',
clickReleaseOnEntity: function(entityID, mouseEvent) {
if (!mouseEvent.isLeftButton) {
return;
}
this.toggleLights();
},
startNearTrigger: function() {
this.toggleLights();
},
modelEmitOn: function(glowDisc) {
var data = {
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-On-Diffuse.jpg",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
})
},
modelEmitOff: function(glowDisc) {
var data = {
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
})
},
masterLightOn: function(masterLight) {
Entities.editEntity(masterLight, {
visible: true
});
},
masterLightOff: function(masterLight) {
Entities.editEntity(masterLight, {
visible: false
});
},
glowLightOn: function(glowLight) {
Entities.editEntity(glowLight, {
visible: true
});
},
glowLightOff: function(glowLight) {
Entities.editEntity(glowLight, {
visible: false
});
},
findGlowLights: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-glow") {
found.push(result);
}
});
return found;
},
findMasterLights: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-master") {
found.push(result);
}
});
return found;
},
findEmitModels: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-model") {
found.push(result);
}
});
return found;
},
findSwitch: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === "hifi-home-living-room-light-switch-up") {
found.push(result);
}
});
return found;
},
toggleLights: function() {
var glowLights = this.findGlowLights();
var masterLights = this.findMasterLights();
var emitModels = this.findEmitModels();
glowLights.forEach(function(glowLight) {
// _this.glowLightOff(glowLight);
});
masterLights.forEach(function(masterLight) {
_this.masterLightOff(masterLight);
});
emitModels.forEach(function(emitModel) {
_this.modelEmitOff(emitModel);
});
Audio.playSound(this.switchSound, {
volume: 0.5,
position: this.position
});
Entities.editEntity(this.entityID, {
position: {
x: 1103.9894,
y: 460.6867,
z: -75.5650
}
});
var otherSwitch = this.findSwitch();
print('other switch:: ' + otherSwitch)
var success = Entities.editEntity(otherSwitch.toString(), {
position: {
x: 1103.5823,
y: 460.6867,
z: -75.6313
}
})
print('edit success ' + success)
},
preload: function(entityID) {
this.entityID = entityID;
setEntityCustomData('grabbableKey', this.entityID, {
wantsTrigger: true
});
var properties = Entities.getEntityProperties(this.entityID);
//The light switch is static, so just cache its position once
this.position = Entities.getEntityProperties(this.entityID, "position").position;
}
};
// entity scripts always need to return a newly constructed object of our type
return new Switch();
});

View file

@ -1,195 +0,0 @@
//
//
// Created by The Content Team 4/10/216
// Copyright 2016 High Fidelity, Inc.
//
// this finds lights and toggles thier visibility, and flips the emissive texture of some light models
//
// 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 SEARCH_RADIUS = 100;
var _this;
var utilitiesScript = Script.resolvePath('../utils.js');
Script.include(utilitiesScript);
Switch = function() {
_this = this;
this.switchSound = SoundCache.getSound("atp:/switches/lamp_switch_2.wav");
};
Switch.prototype = {
prefix: 'hifi-home-living-room-disc-',
clickReleaseOnEntity: function(entityID, mouseEvent) {
if (!mouseEvent.isLeftButton) {
return;
}
this.toggleLights();
},
startNearTrigger: function() {
this.toggleLights();
},
modelEmitOn: function(glowDisc) {
var data = {
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-On-Diffuse.jpg",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
})
},
modelEmitOff: function(glowDisc) {
var data = {
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
})
},
masterLightOn: function(masterLight) {
Entities.editEntity(masterLight, {
visible: true
});
},
masterLightOff: function(masterLight) {
Entities.editEntity(masterLight, {
visible: false
});
},
glowLightOn: function(glowLight) {
Entities.editEntity(glowLight, {
visible: true
});
},
glowLightOff: function(glowLight) {
Entities.editEntity(glowLight, {
visible: false
});
},
findGlowLights: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-glow") {
found.push(result);
}
});
return found;
},
findMasterLights: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-master") {
found.push(result);
}
});
return found;
},
findEmitModels: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === _this.prefix + "light-model") {
found.push(result);
}
});
return found;
},
findSwitch: function() {
var found = [];
var results = Entities.findEntities(this.position, SEARCH_RADIUS);
results.forEach(function(result) {
var properties = Entities.getEntityProperties(result);
if (properties.name === "hifi-home-living-room-light-switch-down") {
found.push(result);
}
});
return found;
},
toggleLights: function() {
var glowLights = this.findGlowLights();
var masterLights = this.findMasterLights();
var emitModels = this.findEmitModels();
glowLights.forEach(function(glowLight) {
// _this.glowLightOff(glowLight);
});
masterLights.forEach(function(masterLight) {
_this.masterLightOff(masterLight);
});
emitModels.forEach(function(emitModel) {
_this.modelEmitOff(emitModel);
});
Audio.playSound(this.switchSound, {
volume: 0.5,
position: this.position
});
Entities.editEntity(this.entityID, {
position: {
x: 1103.9894,
y: 460.6867,
z: -75.5650
}
});
var otherSwitch = this.findSwitch();
print('other switch:: ' + otherSwitch)
var success = Entities.editEntity(otherSwitch.toString(), {
position: {
x: 1103.5823,
y: 460.6867,
z: -75.6313
}
})
print('edit success ' + success)
},
preload: function(entityID) {
this.entityID = entityID;
setEntityCustomData('grabbableKey', this.entityID, {
wantsTrigger: true
});
var properties = Entities.getEntityProperties(this.entityID);
//The light switch is static, so just cache its position once
this.position = Entities.getEntityProperties(this.entityID, "position").position;
}
};
// entity scripts always need to return a newly constructed object of our type
return new Switch();
});

View file

@ -10,8 +10,7 @@
//
(function() {
var ON_MODEL_URL = "atp:/switches/lightswitch_on.fbx";
var OFF_MODEL_URL = "atp:/switches/lightswitch_off.fbx";
var SEARCH_RADIUS = 100;
var _this;
@ -40,7 +39,7 @@
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-On-Diffuse.jpg",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
};
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
@ -52,7 +51,7 @@
"Metal-brushed-light.jpg": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/Metal-brushed-light.jpg",
"Tex.CeilingLight.Emit": "",
"TexCeilingLight.Diffuse": "atp:/models/Lights-Living-Room-2.fbx/Lights-Living-Room-2.fbm/CielingLight-Base.jpg"
}
};
Entities.editEntity(glowDisc, {
textures: JSON.stringify(data)
@ -143,8 +142,15 @@
setEntityCustomData('home-switch', _this.entityID, {
state: 'on'
});
Entities.editEntity(this.entityID, {
modelURL: ON_MODEL_URL
"animation": {
"currentFrame": 1,
"firstFrame": 1,
"hold": 1,
"lastFrame": 2,
"url": "atp:/switches/lightswitch.fbx"
},
});
} else {
@ -162,7 +168,13 @@
});
Entities.editEntity(this.entityID, {
modelURL: OFF_MODEL_URL
"animation": {
"currentFrame": 3,
"firstFrame": 3,
"hold": 1,
"lastFrame": 4,
"url": "atp:/switches/lightswitch.fbx"
},
});
}