UNPKG

react-trophies

Version:

Comprehensive achievement and trophy system for React apps with sound effects, notifications, theming, and visual components. Uses React, React-DOM, Sonner (toast notifications), Howler (sound effects), Zustand (state management), React-Confetti (celebrat

93 lines (92 loc) 3.1 kB
/** * Interface for sound options */ export interface SoundOptions { /** Volume level (0.0 to 1.0) */ volume?: number; /** Whether the sound should loop */ loop?: boolean; /** Whether the sound should preload */ preload?: boolean; /** Callback when sound is loaded */ onload?: () => void; /** Callback when sound ends */ onend?: () => void; } /** * SoundManager - Utility class for managing achievement sounds * Uses howler.js for cross-browser sound support */ declare class SoundManager { /** Collection of sound instances */ private sounds; /** Whether sound is globally enabled */ private enabled; /** Global volume level */ private globalVolume; /** Default sound URLs */ private defaultSounds; /** * Initialize the SoundManager with default sounds * @param defaultSounds - Optional custom default sounds to use * @param enabled - Whether sound should start enabled */ constructor(defaultSounds?: Record<string, string>, enabled?: boolean); /** * Register a new sound with the manager * @param id - Unique identifier for the sound * @param url - URL or array of URLs (for fallbacks) to the sound file * @param options - Additional sound options * @returns The sound manager instance for chaining */ registerSound(id: string, url: string | string[], options?: SoundOptions): SoundManager; /** * Play a registered sound * @param id - ID of the sound to play * @param volume - Optional volume override for this specific play * @returns Sound ID if sound was played, undefined otherwise */ play(id: string, volume?: number): number | undefined; /** * Stop a specific sound or all sounds * @param id - ID of sound to stop, or undefined to stop all sounds * @returns The sound manager instance for chaining */ stop(id?: string): SoundManager; /** * Set the global volume for all sounds * @param volume - Volume level (0.0 to 1.0) * @returns The sound manager instance for chaining */ setVolume(volume: number): SoundManager; /** * Enable or disable all sounds * @param enabled - Whether sounds should be enabled * @returns The sound manager instance for chaining */ setEnabled(enabled: boolean): SoundManager; /** * Check if sounds are enabled * @returns Whether sounds are currently enabled */ isEnabled(): boolean; /** * Get a list of all registered sound IDs * @returns Array of sound IDs */ getSoundIds(): string[]; /** * Check if a sound with the given ID exists * @param id - Sound ID to check * @returns Whether the sound exists */ hasSound(id: string): boolean; /** * Play the achievement unlock sound * @param volume - Optional volume override * @returns Sound ID if played, undefined otherwise */ playUnlockSound(volume?: number): number | undefined; } export declare const soundManager: SoundManager; export default soundManager;