add: type audio playback cat

This commit is contained in:
Tom Boullay
2026-05-09 23:30:14 +01:00
parent b0bb127459
commit e0adb84eca
3 changed files with 13 additions and 2 deletions
@@ -70,7 +70,9 @@ export function RepairCaseObject({
label={open ? "Mallette inspectée" : "Inspecter la mallette"} label={open ? "Mallette inspectée" : "Inspecter la mallette"}
onTrigger={() => { onTrigger={() => {
if (open) return; if (open) return;
AudioManager.getInstance().playSound(REPAIR_CASE_OPEN_SOUND_PATH); AudioManager.getInstance().playSound(REPAIR_CASE_OPEN_SOUND_PATH, 1, {
category: "sfx",
});
onInspect(); onInspect();
}} }}
> >
@@ -69,7 +69,9 @@ export function TriggerObject({
position={position} position={position}
onPress={() => { onPress={() => {
if (soundPath) { if (soundPath) {
AudioManager.getInstance().playSound(soundPath, soundVolume); AudioManager.getInstance().playSound(soundPath, soundVolume, {
category: "sfx",
});
} }
onTrigger?.(); onTrigger?.();
+7
View File
@@ -1,6 +1,10 @@
import { logger } from "@/utils/core/logger"; import { logger } from "@/utils/core/logger";
export type AudioCategory = "music" | "sfx" | "dialogue";
export type OneShotAudioCategory = Exclude<AudioCategory, "music">;
interface PlaySoundOptions { interface PlaySoundOptions {
category?: OneShotAudioCategory;
playbackRate?: number; playbackRate?: number;
} }
@@ -12,6 +16,7 @@ export class AudioManager {
private _musicUnlockHandler: (() => void) | null = null; private _musicUnlockHandler: (() => void) | null = null;
private static readonly MAX_POOL_SIZE_PER_SOUND = 6; 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([ private static readonly IGNORED_PLAYBACK_ERRORS = new Set([
"AbortError", "AbortError",
"NotAllowedError", "NotAllowedError",
@@ -29,6 +34,7 @@ export class AudioManager {
playSound(path: string, volume = 1, options: PlaySoundOptions = {}): void { playSound(path: string, volume = 1, options: PlaySoundOptions = {}): void {
const audio = this._acquireAudio(path); const audio = this._acquireAudio(path);
const category = options.category ?? AudioManager.DEFAULT_SOUND_CATEGORY;
audio.volume = Math.max(0, Math.min(1, volume)); audio.volume = Math.max(0, Math.min(1, volume));
audio.playbackRate = options.playbackRate ?? 1; audio.playbackRate = options.playbackRate ?? 1;
audio.currentTime = 0; audio.currentTime = 0;
@@ -43,6 +49,7 @@ export class AudioManager {
logger.error("AudioManager", "Failed to play sound", { logger.error("AudioManager", "Failed to play sound", {
path, path,
category,
error: AudioManager._toLogValue(error), error: AudioManager._toLogValue(error),
}); });
}); });