From 266dfcd8e941cc68e134274c7e5cb65b047d021f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 23 May 2016 11:45:55 -0700 Subject: [PATCH] new lightswitches and cleanup old code, also more blocky stuff --- .../DomainContent/Home/blocky/blocky.js | 19 ++ .../Home/switches/livingRoomFan.js | 28 ++- .../Home/switches/livingRoomLightDown.js | 197 ------------------ .../Home/switches/livingRoomLightUp.js | 195 ----------------- ...gRoomDiscLights.js => livingRoomLights.js} | 24 ++- 5 files changed, 57 insertions(+), 406 deletions(-) delete mode 100644 unpublishedScripts/DomainContent/Home/switches/livingRoomLightDown.js delete mode 100644 unpublishedScripts/DomainContent/Home/switches/livingRoomLightUp.js rename unpublishedScripts/DomainContent/Home/switches/{livingRoomDiscLights.js => livingRoomLights.js} (91%) diff --git a/unpublishedScripts/DomainContent/Home/blocky/blocky.js b/unpublishedScripts/DomainContent/Home/blocky/blocky.js index 0c4b252a21..948ccd5e04 100644 --- a/unpublishedScripts/DomainContent/Home/blocky/blocky.js +++ b/unpublishedScripts/DomainContent/Home/blocky/blocky.js @@ -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); }); diff --git a/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js index fa8d0968a0..09d0fb97c8 100644 --- a/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js +++ b/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js @@ -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" + }, }) + + } diff --git a/unpublishedScripts/DomainContent/Home/switches/livingRoomLightDown.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomLightDown.js deleted file mode 100644 index 86c9a70716..0000000000 --- a/unpublishedScripts/DomainContent/Home/switches/livingRoomLightDown.js +++ /dev/null @@ -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(); -}); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/switches/livingRoomLightUp.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomLightUp.js deleted file mode 100644 index 1be08a6fec..0000000000 --- a/unpublishedScripts/DomainContent/Home/switches/livingRoomLightUp.js +++ /dev/null @@ -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(); -}); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/switches/livingRoomDiscLights.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomLights.js similarity index 91% rename from unpublishedScripts/DomainContent/Home/switches/livingRoomDiscLights.js rename to unpublishedScripts/DomainContent/Home/switches/livingRoomLights.js index 6fb2ea538a..2c6208481f 100644 --- a/unpublishedScripts/DomainContent/Home/switches/livingRoomDiscLights.js +++ b/unpublishedScripts/DomainContent/Home/switches/livingRoomLights.js @@ -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" + }, }); }