add new maps, persistent storage, music toggle button
This commit is contained in:
55
audio.sex
55
audio.sex
@@ -1,4 +1,6 @@
|
||||
(include raylib.h)
|
||||
(include string.h)
|
||||
(import storage)
|
||||
|
||||
(define MENU-CLICK-FILE "res/music/01 - Menu.ogg")
|
||||
(define FISHING-SPOT-FILE "res/music/02 - Fishing Spot.ogg")
|
||||
@@ -20,6 +22,41 @@
|
||||
;; NULL when no music is playing
|
||||
(var current-music (* Music) NULL)
|
||||
(var audio-unlocked bool false)
|
||||
(var music-enabled bool true)
|
||||
|
||||
(fn apply-music-volume () void
|
||||
(if (!= current-music NULL)
|
||||
(do
|
||||
(var volume float 0.0f)
|
||||
(if music-enabled
|
||||
(= volume 1.0f))
|
||||
(SetMusicVolume (* current-music) volume))))
|
||||
|
||||
(fn load-music-setting () void
|
||||
(var path (* const char) (storage-settings-path))
|
||||
(if (== path NULL)
|
||||
(return))
|
||||
(var text (* char) (LoadFileText path))
|
||||
(if (== text NULL)
|
||||
(return))
|
||||
(if (!= (strstr text "music=0") NULL)
|
||||
(= music-enabled false))
|
||||
(UnloadFileText text)
|
||||
(if music-enabled
|
||||
(TraceLog LOG-INFO "music setting: on")
|
||||
(TraceLog LOG-INFO "music setting: off")))
|
||||
|
||||
(fn save-music-setting () void
|
||||
(var path (* const char) (storage-settings-path))
|
||||
(if (== path NULL)
|
||||
(return))
|
||||
(var ok bool false)
|
||||
(if music-enabled
|
||||
(= ok (SaveFileText path "music=1\n"))
|
||||
(= ok (SaveFileText path "music=0\n")))
|
||||
(if (! ok)
|
||||
(TraceLog LOG-WARNING "failed to save music setting to \"%s\"" path))
|
||||
(storage-sync))
|
||||
|
||||
(fn load-sound ((file (* const char))) Sound
|
||||
(var sound Sound (LoadSound file))
|
||||
@@ -34,6 +71,7 @@
|
||||
(return music))
|
||||
|
||||
(pub fn audio-init () void
|
||||
(load-music-setting)
|
||||
(= menu-click (load-sound MENU-CLICK-FILE))
|
||||
(= fishing-spot-sound (load-sound FISHING-SPOT-FILE))
|
||||
(= fishing-start-sound (load-sound FISHING-START-FILE))
|
||||
@@ -64,7 +102,8 @@
|
||||
(if (IsMusicValid (* music))
|
||||
(do
|
||||
(= current-music music)
|
||||
(PlayMusicStream (* music)))))
|
||||
(PlayMusicStream (* music))
|
||||
(apply-music-volume))))
|
||||
|
||||
(pub fn audio-update () void
|
||||
(if (!= current-music NULL)
|
||||
@@ -79,6 +118,17 @@
|
||||
(pub fn audio-play-fishing-music () void
|
||||
(switch-music (& fishing-music)))
|
||||
|
||||
(pub fn audio-music-enabled () bool
|
||||
(return music-enabled))
|
||||
|
||||
(pub fn audio-toggle-music () void
|
||||
(= music-enabled (! music-enabled))
|
||||
(apply-music-volume)
|
||||
(save-music-setting)
|
||||
(if music-enabled
|
||||
(TraceLog LOG-INFO "music setting: on")
|
||||
(TraceLog LOG-INFO "music setting: off")))
|
||||
|
||||
;; 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
|
||||
@@ -89,7 +139,8 @@
|
||||
(if (!= current-music NULL)
|
||||
(do
|
||||
(StopMusicStream (* current-music))
|
||||
(PlayMusicStream (* current-music)))))
|
||||
(PlayMusicStream (* current-music))
|
||||
(apply-music-volume))))
|
||||
|
||||
#-emscripten
|
||||
(pub fn audio-unlock () void
|
||||
|
||||
Reference in New Issue
Block a user