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
@@ -21,6 +21,9 @@ var id: String = _generate_uuid()
|
||||
|
||||
var is_first_point: bool = true
|
||||
var character: Texture = load(NO_CHARACTER_PATH)
|
||||
## The name of the picked character, its picture's file name, or empty when none is
|
||||
## picked. Saved with the quiz, so the picture can be found again after a restart.
|
||||
var character_name: String = ""
|
||||
|
||||
|
||||
func _init(new_name: String) -> void:
|
||||
@@ -28,6 +31,39 @@ func _init(new_name: String) -> void:
|
||||
player_score = 0
|
||||
|
||||
|
||||
## Shows [param texture], the character called [param new_name], for the player.
|
||||
func set_character(texture: Texture, new_name: String) -> void:
|
||||
character = texture
|
||||
character_name = new_name
|
||||
|
||||
|
||||
## Goes back to no character, e.g. when the characters come from somewhere else.
|
||||
func clear_character() -> void:
|
||||
character = load(NO_CHARACTER_PATH)
|
||||
character_name = ""
|
||||
|
||||
|
||||
## The player as a Dictionary that can be written as JSON, for [QuizSave].
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"id": id, "name": player_name, "score": player_score,
|
||||
"is_first_point": is_first_point, "character": character_name,
|
||||
}
|
||||
|
||||
|
||||
## A player made from [param data], as given by [method to_dict], or null when
|
||||
## [param data] is not a player. The character's picture is not loaded here.
|
||||
static func from_dict(data: Variant) -> PlayerObject:
|
||||
if !(data is Dictionary) || !(data.get("name") is String) || !(data.get("id") is String):
|
||||
return null
|
||||
var player: PlayerObject = PlayerObject.new(data.name)
|
||||
player.id = data.id
|
||||
player.player_score = maxi(int(data.get("score", 0)), 0)
|
||||
player.is_first_point = bool(data.get("is_first_point", player.player_score == 0))
|
||||
player.character_name = str(data.get("character", ""))
|
||||
return player
|
||||
|
||||
|
||||
## Returns a random version 4 UUID, e.g. "3f2b8c1e-9a4d-4e7f-b2c6-5d8e1f0a7b93".
|
||||
static func _generate_uuid() -> String:
|
||||
var bytes: PackedByteArray = Crypto.new().generate_random_bytes(16)
|
||||
|
||||
Reference in new issue
Block a user