0a3ffa6314
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>
36 lines
860 B
TypeScript
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 });
|
|
},
|
|
}));
|