Add offline mode: play from a music folder instead of the server
Build / test (push) Successful in 1m2s
Build / build (push) Successful in 1m12s

Settings has a Music folder row. A folder with subfolders is played as
soundtracks: Next picks a random subfolder and a random song in it, the
subfolder is the answer's soundtrack and the file name without its type the
song. The inspiration list and Search show the subfolders.

A folder with songs and no subfolders is a prepared quiz, played once in order
(natural sort) or at random, showing only the song title. It has no winning
score: after the last song Next becomes Show winner, and the players with the
most points win, ties included.

While a folder is used nothing but the characters is asked from the server:
Sync, QR, Statistics, the update check and play counting are off. Characters
fall back to the cached pictures when the server can't be reached. mp3, ogg and
wav play; other files and broken ones are skipped.

The old local playback code, the hidden Open button and the hidden Local toggle
are removed. Next now waits for the song to start before preparing the next one.
This commit is contained in:
Sansan committed 2026-10-07 23:07:47 +02:00
1 parent b120440404
commit 222d231b1b
42 files changed
+8245 -474

No files matched your search

+41 -2
View File
@@ -1,7 +1,8 @@
class_name SongLoader
extends Node
## Downloads songs from the server into the Playlist ahead of time, so the next song
## can start at once.
## can start at once. With a music folder (see [method Settings.is_offline]) the songs are
## picked from the folder instead.
##
## How many songs it keeps ready is the cache size in the settings
## ([code]Playlist.number_of_tracks_to_preload[/code]).
@@ -22,7 +23,12 @@ var retry_seconds: float = 5.0
## Preloading waits for the list, because loading the list clears the playlist.
func load_song_list() -> void:
GameLog.debug("load_song_list")
if Settings.is_offline():
_start_folder_playlist()
return
var song_list_fetched: Callable = func song_list_fetched(songs: Array[SongInfo]) -> void:
if Settings.is_offline():
return
Playlist.clear_song_list()
for info: SongInfo in songs:
var new_song_object: SongObject = SongObject.new()
@@ -43,6 +49,9 @@ func load_song_list() -> void:
## Starts downloading one more song, which keeps downloading until the cache is full.
func fetch_song() -> void:
GameLog.debug("fetch_song")
if Settings.is_offline():
_add_folder_songs()
return
Playlist.is_song_downloading = true
_download_random_song(SongObject.new())
@@ -65,6 +74,9 @@ func fill_cache() -> void:
func _download_random_song(new_song_object: SongObject) -> void:
var song_downloaded: Callable = func song_downloaded(body: PackedByteArray) -> void:
GameLog.debug("song_downloaded")
# A music folder was picked while the song was downloading
if Settings.is_offline():
return
Playlist.store_song(new_song_object, body)
_add_song_to_queue(new_song_object)
MusicServerClient.fetch_random_song(Settings.use_low_played_mode, song_downloaded,
@@ -79,6 +91,8 @@ func _add_song_to_queue(new_song_object: SongObject) -> void:
func _fetch_song_info(new_song_object: SongObject) -> void:
var song_info_fetched: Callable = func song_info_fetched(info: SongInfo) -> void:
GameLog.debug("song_info_fetched")
if Settings.is_offline():
return
new_song_object.song_number = info.song_no
new_song_object.soundtrack_title = info.soundtrack
new_song_object.song_title = info.song
@@ -95,4 +109,29 @@ func _fetch_song_info(new_song_object: SongObject) -> void:
func _retry_later(step: Callable) -> void:
GameLog.warning("Song download failed, retrying in %s seconds" % retry_seconds)
get_tree().create_timer(retry_seconds).timeout.connect(step)
get_tree().create_timer(retry_seconds).timeout.connect(func() -> void:
if !Settings.is_offline():
step.call())
# A music folder has no playlist on a server, so the game starts with an empty one
func _start_folder_playlist() -> void:
Playlist.clear_song_list()
Playlist.update_last_played_song()
Playlist.game_start_song = 0
Playlist.is_song_downloading = false
song_list_loaded.emit()
fetch_song_if_idle()
# Picks songs from the music folder until enough are ready. A prepared quiz runs out
# when every song is in the playlist.
func _add_folder_songs() -> void:
Playlist.is_song_downloading = false
while Playlist.should_preload_more_songs():
var song_object: SongObject = Settings.music_folder.next_song()
if song_object == null:
return
song_object.song_number = Playlist.song_object_array.size()
Playlist.add_to_playlist(song_object)
song_added.emit()