feat(audio): swap to repair music while a mission is in repair flow
Switch background music to musique-reparation.mp3 whenever any mission (ebike / pylon / farm) is in the repair mini-game step range (inspected → done) and back to musique-jeu.mp3 once the mission leaves that range. Reuses AudioManager.playMusic which handles the swap cleanly when the path changes.
This commit is contained in:
+31
-2
@@ -1,14 +1,43 @@
|
||||
import { useEffect } from "react";
|
||||
import { AudioManager } from "@/managers/AudioManager";
|
||||
import { useGameStore } from "@/managers/stores/useGameStore";
|
||||
import type { MissionStep } from "@/types/gameplay/repairMission";
|
||||
|
||||
const GAME_MUSIC_PATH = "/sounds/musique/musique-jeu.mp3";
|
||||
const GAME_MUSIC_VOLUME = 0.33;
|
||||
const REPAIR_MUSIC_PATH = "/sounds/musique/musique-reparation.mp3";
|
||||
const MUSIC_VOLUME = 0.33;
|
||||
|
||||
// Steps during which the repair mini-game owns the experience.
|
||||
// Triggered when any mission (ebike / pylon / farm) is in this range.
|
||||
const REPAIR_MUSIC_STEPS: ReadonlySet<MissionStep> = new Set([
|
||||
"inspected",
|
||||
"fragmented",
|
||||
"scanning",
|
||||
"repairing",
|
||||
"reassembling",
|
||||
"done",
|
||||
]);
|
||||
|
||||
export function GameMusic(): null {
|
||||
const ebikeStep = useGameStore((state) => state.ebike.currentStep);
|
||||
const pylonStep = useGameStore((state) => state.pylon.currentStep);
|
||||
const farmStep = useGameStore((state) => state.farm.currentStep);
|
||||
|
||||
const inRepair =
|
||||
REPAIR_MUSIC_STEPS.has(ebikeStep) ||
|
||||
REPAIR_MUSIC_STEPS.has(pylonStep) ||
|
||||
REPAIR_MUSIC_STEPS.has(farmStep);
|
||||
|
||||
useEffect(() => {
|
||||
const audio = AudioManager.getInstance();
|
||||
audio.playMusic(GAME_MUSIC_PATH, GAME_MUSIC_VOLUME);
|
||||
audio.playMusic(
|
||||
inRepair ? REPAIR_MUSIC_PATH : GAME_MUSIC_PATH,
|
||||
MUSIC_VOLUME,
|
||||
);
|
||||
}, [inRepair]);
|
||||
|
||||
useEffect(() => {
|
||||
const audio = AudioManager.getInstance();
|
||||
return () => {
|
||||
audio.stopMusic();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user