mirror of
https://github.com/tiennm99/vngeoguessr.git
synced 2026-10-11 03:13:56 +00:00
Nine one-shot effects on the play flow and one ambient loop, both on by default and mutable independently from every header. lib/audio.js owns the single AudioContext, the decoded-buffer cache and the two preferences. Those preferences live in module variables mirrored into localStorage rather than read back from it: a private window throws on both read and write, and re-reading before each sound turned a mute that could not be persisted into a mute that never happened. The gesture listeners stay registered for the life of the page. They open the context on the first interaction, but they are also the only thing that resumes one the browser suspended -- removing them after the first gesture left the game silent for the rest of a session once a phone had been locked. MusicPlayer mounts in the root layout, not in a page, so walking from the menu into a round does not tear down and restart the loop. It loops a decoded buffer rather than an <audio> element, which returns to sample zero and so has no seam. The game header has no room below sm for a second pair of 44px cells beside ThemeToggle's three, so sound collapses there to one mute-everything switch. Both variants stay mounted and subscribe to the preferences, or crossing the breakpoint would reveal a control showing its mount-time state. Assets are CC0 throughout, from Kenney and OpenGameArt, with per-file provenance in public/audio/SOURCES.md. The loop was chosen on a measurement: its first and last 250ms sit within 0.5dB, so the loop point carries continuous energy.
2.2 KiB
2.2 KiB