From 53add29a486d9eb4328d970b603e88026bd30e8a Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Sat, 9 May 2026 23:30:14 +0100 Subject: [PATCH] add: type audio playback cat --- src/components/three/gameplay/RepairCaseObject.tsx | 4 +++- src/components/three/interaction/TriggerObject.tsx | 4 +++- src/managers/AudioManager.ts | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/three/gameplay/RepairCaseObject.tsx b/src/components/three/gameplay/RepairCaseObject.tsx index 2307794..97987f2 100644 --- a/src/components/three/gameplay/RepairCaseObject.tsx +++ b/src/components/three/gameplay/RepairCaseObject.tsx @@ -70,7 +70,9 @@ export function RepairCaseObject({ label={open ? "Mallette inspectée" : "Inspecter la mallette"} onTrigger={() => { if (open) return; - AudioManager.getInstance().playSound(REPAIR_CASE_OPEN_SOUND_PATH); + AudioManager.getInstance().playSound(REPAIR_CASE_OPEN_SOUND_PATH, 1, { + category: "sfx", + }); onInspect(); }} > diff --git a/src/components/three/interaction/TriggerObject.tsx b/src/components/three/interaction/TriggerObject.tsx index 77f4cc6..599cc2f 100644 --- a/src/components/three/interaction/TriggerObject.tsx +++ b/src/components/three/interaction/TriggerObject.tsx @@ -69,7 +69,9 @@ export function TriggerObject({ position={position} onPress={() => { if (soundPath) { - AudioManager.getInstance().playSound(soundPath, soundVolume); + AudioManager.getInstance().playSound(soundPath, soundVolume, { + category: "sfx", + }); } onTrigger?.(); diff --git a/src/managers/AudioManager.ts b/src/managers/AudioManager.ts index 6c2a534..e0237b4 100644 --- a/src/managers/AudioManager.ts +++ b/src/managers/AudioManager.ts @@ -1,6 +1,10 @@ import { logger } from "@/utils/core/logger"; +export type AudioCategory = "music" | "sfx" | "dialogue"; +export type OneShotAudioCategory = Exclude; + interface PlaySoundOptions { + category?: OneShotAudioCategory; playbackRate?: number; } @@ -12,6 +16,7 @@ export class AudioManager { private _musicUnlockHandler: (() => void) | null = null; private static readonly MAX_POOL_SIZE_PER_SOUND = 6; + private static readonly DEFAULT_SOUND_CATEGORY: OneShotAudioCategory = "sfx"; private static readonly IGNORED_PLAYBACK_ERRORS = new Set([ "AbortError", "NotAllowedError", @@ -29,6 +34,7 @@ export class AudioManager { playSound(path: string, volume = 1, options: PlaySoundOptions = {}): void { const audio = this._acquireAudio(path); + const category = options.category ?? AudioManager.DEFAULT_SOUND_CATEGORY; audio.volume = Math.max(0, Math.min(1, volume)); audio.playbackRate = options.playbackRate ?? 1; audio.currentTime = 0; @@ -43,6 +49,7 @@ export class AudioManager { logger.error("AudioManager", "Failed to play sound", { path, + category, error: AudioManager._toLogValue(error), }); });