add: type audio playback cat
This commit is contained in:
@@ -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?.();
|
||||||
|
|||||||
@@ -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),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user