Skip to content
Snippets Groups Projects
Commit bfe57e81 authored by Florian Kaufmann's avatar Florian Kaufmann
Browse files

Changed coding style

parent 4071b30c
1 merge request!10Added sounds & the ability to play them
/**
* Loads, manages & plays sound files
*/
class SoundPlayer {
constructor() {
this.context = new window.AudioContext();
/** @type {{[key: string]: HTMLAudioElement}} */
this.sounds = {};
this.initSounds();
}
initSounds() {
let path = "./res/sounds/";
let extension = ".oga";
let names = ["defaultError", "defaultSuccess", "join", "leave", "roundOver", "selectedWord", "timeLow", "win", "wtfError", "yourTurn"];
for (let name of names) {
let audio = document.createElement("audio");
audio.controls = true;
audio.id = name;
audio.src = path + name + extension;
this.sounds[name] = audio;
}
}
/**
*
* @param {string} name
*/
playSound(name) {
this.sounds[name].currentTime = 0.0;
this.sounds[name].play();
}
/**
*
* @param {"defaultError" | "defaultSuccess" | "join" | "leave" | "roundOver" | "selectedWord" | "timeLow" | "win" | "wtfError" | "yourTurn"} name
*/
export default function playSound(name) {
sounds[name].currentTime = 0.0;
sounds[name].play();
}
export default new SoundPlayer();
\ No newline at end of file
/** @type {{[key: string]: HTMLAudioElement}} */
let sounds = {};
function initSounds() {
let path = "./res/sounds/";
let extension = ".oga";
let names = ["defaultError", "defaultSuccess", "join", "leave", "roundOver", "selectedWord", "timeLow", "win", "wtfError", "yourTurn"];
for (let name of names) {
let audio = document.createElement("audio");
audio.controls = true;
audio.id = name;
audio.src = path + name + extension;
sounds[name] = audio;
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment