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
@@ -0,0 +1,47 @@
|
||||
class_name FolderCharacters
|
||||
extends RefCounted
|
||||
## Characters read from a folder on this computer instead of the server: every PNG, JPG
|
||||
## or WebP picture in it is a character, named by its file name.
|
||||
##
|
||||
## Has the same two calls as [CharacterCache], so the character select popup uses either.
|
||||
|
||||
## The file endings of the pictures that are characters.
|
||||
const PICTURE_EXTENSIONS: Array[String] = ["png", "jpg", "jpeg", "webp"]
|
||||
|
||||
## The folder the pictures are in.
|
||||
var path: String = ""
|
||||
|
||||
|
||||
func _init(folder_path: String) -> void:
|
||||
path = folder_path
|
||||
|
||||
|
||||
## The file names of the pictures in [param folder], in natural order. Hidden files and
|
||||
## other files are left out.
|
||||
static func picture_names(folder: String) -> Array[String]:
|
||||
var names: Array[String] = []
|
||||
for file_name: String in DirAccess.get_files_at(folder):
|
||||
if !file_name.begins_with(".") \
|
||||
&& PICTURE_EXTENSIONS.has(file_name.get_extension().to_lower()):
|
||||
names.append(file_name)
|
||||
names.sort_custom(func(a: String, b: String) -> bool: return a.naturalnocasecmp_to(b) < 0)
|
||||
return names
|
||||
|
||||
|
||||
## Calls [param on_done] with the names of the characters as an [code]Array[String][/code].
|
||||
func load_list(on_done: Callable) -> void:
|
||||
on_done.call(picture_names(path))
|
||||
|
||||
|
||||
## Calls [param on_done] with the picture of [param character_name] as an [Image]. Nothing
|
||||
## is called when the picture is gone or can't be read.
|
||||
func fetch_image(character_name: String, on_done: Callable) -> void:
|
||||
var file: String = path.path_join(character_name.validate_filename())
|
||||
if !FileAccess.file_exists(file):
|
||||
GameLog.warning("The picture of ", character_name, " is not in ", path)
|
||||
return
|
||||
var picture: Image = CharacterCard.image_from_bytes(FileAccess.get_file_as_bytes(file))
|
||||
if picture == null:
|
||||
GameLog.warning("Could not read the picture ", file)
|
||||
return
|
||||
on_done.call(picture)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bc2nkmd162ibl
|
||||
Reference in new issue
Block a user