summaryrefslogtreecommitdiff
path: root/deck-button.js
diff options
context:
space:
mode:
Diffstat (limited to 'deck-button.js')
-rw-r--r--deck-button.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/deck-button.js b/deck-button.js
new file mode 100644
index 0000000..03cd4de
--- /dev/null
+++ b/deck-button.js
@@ -0,0 +1,26 @@
+const sfx = new Audio("audio/button-press.mp3");
+
+export function DeckButton(name) {
+ const elem = document.getElementById(`${name}-button`);
+ const images = { up: `images/${name}-button-up.jpg`, down: `images/${name}-button-down.jpg` };
+
+ let state = "off";
+
+ const turnOn = function () {
+ state = "on";
+ elem.src = images.down;
+ };
+
+ const turnOff = function () {
+ state = "off";
+ elem.src = images.up;
+ };
+
+ return {
+ state: () => state,
+ toggle: (opts = {sound: true}) => {
+ state === "off" ? turnOn(opts) : turnOff(opts);
+ if (opts.sound) sfx.play();
+ }
+ };
+}