diff --git a/audio.sex b/audio.sex index 1c5e8e2..1a87cc3 100644 --- a/audio.sex +++ b/audio.sex @@ -15,6 +15,7 @@ ;; NULL when no music is playing (var current-music (* Music) NULL) +(var audio-unlocked bool false) (fn load-sound ((file (* const char))) Sound (var sound Sound (LoadSound file)) @@ -70,7 +71,24 @@ (pub fn audio-play-fishing-music () void (switch-music (& fishing-music))) +;; Browsers keep the audio context suspended until the first user gesture. +;; Restart the current track once after that gesture so the music actually begins. +#+emscripten +(pub fn audio-unlock () void + (if audio-unlocked + (return)) + (= audio-unlocked true) + (if (!= current-music NULL) + (do + (StopMusicStream (* current-music)) + (PlayMusicStream (* current-music))))) + +#-emscripten +(pub fn audio-unlock () void + (return)) + (pub fn audio-play-menu-click () void + (audio-unlock) (if (IsSoundValid menu-click) (PlaySound menu-click))) diff --git a/menu.sex b/menu.sex index 59aef96..256501a 100644 --- a/menu.sex +++ b/menu.sex @@ -67,7 +67,10 @@ (= clicked true) (.quit (. state app-state)))) - ;; Any menu key press is a UI interaction too + ;; Any menu key press or click is a UI interaction too (var key-pressed bool (!= 0 (GetKeyPressed))) + (var mouse-pressed bool (IsMouseButtonPressed MOUSE-BUTTON-LEFT)) + (if (|| mouse-pressed key-pressed) + (audio-unlock)) (if (|| clicked key-pressed) (audio-play-menu-click))) diff --git a/shell.html b/shell.html index 5380a49..20f928b 100644 --- a/shell.html +++ b/shell.html @@ -47,6 +47,17 @@

Instructions go here.