From 62287a6a9fe94b725a19ffd3f4f8ab86baaaeff3 Mon Sep 17 00:00:00 2001 From: Patterntrick Date: Thu, 23 Mar 2017 06:09:40 -0700 Subject: [PATCH] Update xylophoneKey.js Made all the requested changes. --- xylophoneKey.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/xylophoneKey.js b/xylophoneKey.js index 69ce38dfee..fdeddd9c2d 100644 --- a/xylophoneKey.js +++ b/xylophoneKey.js @@ -1,12 +1,12 @@ (function() { - var BASE_PATH = "http://mpassets.highfidelity.com/3fd92e5e-93cf-4bc1-b2f1-c6bae5629814-v1/"; - Script.include(BASE_PATH + "pUtils.js"); - var TIMEOUT = 150; + Script.include(Script.resolvePath("pUtils.js")); + const TIMEOUT = 150; + const TEXGRAY = Script.resolvePath("xylotex_bar_gray.png"); + const TEXBLACK = Script.resolvePath("xylotex_bar_black.png"); var _this; function XylophoneKey() { _this = this; - return; } XylophoneKey.prototype = { @@ -17,15 +17,16 @@ preload: function(entityID) { _this.entityID = entityID; - - var soundURL = BASE_PATH + JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData).soundFile; - //_this.homePos = Entities.getEntityProperties(entityID, ["position"]).position; - //Entities.editEntity(_this.entityID, {position: _this.homePos}); //This is the workaround for collisionWithEntity not being triggered after entity is reloaded. + var soundURL = Script.resolvePath(JSON.parse(Entities.getEntityProperties(_this.entityID, ["userData"]).userData).soundFile); _this.sound = SoundCache.getSound(soundURL); + //Explicitly setting dimensions is a workaround for collisionWithEntity not being triggered after entity is reloaded. Fogbugz Case no. 1939 + Entities.editEntity(_this.entityID, {dimensions: {x: 0.15182036161422729, y: 0.049085158854722977, z: 0.39702033996582031}}); }, collisionWithEntity: function(thisEntity, otherEntity, collision) { - if (!_this.isWaiting && collision.type == 0) {_this.hit();} + if (collision.type === 0) { + _this.hit(); + } }, clickDownOnEntity: function() { @@ -33,25 +34,26 @@ }, hit: function() { - _this.isWaiting = true; - _this.homePos = Entities.getEntityProperties(_this.entityID, ["position"]).position; - _this.injector = Audio.playSound(_this.sound, {position: _this.homePos, volume: 1}); - Controller.triggerHapticPulse(1, 15, 2); //This should be made to only pulse the hand thats holding the mallet. - editEntityTextures(_this.entityID, "file5", BASE_PATH + "xylotex_bar_gray.png"); - var newPos = Vec3.sum(_this.homePos, {x:0,y:-0.025,z:0}); - Entities.editEntity(_this.entityID, {position: newPos}); - _this.timeout(); + if (!_this.isWaiting) { + _this.isWaiting = true; + _this.homePos = Entities.getEntityProperties(_this.entityID, ["position"]).position; + _this.injector = Audio.playSound(_this.sound, {position: _this.homePos, volume: 1}); + Controller.triggerHapticPulse(1, 15, 2); //This should be made to only pulse the hand thats holding the mallet. + editEntityTextures(_this.entityID, "file5", TEXGRAY); + var newPos = Vec3.sum(_this.homePos, {x:0,y:-0.025,z:0}); + Entities.editEntity(_this.entityID, {position: newPos}); + _this.timeout(); + }; }, timeout: function() { Script.setTimeout(function() { - editEntityTextures(_this.entityID, "file5", BASE_PATH + "xylotex_bar_black.png"); + editEntityTextures(_this.entityID, "file5", TEXBLACK); Entities.editEntity(_this.entityID, {position: _this.homePos}); _this.isWaiting = false; - }, TIMEOUT) + }, TIMEOUT); }, - - }; + } return new XylophoneKey();