Add offline mode: play from a music folder instead of the server
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:
1 parent
b120440404
commit
222d231b1b
42 files changed
+8245
-474
No files matched your search
+38
-46
@@ -18,7 +18,6 @@ signal search_pressed
|
||||
## Emitted with a line for the game log, e.g. when a player gets a point.
|
||||
signal event_logged(text: String)
|
||||
|
||||
var songs: Array = []
|
||||
var current_player_row: PlayerRow
|
||||
|
||||
## True while statistics are off because a player won, until points are reset.
|
||||
@@ -27,8 +26,6 @@ var stats_paused_by_win: bool = false
|
||||
## Dims the window behind an open popup and keeps clicks from reaching the buttons under it.
|
||||
var popup_backdrop: PopupBackdrop
|
||||
|
||||
@onready var open_button: Button = $Open
|
||||
@onready var file_dialog: FileDialog = $FileDialog
|
||||
@onready var inspiration_list: InspirationList = $InspirationList
|
||||
@onready var now_playing: NowPlaying = $NowPlaying
|
||||
@onready var players_panel: PlayersPanel = $PlayersPanel
|
||||
@@ -47,6 +44,7 @@ func _ready() -> void:
|
||||
popup_backdrop = PopupBackdrop.add_to(self, _popups())
|
||||
song_controls.next_pressed.connect(play_next_song)
|
||||
song_controls.show_answer_pressed.connect(show_answer_pressed)
|
||||
song_controls.show_winner_pressed.connect(show_final_winners)
|
||||
toolbar.sound_test_pressed.connect(music_player.get_sound_test_song)
|
||||
toolbar.search_pressed.connect(search_pressed.emit)
|
||||
quiz_settings_button.pressed.connect(quiz_settings_card.toggle)
|
||||
@@ -63,9 +61,7 @@ func _ready() -> void:
|
||||
music_player.play_next_song.connect(play_next_song)
|
||||
music_player.update_song_list.connect(update_song_list)
|
||||
|
||||
open_button.pressed.connect(open)
|
||||
|
||||
inspiration_list.load_from_server()
|
||||
inspiration_list.load_soundtracks()
|
||||
song_loader.load_song_list()
|
||||
character_select_popup.load_characters()
|
||||
|
||||
@@ -106,7 +102,7 @@ func on_sync_finished() -> void:
|
||||
## Reloads the soundtracks, playlist and characters from the server.
|
||||
func refresh_from_server() -> void:
|
||||
GameLog.debug("refresh_from_server")
|
||||
inspiration_list.load_from_server()
|
||||
inspiration_list.load_soundtracks()
|
||||
reset_playlist()
|
||||
character_select_popup.load_characters()
|
||||
|
||||
@@ -127,13 +123,23 @@ func show_answer_pressed() -> void:
|
||||
|
||||
func play_next_song() -> void:
|
||||
GameLog.debug("play_next_song ", Playlist.latest_played_song)
|
||||
# Every song of a prepared quiz has played, e.g. when songs play on by themselves
|
||||
if Settings.is_prepared_quiz() && Playlist.first_song_played \
|
||||
&& Playlist.get_preloaded_songs() == 0:
|
||||
song_controls.show_winner_button()
|
||||
return
|
||||
if Playlist.first_song_played:
|
||||
Playlist.set_latest_played_song()
|
||||
Playlist.first_song_played = true
|
||||
music_player.play_song_object(Playlist.latest_played_song)
|
||||
if !(Playlist.get_preloaded_songs() > 0):
|
||||
song_controls.set_next_enabled(false)
|
||||
# The song counts as played once it starts, which can take a moment if another song
|
||||
# is stopping, so the next song is picked after that
|
||||
await music_player.play_song_object(Playlist.latest_played_song)
|
||||
song_loader.fetch_song_if_idle()
|
||||
if !(Playlist.get_preloaded_songs() > 0):
|
||||
if Settings.is_prepared_quiz():
|
||||
song_controls.show_winner_button()
|
||||
else:
|
||||
song_controls.set_next_enabled(false)
|
||||
|
||||
|
||||
# The quiz settings card is left out: it does not dim the quiz
|
||||
@@ -159,6 +165,10 @@ func song_object_clicked(song_no: int) -> void:
|
||||
GameLog.debug("Clicked Song Object: ", Playlist.song_object_array[song_no].to_string())
|
||||
if !Settings.character_select_open:
|
||||
if Playlist.get_song(song_no) == null:
|
||||
if Settings.is_offline():
|
||||
GameLog.warning("The song's file is gone: ",
|
||||
Playlist.song_object_array[song_no].song_path)
|
||||
return
|
||||
GameLog.debug("has no song, need to download")
|
||||
var song_downloaded: Callable = func song_downloaded(body: PackedByteArray) -> void:
|
||||
Playlist.add_song_to_song_object(song_no, body)
|
||||
@@ -174,7 +184,10 @@ func reset_playlist() -> void:
|
||||
var playlist_reset_done: Callable = func playlist_reset_done() -> void:
|
||||
Playlist.reset_playlist()
|
||||
song_loader.load_song_list()
|
||||
|
||||
if Settings.is_offline():
|
||||
Settings.music_folder.restart()
|
||||
playlist_reset_done.call()
|
||||
return
|
||||
MusicServerClient.reset_playlist(playlist_reset_done)
|
||||
|
||||
|
||||
@@ -224,6 +237,20 @@ func _on_point_taken(player_object: PlayerObject) -> void:
|
||||
update_song_list()
|
||||
|
||||
|
||||
## Shows the players with the most points as the winners, at the end of a prepared quiz.
|
||||
func show_final_winners() -> void:
|
||||
GameLog.debug("show_final_winners")
|
||||
var top_score: int = 0
|
||||
for player: PlayerObject in Settings.player_array:
|
||||
top_score = maxi(top_score, player.player_score)
|
||||
var winners: Array[PlayerObject] = []
|
||||
for player: PlayerObject in Settings.player_array:
|
||||
if player.player_score == top_score:
|
||||
winners.append(player)
|
||||
winner_popup.show_winners(winners)
|
||||
music_player.play_song(preload("res://sounds/winning.mp3"))
|
||||
|
||||
|
||||
func _on_player_won(player_object: PlayerObject) -> void:
|
||||
GameLog.debug("_on_player_won")
|
||||
winner_popup.show_winner(player_object)
|
||||
@@ -249,38 +276,3 @@ func _on_change_character_requested(new_player: PlayerRow, player_name: String)
|
||||
func _on_new_character_selected(character_texture: ImageTexture) -> void:
|
||||
GameLog.debug("_on_new_character_selected")
|
||||
current_player_row.new_character_selected(character_texture)
|
||||
|
||||
|
||||
###Local
|
||||
|
||||
var local_path: String = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns of the Patriots/2-16 Metal Gear Saga.mp3'
|
||||
|
||||
|
||||
func open() -> void:
|
||||
file_dialog.popup()
|
||||
|
||||
|
||||
func _on_file_dialog_dir_selected(path: String) -> void:
|
||||
GameLog.debug(path)
|
||||
dir_contents(path)
|
||||
|
||||
|
||||
func dir_contents(path: String) -> void:
|
||||
var dir: DirAccess = DirAccess.open(path)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name: String = dir.get_next()
|
||||
songs.clear()
|
||||
var soundtracks: Array = []
|
||||
while file_name != "":
|
||||
if dir.current_is_dir():
|
||||
#GameLog.debug("Found directory: " + file_name)
|
||||
soundtracks.append(file_name)
|
||||
else:
|
||||
#GameLog.debug("Found file: " + file_name)
|
||||
if file_name.ends_with(".mp3"):
|
||||
songs.append(path + "/" + file_name)
|
||||
file_name = dir.get_next()
|
||||
inspiration_list.show_soundtracks(soundtracks)
|
||||
else:
|
||||
GameLog.warning("An error occurred when trying to access the path.")
|
||||
Reference in new issue
Block a user