campfire/src/lib/sound.js

31 lines
733 B
JavaScript
Raw Normal View History

2025-07-13 20:44:54 +01:00
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';
2024-06-29 10:46:27 +01:00
let sounds;
if (typeof Audio !== typeof undefined) {
sounds = {
"default": new Audio(sound_log),
"post": new Audio(sound_success),
"boost": new Audio(sound_hello),
2024-06-29 10:46:27 +01:00
};
}
export function playSound(name) {
2024-06-28 08:43:12 +01:00
if (name === false) return;
if (!name) name = "default";
const sound = sounds[name];
if (!sound) {
2025-07-13 20:44:54 +01:00
console.warn(lang.string('lang.sound_does_not_exist', name));
return;
}
sound.pause();
sound.volume = 0.25;
sound.currentTime = 0;
sound.play();
}