| 
									
										
										
										
											2019-08-14 22:09:18 -06:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2019-09-11 20:55:07 -06:00
										 |  |  |  * 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/.
 | 
					
						
							| 
									
										
										
										
											2019-08-14 22:09:18 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | var sfx = {}; | 
					
						
							| 
									
										
										
										
											2019-08-14 22:09:18 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | function initSFX() { | 
					
						
							|  |  |  |     if (localStorage.getItem("alertsound") == null) { | 
					
						
							|  |  |  |         localStorage.setItem("alertsound", "sonar"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-09-10 20:29:35 -06:00
										 |  |  |     if (localStorage.getItem("alertvolume") == null) { | 
					
						
							|  |  |  |         localStorage.setItem("alertvolume", 100); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     var alertNoiseName = localStorage.getItem("alertsound"); | 
					
						
							| 
									
										
										
										
											2019-09-10 20:29:35 -06:00
										 |  |  |     var alertVolume = localStorage.getItem("alertvolume"); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     sfx = { | 
					
						
							|  |  |  |         "alert": new Audio("assets/audio/alert." + alertNoiseName + ".mp3"), | 
					
						
							|  |  |  |         "ok": new Audio("assets/audio/ok.mp3"), | 
					
						
							|  |  |  |         "error": new Audio("assets/audio/error.mp3") | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-09-10 20:29:35 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     setVolume("alert", alertVolume); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-14 22:09:18 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-10 20:29:35 -06:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Play a sound. | 
					
						
							|  |  |  |  * @param string sound Name of the sound to play (alert, ok, error) | 
					
						
							|  |  |  |  * @returns {undefined} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-08-14 22:09:18 -06:00
										 |  |  | function playSound(sound) { | 
					
						
							|  |  |  |     sfx[sound].play(); | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-10 20:29:35 -06:00
										 |  |  | /** | 
					
						
							|  |  |  |  * 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-22 22:21:03 -06:00
										 |  |  | initSFX(); |