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
@@ -200,3 +200,124 @@ func test_display_name_is_the_folder_name() -> void:
|
||||
var folder: MusicFolder = _folder("Musiktävling 2025/")
|
||||
|
||||
assert_str(folder.display_name()).is_equal("Musiktävling 2025")
|
||||
|
||||
|
||||
# A quiz's own characters
|
||||
|
||||
func _picture(relative_path: String) -> void:
|
||||
_file(relative_path, Image.create(8, 4, false, Image.FORMAT_RGB8).save_png_to_buffer())
|
||||
|
||||
|
||||
func test_prepared_quiz_with_a_characters_folder_is_still_a_prepared_quiz() -> void:
|
||||
_song("01. Jingle Bells.mp3")
|
||||
_song("02. Last Christmas.mp3")
|
||||
_picture("characters/Santa.png")
|
||||
|
||||
var folder: MusicFolder = _folder()
|
||||
|
||||
assert_int(folder.kind).is_equal(MusicFolder.Kind.PREPARED_QUIZ)
|
||||
assert_int(folder.quiz_size()).is_equal(2)
|
||||
assert_str(folder.characters_path).is_equal(_root.path_join("characters"))
|
||||
|
||||
|
||||
func test_characters_folder_is_not_a_soundtrack() -> void:
|
||||
_song("Chrono Trigger/Corridors of Time.mp3")
|
||||
_picture("Characters/Frog.png")
|
||||
|
||||
var folder: MusicFolder = _folder()
|
||||
|
||||
assert_int(folder.kind).is_equal(MusicFolder.Kind.SOUNDTRACKS)
|
||||
assert_array(folder.soundtrack_names()).contains_exactly(["Chrono Trigger"])
|
||||
assert_str(folder.characters_path).is_equal(_root.path_join("Characters"))
|
||||
|
||||
|
||||
func test_characters_folder_without_pictures_is_not_used() -> void:
|
||||
_song("01. Opening.mp3")
|
||||
_file("characters/notes.txt", "not a picture".to_utf8_buffer())
|
||||
|
||||
var folder: MusicFolder = _folder()
|
||||
|
||||
assert_int(folder.kind).is_equal(MusicFolder.Kind.PREPARED_QUIZ)
|
||||
assert_str(folder.characters_path).is_empty()
|
||||
|
||||
|
||||
func test_only_a_characters_folder_is_nothing_to_play() -> void:
|
||||
_picture("characters/Santa.png")
|
||||
|
||||
assert_int(_folder().kind).is_equal(MusicFolder.Kind.EMPTY)
|
||||
|
||||
|
||||
func test_folder_without_characters_has_no_characters_path() -> void:
|
||||
_song("Chrono Trigger/Corridors of Time.mp3")
|
||||
|
||||
assert_str(_folder().characters_path).is_empty()
|
||||
|
||||
|
||||
# Continuing a prepared quiz
|
||||
|
||||
func _prepared_quiz(songs: int) -> MusicFolder:
|
||||
for i: int in songs:
|
||||
_song("%02d. Song.mp3" % (i + 1))
|
||||
return _folder()
|
||||
|
||||
|
||||
func test_prepared_quiz_continues_where_it_was() -> void:
|
||||
var folder: MusicFolder = _prepared_quiz(4)
|
||||
folder.next_song()
|
||||
folder.next_song()
|
||||
|
||||
var again: MusicFolder = _folder()
|
||||
assert_bool(again.restore_progress(folder.progress())).is_true()
|
||||
|
||||
assert_str(again.next_song().song_title).is_equal("03. Song")
|
||||
assert_str(again.next_song().song_title).is_equal("04. Song")
|
||||
assert_object(again.next_song()).is_null()
|
||||
|
||||
|
||||
func test_random_prepared_quiz_continues_in_the_same_order() -> void:
|
||||
var folder: MusicFolder = _prepared_quiz(8)
|
||||
folder.set_play_order(MusicFolder.PlayOrder.RANDOM)
|
||||
folder.next_song()
|
||||
var saved: Dictionary = JSON.parse_string(JSON.stringify(folder.progress()))
|
||||
var expected: Array[String] = []
|
||||
for i: int in 7:
|
||||
expected.append(folder.next_song().song_title)
|
||||
|
||||
var again: MusicFolder = _folder()
|
||||
again.restore_progress(saved)
|
||||
|
||||
assert_int(again.play_order).is_equal(MusicFolder.PlayOrder.RANDOM)
|
||||
var titles: Array[String] = []
|
||||
for i: int in 7:
|
||||
titles.append(again.next_song().song_title)
|
||||
assert_array(titles).contains_exactly(expected)
|
||||
|
||||
|
||||
func test_songs_removed_from_the_folder_are_left_out_when_continuing() -> void:
|
||||
var folder: MusicFolder = _prepared_quiz(4)
|
||||
folder.next_song()
|
||||
folder.next_song()
|
||||
var saved: Dictionary = folder.progress()
|
||||
# One played song and one still to play are gone
|
||||
DirAccess.remove_absolute(_root.path_join("01. Song.mp3"))
|
||||
DirAccess.remove_absolute(_root.path_join("04. Song.mp3"))
|
||||
|
||||
var again: MusicFolder = _folder()
|
||||
again.restore_progress(saved)
|
||||
|
||||
assert_str(again.next_song().song_title).is_equal("03. Song")
|
||||
assert_object(again.next_song()).is_null()
|
||||
|
||||
|
||||
func test_progress_that_does_not_fit_changes_nothing() -> void:
|
||||
var folder: MusicFolder = _prepared_quiz(2)
|
||||
|
||||
assert_bool(folder.restore_progress({})).is_false()
|
||||
assert_bool(folder.restore_progress({"queue": "nope", "next": 1})).is_false()
|
||||
assert_str(folder.next_song().song_title).is_equal("01. Song")
|
||||
|
||||
|
||||
func test_soundtrack_folder_has_no_progress_to_continue() -> void:
|
||||
_song("Chrono Trigger/Corridors of Time.mp3")
|
||||
|
||||
assert_bool(_folder().restore_progress({"queue": [], "next": 0})).is_false()
|
||||
Reference in new issue
Block a user