From c1f8cbd1a3c34b26f69336e34a175065a82047c3 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 24 Sep 2015 14:07:15 -0700 Subject: [PATCH] Remove space before function calls, add spaces before functions --- examples/toys/flashlight/flashlight.js | 82 ++++++++++++-------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/examples/toys/flashlight/flashlight.js b/examples/toys/flashlight/flashlight.js index 5563001d07..9836579afd 100644 --- a/examples/toys/flashlight/flashlight.js +++ b/examples/toys/flashlight/flashlight.js @@ -15,9 +15,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // /*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ -(function () { +(function() { Script.include("../../libraries/utils.js"); + var ON_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/flashlight_on.wav'; var OFF_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/flashlight_off.wav'; @@ -31,22 +32,10 @@ var DISABLE_LIGHT_THRESHOLD = 0.7; // These constants define the Spotlight position and orientation relative to the model - var MODEL_LIGHT_POSITION = { - x: 0, - y: -0.3, - z: 0 - }; - var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, { - x: 1, - y: 0, - z: 0 - }); + var MODEL_LIGHT_POSITION = { x: 0, y: -0.3, z: 0 }; + var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, { x: 1, y: 0, z: 0 }); - var GLOW_LIGHT_POSITION = { - x: 0, - y: -0.1, - z: 0 - }; + var GLOW_LIGHT_POSITION = { x: 0, y: -0.1, z: 0}; // Evaluate the world light entity positions and orientations from the model ones function evalLightWorldTransform(modelPos, modelRot) { @@ -64,20 +53,21 @@ }; } - Flashlight.prototype = { lightOn: false, hand: null, whichHand: null, hasSpotlight: false, spotlight: null, - setRightHand: function () { + setRightHand: function() { this.hand = 'RIGHT'; }, - setLeftHand: function () { + + setLeftHand: function() { this.hand = 'LEFT'; }, - startNearGrab: function () { + + startNearGrab: function() { if (!this.hasSpotlight) { //this light casts the beam @@ -117,16 +107,17 @@ cutoff: 90, // in degrees }); - this.hasSpotlight = true; } }, - setWhichHand: function () { + + setWhichHand: function() { this.whichHand = this.hand; }, - continueNearGrab: function () { + + continueNearGrab: function() { if (this.whichHand === null) { //only set the active hand once -- if we always read the current hand, our 'holding' hand will get overwritten this.setWhichHand(); @@ -135,7 +126,8 @@ this.changeLightWithTriggerPressure(this.whichHand); } }, - releaseGrab: function () { + + releaseGrab: function() { //delete the lights and reset state if (this.hasSpotlight) { Entities.deleteEntity(this.spotlight); @@ -147,29 +139,28 @@ this.lightOn = false; } }, - updateLightPositions: function () { + + updateLightPositions: function() { var modelProperties = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); //move the two lights along the vectors we set above var lightTransform = evalLightWorldTransform(modelProperties.position, modelProperties.rotation); var glowLightTransform = glowLightWorldTransform(modelProperties.position, modelProperties.rotation); - //move them with the entity model Entities.editEntity(this.spotlight, { position: lightTransform.p, rotation: lightTransform.q, }); - Entities.editEntity(this.glowLight, { position: glowLightTransform.p, rotation: glowLightTransform.q, }); }, - changeLightWithTriggerPressure: function (flashLightHand) { + changeLightWithTriggerPressure: function(flashLightHand) { var handClickString = flashLightHand + "_HAND_CLICK"; var handClick = Controller.findAction(handClickString); @@ -183,7 +174,8 @@ } return; }, - turnLightOff: function () { + + turnLightOff: function() { this.playSoundAtCurrentPosition(false); Entities.editEntity(this.spotlight, { intensity: 0 @@ -193,7 +185,8 @@ }); this.lightOn = false; }, - turnLightOn: function () { + + turnLightOn: function() { this.playSoundAtCurrentPosition(true); Entities.editEntity(this.glowLight, { @@ -204,16 +197,8 @@ }); this.lightOn = 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: - // * remembering our entityID, so we can access it in cases where we're called without an entityID - preload: function (entityID) { - this.entityID = entityID; - this.ON_SOUND = SoundCache.getSound(ON_SOUND_URL); - this.OFF_SOUND = SoundCache.getSound(OFF_SOUND_URL); - }, - playSoundAtCurrentPosition: function (playOnSound) { + playSoundAtCurrentPosition: function(playOnSound) { var position = Entities.getEntityProperties(this.entityID, "position").position; var audioProperties = { @@ -228,10 +213,21 @@ } }, - // unload() will be called when our entity is no longer available. It may be because we were deleted, - // or because we've left the domain or quit the application. - unload: function () { + preload: function(entityID) { + // 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: + // * remembering our entityID, so we can access it in cases where we're called without an entityID + // * preloading sounds + this.entityID = entityID; + this.ON_SOUND = SoundCache.getSound(ON_SOUND_URL); + this.OFF_SOUND = SoundCache.getSound(OFF_SOUND_URL); + + }, + + unload: function() { + // unload() will be called when our entity is no longer available. It may be because we were deleted, + // or because we've left the domain or quit the application. if (this.hasSpotlight) { Entities.deleteEntity(this.spotlight); Entities.deleteEntity(this.glowLight); @@ -242,8 +238,8 @@ this.lightOn = false; } - }, + }; // entity scripts always need to return a newly constructed object of our type