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
@@ -1,13 +1,24 @@
|
||||
class_name CharacterSelectPopup
|
||||
extends BasePopup
|
||||
## The characters players pick from, from the server or from a folder on this computer
|
||||
## (see [method Settings.characters_dir]).
|
||||
|
||||
## Emitted with the picture of the character that was picked.
|
||||
signal character_selected(texture: ImageTexture)
|
||||
## Emitted with the picture and name of the character that was picked.
|
||||
signal character_selected(texture: ImageTexture, character_name: String)
|
||||
|
||||
## Emitted when the characters come from somewhere else than before, e.g. a folder was
|
||||
## picked. Characters picked before are not in the new set.
|
||||
signal source_changed
|
||||
|
||||
var can_select_character: bool = false
|
||||
var character: PackedScene = preload("res://popups/CharacterCard.tscn")
|
||||
## Keeps the pictures on disk, so only changed ones are downloaded.
|
||||
var character_cache: CharacterCache = CharacterCache.new()
|
||||
## Where the characters shown come from: [member character_cache] or a [FolderCharacters].
|
||||
var source: RefCounted = character_cache
|
||||
## The folder the characters shown come from, or empty for the server. Null before the
|
||||
## characters were first loaded.
|
||||
var source_dir: Variant = null
|
||||
|
||||
@onready var character_panel: Panel = %CharacterPanel
|
||||
@onready var title_label: Label = %TitleLabel
|
||||
@@ -25,18 +36,30 @@ func _on_close_timeout() -> void:
|
||||
close_timer.stop()
|
||||
|
||||
|
||||
## Loads the characters from where [method Settings.characters_dir] says. Emits
|
||||
## [signal source_changed] when that is somewhere else than last time.
|
||||
func load_characters() -> void:
|
||||
GameLog.debug("load_characters")
|
||||
var dir: String = Settings.characters_dir()
|
||||
var changed: bool = source_dir != null && source_dir != dir
|
||||
source_dir = dir
|
||||
source = character_cache if dir.is_empty() else FolderCharacters.new(dir)
|
||||
var loading: RefCounted = source
|
||||
var list_loaded: Callable = func list_loaded(names: Array[String]) -> void:
|
||||
GameLog.debug("list_loaded")
|
||||
# The source changed again before the server answered
|
||||
if source != loading:
|
||||
return
|
||||
Settings.delete_children(character_grid)
|
||||
for character_name: String in names:
|
||||
GameLog.debug("character_name ", character_name)
|
||||
var character_box: CharacterCard = character.instantiate()
|
||||
character_grid.add_child(character_box)
|
||||
character_box.set_character_name(character_name, character_cache.fetch_image)
|
||||
character_box.set_character_name(character_name, loading.fetch_image)
|
||||
character_box.new_character_selected.connect(_on_character_selected)
|
||||
character_cache.load_list(list_loaded)
|
||||
loading.load_list(list_loaded)
|
||||
if changed:
|
||||
source_changed.emit()
|
||||
|
||||
|
||||
func show_grid(player_name: String) -> void:
|
||||
@@ -53,12 +76,12 @@ func close() -> void:
|
||||
Settings.character_select_open = false
|
||||
|
||||
|
||||
func _on_character_selected(texture: ImageTexture) -> void:
|
||||
func _on_character_selected(texture: ImageTexture, character_name: String) -> void:
|
||||
GameLog.debug("_on_character_selected")
|
||||
# Not close(): character_select_open stays true until close_timer fires, so the click
|
||||
# that picked the character does not also select a song behind it
|
||||
visible = false
|
||||
if can_select_character:
|
||||
character_selected.emit(texture)
|
||||
character_selected.emit(texture, character_name)
|
||||
close_timer.start()
|
||||
can_select_character = false
|
||||
Reference in new issue
Block a user