campfire/src/sound.js

20 lines
499 B
JavaScript
Raw Normal View History

const sounds = {
2024-06-28 08:43:12 +01:00
"default": new Audio("/sound/log.ogg"),
"post": new Audio("/sound/success.ogg"),
"boost": new Audio("/sound/hello.ogg"),
};
export function play_sound(name) {
2024-06-28 08:43:12 +01:00
if (name === false) return;
if (!name) name = "default";
const sound = sounds[name];
if (!sound) {
console.warn(`Attempted to play sound "${name}", which does not exist!`);
return;
}
sound.pause();
sound.volume = 0.25;
sound.currentTime = 0;
sound.play();
}