[arcade] Fix mute toggle

This commit is contained in:
Max Wofford 2024-06-01 16:57:30 -04:00
parent de45024f12
commit 6fbdc0feab
2 changed files with 16 additions and 2 deletions

View file

@ -6,6 +6,9 @@
<title>Power Hour: Arcade</title>
<link rel="icon" type="image/x-icon" href="https://cloud-n6tkrqcbc-hack-club-bot.vercel.app/0favicon.png">
<script>
let muted = true
</script>
<!-- <style href="style.css"></style> -->
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="data-loader.js"></script>
@ -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

View file

@ -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 }),