diff --git a/unpublishedScripts/DomainContent/Home/switches/dressingRoomDiscLights.js b/unpublishedScripts/DomainContent/Home/switches/dressingRoomDiscLights.js new file mode 100644 index 0000000000..4719b9ee5a --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/dressingRoomDiscLights.js @@ -0,0 +1,180 @@ +(function() { + + var SEARCH_RADIUS = 100; + + var EMISSIVE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelitysign_white_emissive.png"; + + var DIFFUSE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelity_diffusebaked.png"; + + var _this; + var utilitiesScript = Script.resolvePath('../../../../libraries/utils.js'); + Script.include(utilitiesScript); + Switch = function() { + _this = this; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; + + Switch.prototype = { + prefix: 'hifi-home-dressing-room-disc-light', + clickReleaseOnEntity: function(entityID, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + startNearTrigger: function() { + this.toggleLights(); + }, + + modelEmitOn: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:' + EMISSIVE_TEXTURE_URL ',\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + modelEmitOff: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:"",\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + masterLightOn: function(masterLight) { + Entities.editEntity(masterLight, { + visible: true + }); + }, + + masterLightOff: function() { + 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; + }, + + toggleLights: function() { + + this.switch = getEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + + var glowLights = this.findGlowLights(); + var masterLights = this.findMasterLights(); + var emitModels = this.findEmitModels(); + + if (this.switch.state === 'off') { + glowLights.forEach(function(glowLight) { + _this.glowLightOn(glowLight); + }); + masterLights.forEach(function(masterLight) { + _this.masterLightOn(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOn(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'on' + }); + + } else { + glowLights.forEach(function(glowLight) { + _this.glowLightOff(glowLight); + }); + masterLights.forEach(function(masterLight) { + _this.masterLightOff(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOff(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + } + + this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + flipSwitch: function() { + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + }, + + 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/labDeskLamp.js b/unpublishedScripts/DomainContent/Home/switches/labDeskLamp.js new file mode 100644 index 0000000000..7685391142 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/labDeskLamp.js @@ -0,0 +1,150 @@ +(function() { + var SEARCH_RADIUS = 100; + + var EMISSIVE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelitysign_white_emissive.png"; + + var DIFFUSE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelity_diffusebaked.png"; + + var _this; + var utilitiesScript = Script.resolvePath('../../../../libraries/utils.js'); + Script.include(utilitiesScript); + Switch = function() { + _this = this; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; + + Switch.prototype = { + prefix: 'hifi-home-lab-desk-lamp', + clickReleaseOnEntity: function(entityID, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + startNearTrigger: function() { + this.toggleLights(); + }, + + modelEmitOn: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:' + EMISSIVE_TEXTURE_URL ',\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + modelEmitOff: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:"",\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + masterLightOn: function(masterLight) { + Entities.editEntity(masterLight, { + visible: true + }); + }, + + masterLightOff: function() { + Entities.editEntity(masterLight, { + visible: false + }); + }, + + + 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 + "spotlight") { + 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 + "model") { + found.push(result); + } + }); + return found; + }, + + toggleLights: function() { + + this.switch = getEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + + var masterLights = this.findMasterLights(); + var emitModels = this.findEmitModels(); + + if (this.switch.state === 'off') { + + masterLights.forEach(function(masterLight) { + _this.masterLightOn(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOn(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'on' + }); + + } else { + + masterLights.forEach(function(masterLight) { + _this.masterLightOff(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOff(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + } + + this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + flipSwitch: function() { + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + }, + + 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/list.txt b/unpublishedScripts/DomainContent/Home/switches/list.txt new file mode 100644 index 0000000000..8509514bbb --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/list.txt @@ -0,0 +1,17 @@ +hifi-home-living-room-disc-light-model +hifi-home-living-room-disc-light-glow +hifi-home-living-room-disc-light-master + +hifi-home-living-room-ceiling-fan +hifi-home-living-room-ceiling-fan-sound +hifi-home-living-room-vent-sound + +hifi-home-living-room-desk-lamp-trigger +hifi-home-living-room-desk-lamp-spotlight + +hifi-home-lab-desk-lamp-trigger +hifi-home-lab-desk-lamp-spotlight + +hifi-home-dressing-room-disc-light-model +hifi-home-dressing-room-disc-light-glow +hifi-home-dressing-room-disc-light-master \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/switches/livingRoomDeskLamp.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomDeskLamp.js new file mode 100644 index 0000000000..78d63f343c --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/livingRoomDeskLamp.js @@ -0,0 +1,151 @@ +(function() { + var SEARCH_RADIUS = 100; + + var EMISSIVE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelitysign_white_emissive.png"; + + var DIFFUSE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelity_diffusebaked.png"; + + var _this; + var utilitiesScript = Script.resolvePath('../../../../libraries/utils.js'); + Script.include(utilitiesScript); + Switch = function() { + _this = this; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; + + Switch.prototype = { + prefix: 'hifi-home-living-room-desk-lamp', + clickReleaseOnEntity: function(entityID, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + startNearTrigger: function() { + this.toggleLights(); + }, + + modelEmitOn: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:' + EMISSIVE_TEXTURE_URL ',\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + modelEmitOff: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:"",\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + masterLightOn: function(masterLight) { + Entities.editEntity(masterLight, { + visible: true + }); + }, + + masterLightOff: function() { + Entities.editEntity(masterLight, { + visible: false + }); + }, + + + 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 + "spotlight") { + 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 + "model") { + found.push(result); + } + }); + return found; + }, + + toggleLights: function() { + + this.switch = getEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + + var masterLights = this.findMasterLights(); + var emitModels = this.findEmitModels(); + + if (this.switch.state === 'off') { + + masterLights.forEach(function(masterLight) { + _this.masterLightOn(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOn(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'on' + }); + + } else { + + masterLights.forEach(function(masterLight) { + _this.masterLightOff(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOff(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + } + + this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + flipSwitch: function() { + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + }, + + 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/livingRoomDiscLights.js new file mode 100644 index 0000000000..eda568eeb6 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/livingRoomDiscLights.js @@ -0,0 +1,180 @@ +(function() { + + var SEARCH_RADIUS = 100; + + var EMISSIVE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelitysign_white_emissive.png"; + + var DIFFUSE_TEXTURE_URL = "http://hifi-content.s3.amazonaws.com/highfidelity_diffusebaked.png"; + + var _this; + var utilitiesScript = Script.resolvePath('../../../../libraries/utils.js'); + Script.include(utilitiesScript); + Switch = function() { + _this = this; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; + + Switch.prototype = { + prefix: 'hifi-home-living-room-disc-light', + clickReleaseOnEntity: function(entityID, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + startNearTrigger: function() { + this.toggleLights(); + }, + + modelEmitOn: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:' + EMISSIVE_TEXTURE_URL ',\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + modelEmitOff: function(discModel) { + Entities.editEntity(glowDisc, { + textures: 'emissive:"",\ndiffuse:"' + DIFFUSE_TEXTURE_URL + '"' + }) + }, + + masterLightOn: function(masterLight) { + Entities.editEntity(masterLight, { + visible: true + }); + }, + + masterLightOff: function() { + 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; + }, + + toggleLights: function() { + + this.switch = getEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + + var glowLights = this.findGlowLights(); + var masterLights = this.findMasterLights(); + var emitModels = this.findEmitModels(); + + if (this.switch.state === 'off') { + glowLights.forEach(function(glowLight) { + _this.glowLightOn(glowLight); + }); + masterLights.forEach(function(masterLight) { + _this.masterLightOn(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOn(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'on' + }); + + } else { + glowLights.forEach(function(glowLight) { + _this.glowLightOff(glowLight); + }); + masterLights.forEach(function(masterLight) { + _this.masterLightOff(masterLight); + }); + emitModels.forEach(function(emitModel) { + _this.modelEmitOff(emitModel); + }); + setEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + } + + this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + flipSwitch: function() { + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + }, + + 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/livingRoomFan.js b/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js new file mode 100644 index 0000000000..6498807e47 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/switches/livingRoomFan.js @@ -0,0 +1,136 @@ +(function() { + var SEARCH_RADIUS = 100; + var _this; + var utilitiesScript = Script.resolvePath('../../../../libraries/utils.js'); + Script.include(utilitiesScript); + Switch = function() { + _this = this; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; + + Switch.prototype = { + prefix: 'hifi-home-living-room-fan', + clickReleaseOnEntity: function(entityID, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggle(); + }, + + startNearTrigger: function() { + this.toggle(); + }, + + fanRotationOn: function() { + Entities.editEntity(this.fan, { + damping: 0, + angularVelocity: { + x: 0, + y: 0.25, + z: 0 + } + }) + }, + + fanRotationOff: function() { + Entities.editEntity(this.fan, { + damping: 1.0, + // angularVelocity:{ + // x:0, + // y:0, + // z:0 + // } + }) + }, + + fanSoundOn: function() { + + }, + + fanSoundOff: function() { + + }, + + ventSoundOn: function() { + + }, + + ventSoundOff: function() { + + }, + + findFan: 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) { + found.push(result); + } + }); + return found; + }, + + toggle: function() { + this.fan = this.findFan(); + this.switch = getEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + + if (this.switch.state === 'off') { + this.fanRotationOn(); + this.fanSoundOn(); + this.ventSoundOn(); + setEntityCustomData('home-switch', this.entityID, { + state: 'on' + }); + + } else { + this.fanRotationOff(); + this.fanSoundOff(); + this.ventSoundOff(); + + setEntityCustomData('home-switch', this.entityID, { + state: 'off' + }); + } + + this.flipSwitch(); + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + flipSwitch: function() { + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + }, + + 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