Files
HokmPlay/src/lib/sound-store.ts
T
soroush.asadi 0a3ffa6314 Fix: in-game mute button now mutes background music too
HUD mute is a master toggle (sound effects + music) via sound-store.toggleAll;
icon reflects fully-muted state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 12:46:51 +03:30

36 lines
860 B
TypeScript

"use client";
import { create } from "zustand";
import { sound } from "./sound";
interface SoundStore {
sfx: boolean;
music: boolean;
toggleSfx: () => void;
toggleMusic: () => void;
/** Master mute: turns BOTH sfx and music off (or both back on). */
toggleAll: () => void;
}
export const useSoundStore = create<SoundStore>((set, get) => ({
sfx: sound.sfxEnabled,
music: sound.musicEnabled,
toggleSfx: () => {
const v = !get().sfx;
sound.setSfxEnabled(v);
set({ sfx: v });
},
toggleMusic: () => {
const v = !get().music;
sound.setMusicEnabled(v);
set({ music: v });
},
toggleAll: () => {
// If anything is on, mute everything; otherwise turn everything back on.
const v = !(get().sfx || get().music);
sound.setSfxEnabled(v);
sound.setMusicEnabled(v);
set({ sfx: v, music: v });
},
}));