You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.1 KiB

2 years ago
"use strict"
let audioOptions = {
sound: true,
music: true
};
class Sound{
constructor(type){
this.sound = random(audio.sound[type]);
}
static Won(){return "won";}
static Lost(){return "lost";}
static Coin(){return "coin";}
static Jump(){return "jump";}
play(){
this.sound.play();
updateVolume();
}
}
function toggleSounds(){
audioOptions.sound = !audioOptions.sound;
$("#soundVolume").prop("disabled", !audioOptions.sound);
updateVolume();
}
function toggleMusic(){
audioOptions.music = !audioOptions.music;
$("#musicVolume").prop("disabled", !audioOptions.music);
updateVolume();
}
function updateVolume(){
let soundVolume = $("#soundVolume").val() / 100,
musicVolume = $("#musicVolume").val() / 100;
soundVolume = !audioOptions.sound ? 0 : soundVolume;
musicVolume = !audioOptions.music ? 0 : musicVolume;
setVolume("sound", soundVolume);
setVolume("music", musicVolume);
}
function getVolume(type){
let val = $("#" + type + "Volume").val();
return val / 100;
}
function setVolume(key, volume){
for (let prop in audio){
if (prop === key){
for (let type in audio[prop]){
let audios = audio[prop][type];
for (let audio of audios){
audio.setVolume(volume);
}
}
}
}
}
function resetMusics(){
for (let type in audio.music){
let audios = audio.music[type];
for (let audio of audios){
audio.jump();
audio.pause();
}
}
}
function loadAudioFiles(loadedCallback){
soundFormats("mp3", "wav");
audio = JSON.parse(JSON.stringify(settings.audio));
loader = new Loader(Loader.Circle(), "Loading Assets...", loadedCallback);
let count = 0, index = 0;
for (let prop in audio){
let type = audio[prop];
for (let key in type){
let files = type[key];
for (let file of files){
count++;
}
}
}
for (let prop in audio){
let type = audio[prop];
for (let key in type){
let files = type[key];
for (let file of files){
loadSound(file, updateProgress);
function updateProgress(song){
files[files.indexOf(file)] = song;
index++;
loader.updateProgress(index / count, song.file);
}
}
}
}
}
function audioFilesLoaded(){
updateVolume();
loadNewGame();
}