// // toys/AC_scripts/toybox_sounds.js // // This script adds several sounds to the correct locations for toybox. // By James B. Pollack @imgntn 10/21/2015 // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // var soundMap = [{ name: 'desert wind 1', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/Desert_Wind__Whistle.L.wav", audioOptions: { position: { x: -38.1, y: -8.2, z: -19.1 }, volume: 0.5, loop: true } }, { name: 'desert wind 2', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/Desert_Wind__Whistle.R.wav", audioOptions: { position: { x: 28.2, y: -8.2, z: 9.1 }, volume: 0.5, loop: true } }, { name: 'desert wind 3', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/Desert_Day_Atmosphere.L.wav", audioOptions: { position: { x: 4.81, y: -8.2, z: 27.89 }, volume: 0.5, loop: true } }, { name: 'desert wind 4', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/Desert_Day_Atmosphere.R.wav", audioOptions: { position: { x: -11.61, y: -8.2, z: 29.93 }, volume: 0.5, loop: true } }, { name: 'distant music 1', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/bm_music3.L.wav", audioOptions: { position: { x: -33.91, y: -8.63, z: -56.65 }, volume: 1, loop: true } }, { name: 'distant music 2', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/bm_music6.L.wav", audioOptions: { position: { x: 48.49, y: -8.63, z: 24.77 }, volume: .25, loop: true } }, { name: 'distant music 3', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/wonky2.L.wav", audioOptions: { position: { x: 7.53, y: -8.63, z: -24.46 }, volume: .09, loop: true } }, { name: 'street party 1', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/streetparty1.L.wav", audioOptions: { position: { x: 29.23, y: -8.633, z: -11.23 }, volume: .08, loop: true } }, { name: 'street party 2 ', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/streetparty2.L.wav", audioOptions: { position: { x: -19.98, y: -8.63, z: -21.95 }, volume: .08, loop: true } }, { name: 'street party 3', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/streetparty3.L.wav", audioOptions: { position: { x: -31.94, y: -8.63, z: 14.67 }, volume: .08, loop: true } }, { name: 'windchime 1', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/windchime1.L.wav", audioOptions: { position: { x: 3.11, y: -8.63, z: 8.31 }, volume: .05, loop: true }, playAtInterval: 60 * 1000 }, { name: 'windchime 2', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/windchime2.L.wav", audioOptions: { position: { x: -40.11, y: -8.63, z: -5.70 }, volume: .05, loop: true }, playAtInterval: 60 * 1000 }, { name: 'tarp in wind', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/tarp.R.wav", audioOptions: { position: { x: -9.42, y: -8.63, z: -6.54 }, volume: .05, loop: true }, playAtInterval: 60 * 1000 }, { name: 'cloth in wind', url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Sounds/cloth_sail.L.wav", audioOptions: { position: { x: 17.12, y: -8.63, z: 15.3 }, volume: .05, loop: true }, playAtInterval: 60 * 1000 }]; function loadSounds() { soundMap.forEach(function(soundData) { soundData.sound = SoundCache.getSound(soundData.url); }); } function playSound(soundData) { if (soundData.injector) { // try/catch in case the injector QObject has been deleted already try { soundData.injector.stop(); } catch (e) {} } soundData.injector = Audio.playSound(soundData.sound, soundData.audioOptions); } function checkDownloaded(soundData) { if (soundData.sound.downloaded) { Script.clearInterval(soundData.downloadTimer); if (soundData.hasOwnProperty('playAtInterval')) { soundData.playingInterval = Script.setInterval(function() { playSound(soundData) }, soundData.playAtInterval); } else { playSound(soundData); } } } function startCheckDownloadedTimers() { soundMap.forEach(function(soundData) { soundData.downloadTimer = Script.setInterval(function() { checkDownloaded(soundData); }, 1000); }); } Script.scriptEnding.connect(function() { soundMap.forEach(function(soundData) { if (soundData.hasOwnProperty("injector")) { soundData.injector.stop(); } if (soundData.hasOwnProperty("downloadTimer")) { Script.clearInterval(soundData.downloadTimer); } if (soundData.hasOwnProperty("playingInterval")) { Script.clearInterval(soundData.playingInterval); } }); }); loadSounds(); startCheckDownloadedTimers();