From 6fbdc0feab551f3b8da11984da7b41366ccaf6a7 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Sat, 1 Jun 2024 16:57:30 -0400 Subject: [PATCH] [arcade] Fix mute toggle --- public/arcade/index.html | 15 ++++++++++++++- public/yap.js | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/public/arcade/index.html b/public/arcade/index.html index abc1271e..47c67962 100644 --- a/public/arcade/index.html +++ b/public/arcade/index.html @@ -6,6 +6,9 @@ Power Hour: Arcade + @@ -64,7 +67,7 @@ handleClick({ name: "Dino", flavorText: selfClicks["Dino"] }) }) - document.querySelector('.sound-button').addEventListener('click', toggleMusic) + document.querySelector('.sound-button').addEventListener('click', toggleMute) function handleClick(inv) { let msg = sample(inv.flavorText) @@ -128,6 +131,16 @@ rate: 0.5 }) + async function toggleMute() { + muted = !muted + if (muted) { + document.querySelector('.sound-button').textContent = 'Want sound?' + } else if (!muted) { + document.querySelector('.sound-button').textContent = 'Mute sound' + } + toggleMusic() + } + async function toggleMusic() { if (firstPlay) { // strange fade-in effect where the pitch shifts up like a record player diff --git a/public/yap.js b/public/yap.js index b6fe995e..d7e38d1a 100644 --- a/public/yap.js +++ b/public/yap.js @@ -3,8 +3,9 @@ async function yap(text, { endCallback = () => {}, baseRate = 1.9, rateVariance = 0.50, - volume = 0.50 }) { + let volume = 0.2 + if (muted) { endCallback(); return } const yap_sounds = { // these sounds and most of the yapping code are adapted from https://github.com/equalo-official/animalese-generator a: new Howl({ src: '/bin/yapping/a.wav', volume }),