const sfx = new Audio("audio/button-press.mp3"); export function DeckButton(name) { const button = document.getElementById(name); const img = document.getElementById(`${name}-img`); const images = { up: `images/${name}-button-up.jpg`, down: `images/${name}-button-down.jpg` }; let state = "off"; const turnOn = function () { state = "on"; img.src = images.down; }; const turnOff = function () { state = "off"; img.src = images.up; }; return { state: () => state, toggle: (opts = {sound: true}) => { state === "off" ? turnOn(opts) : turnOff(opts); if (opts.sound) sfx.play(); }, disable: () => { button.disabled = true; }, enable: () => { button.disabled = false; }, }; }