From 1cc3b0e47e53f62d90beaef4c40d4ca3c5e45ffe Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Wed, 3 Jun 2026 01:00:29 +0200 Subject: [PATCH] feat(audio): swap to repair music while a mission is in repair flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/world/GameMusic.tsx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/world/GameMusic.tsx b/src/world/GameMusic.tsx index c804f88..ade6f9e 100644 --- a/src/world/GameMusic.tsx +++ b/src/world/GameMusic.tsx @@ -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 = 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(); };