30 lines
733 B
JavaScript
30 lines
733 B
JavaScript
import Lang from '$lib/lang';
|
|
|
|
const lang = Lang('en_GB');
|
|
|
|
import sound_log from '../sound/log.ogg';
|
|
import sound_hello from '../sound/hello.ogg';
|
|
import sound_success from '../sound/success.ogg';
|
|
let sounds;
|
|
|
|
if (typeof Audio !== typeof undefined) {
|
|
sounds = {
|
|
"default": new Audio(sound_log),
|
|
"post": new Audio(sound_success),
|
|
"boost": new Audio(sound_hello),
|
|
};
|
|
}
|
|
|
|
export function playSound(name) {
|
|
if (name === false) return;
|
|
if (!name) name = "default";
|
|
const sound = sounds[name];
|
|
if (!sound) {
|
|
console.warn(lang.string('lang.sound_does_not_exist', name));
|
|
return;
|
|
}
|
|
sound.pause();
|
|
sound.volume = 0.25;
|
|
sound.currentTime = 0;
|
|
sound.play();
|
|
}
|