import { TransformNode } from '@babylonjs/core'; import { GameEntityBehavior } from "../classes/entity.d.ts"; import { GameEngine } from "../classes/gameEngine.d.ts"; import { GameEvent } from "../classes/eventBus.d.ts"; /** * Configuration for a single sound. */ export interface SoundConfig { /** Path to the sound file */ url: string; /** Volume level (0-1), default 1 */ volume?: number; /** Whether to loop the sound, default false */ loop?: boolean; /** Whether to use spatial 3D audio, default false */ spatial?: boolean; /** Maximum distance for spatial audio, default 100 */ maxDistance?: number; /** Whether to autoplay when registered, default false */ autoplay?: boolean; /** Audio channel name (e.g., 'sfx', 'music'). Used with AudioManager. */ channel?: string; } /** * State interface for entities using SoundBehavior. * Entity state should include a `sounds` property with sound configurations. */ export interface SoundEntityState { /** Map of sound name to configuration */ sounds?: Record; } /** * Behavior for managing sounds on an entity. * * Sounds are configured in the entity's state under the `sounds` property. * The behavior creates sounds via AudioManager (BabylonJS AudioV2). * * Requires AudioManager to be configured on the GameEngine. If no AudioManager is found, * a warning is logged and no sounds are created. * * @example * ```typescript * // Entity definition * { * type: 'player', * behaviors: [SoundBehavior, ...], * defaultState: { * sounds: { * jump: { url: 'sounds/jump.mp3', volume: 0.8, channel: 'sfx' }, * footstep: { url: 'sounds/footstep.mp3', loop: true, channel: 'sfx' } * } * } * } * * // In another behavior, get the sound behavior and control sounds * const soundBehavior = entity.getBehavior(SoundBehavior); * soundBehavior?.play('jump'); * ``` */ export declare class SoundBehavior extends GameEntityBehavior { name: string; eventSubscriptions: string[]; /** Map of sound name to StaticSound instance */ private _sounds; /** Whether sounds have been initialized */ private _initialized; /** AudioManager reference */ private _audioManager; /** Node reference for spatial detach on cleanup */ private _node; private _log; onNodeAttached(node: TransformNode, gameEngine: GameEngine): void; processEvent(_event: GameEvent, _state: SoundEntityState): boolean; onReset(_state: SoundEntityState): void; destroy(): Promise; private _createSound; private _disposeSounds; /** * Play a sound by name. * * @param name - The name of the sound to play. If omitted and only one sound exists, plays that sound. * @param time - Optional time offset in seconds to start playing from */ play(name?: string, time?: number): void; /** * Stop a sound by name. * * @param name - The name of the sound to stop. If omitted, stops all sounds. */ stop(name?: string): void; /** * Pause a sound by name. * * @param name - The name of the sound to pause. If omitted and only one sound exists, pauses that sound. */ pause(name?: string): void; /** * Set the volume of a sound. * * @param volume - Volume level (0-1) * @param name - The name of the sound. If omitted, sets volume for all sounds. */ setVolume(volume: number, name?: string): void; /** * Check if a sound is currently playing. * * @param name - The name of the sound. If omitted and only one sound exists, checks that sound. */ isPlaying(name?: string): boolean; /** * Get all registered sound names. */ getSoundNames(): string[]; /** * Check if a sound with the given name exists. * * @param name */ hasSound(name: string): boolean; /** * Register a new sound at runtime. Replaces any existing sound with the same name. * * @param name * @param config */ registerSound(name: string, config: SoundConfig): void; /** * Unregister and dispose a sound. * * @param name */ unregisterSound(name: string): void; /** * Get a sound by name. If name is omitted and only one sound exists, returns that sound. */ private _getSound; }