Save the quiz and continue it after a restart; load characters from a folder
The quiz is saved to current_quiz.json in the config folder after every change, and the game goes on where it was when it starts again: the players with their points and characters, every song with who got a point for it and whether it was played, answered or is playing, and the songs downloaded ahead with their files. The song that was playing is ready to play again. Songs whose files are gone are downloaded again. On a server, the saved songs are checked against the server's playlist. If it changed, e.g. after a sync, or another server is used, the quiz starts over with the same players. A quiz from a music folder continues offline, including how far a prepared quiz has come. A new game is saved like any other change, and a file that can't be read starts a new quiz. Characters can be read from a folder picked in Settings instead of the server, for this session. A music folder with a characters folder brings its own characters, e.g. for a themed quiz; that folder is not counted as a soundtrack. When the characters come from somewhere else, players pick their characters again. Closes #11, closes #44
This commit is contained in:
1 parent
4a934840f6
commit
e4352a9f34
33 files changed
+2886
-499
No files matched your search
+12
-9
@@ -5,8 +5,9 @@ extends Node
|
||||
## Registered as the [code]Playlist[/code] autoload.
|
||||
##
|
||||
## Downloaded songs are kept on disk in the [code]songs[/code] folder next to the
|
||||
## settings, not in memory. The folder only holds the current playlist: it is emptied when
|
||||
## the game starts and when the playlist is reset.
|
||||
## settings, not in memory. The folder only holds the current playlist: when the game
|
||||
## starts, songs the saved quiz does not use are deleted (see [QuizSave]), and the folder
|
||||
## is emptied when the playlist is reset.
|
||||
|
||||
const SONGS_FOLDER_NAME: String = "songs"
|
||||
|
||||
@@ -25,10 +26,6 @@ var game_start_song: int = 0
|
||||
var _song_files_written: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
clear_song_files()
|
||||
|
||||
|
||||
## The folder downloaded songs are kept in.
|
||||
static func songs_folder() -> String:
|
||||
return Settings.config_dir().path_join(SONGS_FOLDER_NAME)
|
||||
@@ -152,7 +149,11 @@ func add_song_to_song_object(song_no: int, mp3: PackedByteArray) -> void:
|
||||
## written, the song is kept in memory instead.
|
||||
func store_song(song_object: SongObject, mp3: PackedByteArray) -> void:
|
||||
DirAccess.make_dir_recursive_absolute(songs_folder())
|
||||
# Songs kept from a saved quiz already have files, which must not be written over
|
||||
var path: String = songs_folder().path_join("song_%d.mp3" % _song_files_written)
|
||||
while FileAccess.file_exists(path):
|
||||
_song_files_written += 1
|
||||
path = songs_folder().path_join("song_%d.mp3" % _song_files_written)
|
||||
_song_files_written += 1
|
||||
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
|
||||
if file == null:
|
||||
@@ -169,12 +170,14 @@ func store_song(song_object: SongObject, mp3: PackedByteArray) -> void:
|
||||
song_object.song_path = path
|
||||
|
||||
|
||||
## Deletes the files of the songs downloaded so far.
|
||||
func clear_song_files() -> void:
|
||||
## Deletes the files of the songs downloaded so far, except those in [param keep].
|
||||
func clear_song_files(keep: PackedStringArray = []) -> void:
|
||||
if !DirAccess.dir_exists_absolute(songs_folder()):
|
||||
return
|
||||
for file_name: String in DirAccess.get_files_at(songs_folder()):
|
||||
DirAccess.remove_absolute(songs_folder().path_join(file_name))
|
||||
var path: String = songs_folder().path_join(file_name)
|
||||
if !keep.has(path):
|
||||
DirAccess.remove_absolute(path)
|
||||
|
||||
|
||||
func song_has_played(song_no: int = latest_played_song) -> void:
|
||||
|
||||
Reference in new issue
Block a user