// soccer // // Created for HiFi Hackathon on 10/26/2018 // (function() { var RESET_SOUND = SoundCache.getSound(Script.resolvePath('assets/sounds/reset.wav')); var SEARCH_RADIUS = 200; var WAIT_TO_FIND_SCORE_BOARDS = 500; var _this; var audioVolume = 0.4; var injector; var scoreBoardPosition; var scoreTexts = []; var Goal = function() { _this = this; }; Goal.prototype = { preload: function(entityID) { _this.entityID = entityID; }, mousePressOnEntity: function() { print("RESETTING SOCCER SCORES"); var position = Entities.getEntityProperties(_this.entityID, 'position').position; Entities.findEntities(position, SEARCH_RADIUS).forEach(function(nearbyEntity) { var name = Entities.getEntityProperties(nearbyEntity, 'name').name; if (name === "Soccer Score") { scoreTexts.push(nearbyEntity); } }); _this.playSound(RESET_SOUND); Script.setTimeout(function() { scoreTexts.forEach(function(scoreBoard) { Entities.editEntity(scoreBoard, { locked: false }); Entities.editEntity(scoreBoard, { text: 0 }); Entities.editEntity(scoreBoard, { locked: true }); }); }, WAIT_TO_FIND_SCORE_BOARDS); }, playSound: function(sound, volume, localOnly) { // print("sound"); if (sound.downloaded) { if (injector) { injector.stop(); } injector = Audio.playSound(sound, { position: scoreBoardPosition, volume: audioVolume }); } } }; return new Goal(); });