/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ var sfx = {}; function initSFX() { if (localStorage.getItem("alertsound") == null) { localStorage.setItem("alertsound", "sonar"); } if (localStorage.getItem("alertvolume") == null) { localStorage.setItem("alertvolume", 100); } var alertNoiseFile = SETTINGS.alertsounds[localStorage.getItem("alertsound")].file; var alertVolume = localStorage.getItem("alertvolume"); sfx = { "alert": new Audio("assets/audio/" + alertNoiseFile), "ok": new Audio("assets/audio/ok.mp3"), "error": new Audio("assets/audio/error.mp3"), "scan": new Audio("assets/audio/scan.mp3") }; setVolume("alert", alertVolume); } /** * Play a sound. * @param string sound Name of the sound to play (alert, ok, error) * @returns {undefined} */ function playSound(sound) { sfx[sound].play(); } /** * Set sound volume * @param string sound The name of the sound to set volume of * @param number volume Number in range 0 to 100 */ function setVolume(sound, volume) { sfx[sound].volume = volume / 100.0; } initSFX();