From 254dbaf2fd03244882d1778cbd7b065ce5b4d56e Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Sat, 1 Nov 2025 11:36:18 +0100 Subject: [PATCH] traffic light: every color has its own buzz sound volume --- src/App/Plant/TrafficLight/TrafficLight.tsx | 22 +++++++++++---------- src/App/useAudioContext.ts | 9 ++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/App/Plant/TrafficLight/TrafficLight.tsx b/src/App/Plant/TrafficLight/TrafficLight.tsx index 8ffd4da..b014573 100644 --- a/src/App/Plant/TrafficLight/TrafficLight.tsx +++ b/src/App/Plant/TrafficLight/TrafficLight.tsx @@ -40,21 +40,23 @@ export const TrafficLight = memo(function TrafficLight({state, speed, raiseUIEve // preloadAudio(sndAtmosphere); - // the traffic light makes sound too: + // play wind useEffect(() => { const stopPlaying = playURL(sndAtmosphere, true); return () => stopPlaying(); }, []); - useEffect(() => { - if (redOn || yellowOn || greenOn) { - const stopPlaying = playURL(sndBuzz, true); - return () => { - stopPlaying(); - }; - } - else return () => {}; - }, [redOn || yellowOn || greenOn]) + // for added realism, every light color has its own buzzing noise volume + for (const [color, gain] of [[redOn, 0.5], [yellowOn, 1], [greenOn, 0.3]] as [boolean, number][]) { + useEffect(() => { + if (color) { + const stopPlaying = playURL(sndBuzz, true, gain); + return () => { + stopPlaying(); + }; + } + }, [color]); + } return <>