Skip to content

Commit

Permalink
Merge pull request #213 from oskarrough/feat/mute-button
Browse files Browse the repository at this point in the history
Add a sound mute button to the menu
  • Loading branch information
oskarrough authored Sep 29, 2023
2 parents 6dd893a + ed63b6c commit 8f8e918
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
11 changes: 10 additions & 1 deletion src/ui/components/menu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {html} from '../lib.js'
import {html, useState} from '../lib.js'
import History from './history.js'
import {saveToUrl} from '../save-load.js'
import {toggleMute} from '../sounds.js'

// @ts-ignore
const abandonGame = () => (window.location.href = window.location.origin)
Expand All @@ -17,6 +18,13 @@ const abandonGame = () => (window.location.href = window.location.origin)
* @returns {import('preact').VNode}
*/
export default function Menu({game, gameState, onUndo}) {
const [muted, setMuted] = useState(false)

function toggleSound() {
toggleMute(!muted)
setMuted(!muted)
}

return html`
<div class="Container">
<h1 center>Slay the Web</h1>
Expand All @@ -34,6 +42,7 @@ export default function Menu({game, gameState, onUndo}) {
<li>
<button onclick=${() => abandonGame()}>Abandon Game</button>
</li>
<li><label>Sound <input type="checkbox" checked=${!muted} onClick=${() => toggleSound()}/></label></li>
</ul>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/ui/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const playDefenseCard = () => {
amSynth.triggerAttackRelease('G#2', 0.02)
}

export const toggleMute = (shouldMute) => {
Tone.Master.mute = shouldMute
}

export default {
startGame,
startTurn,
Expand Down

1 comment on commit 8f8e918

@vercel
Copy link

@vercel vercel bot commented on 8f8e918 Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

slaytheweb – ./

slaytheweb.vercel.app
slaytheweb-oskar.vercel.app
slaytheweb-git-main-oskar.vercel.app
slaytheweb.cards

Please sign in to comment.