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
79 lines
2.3 KiB
GDScript
79 lines
2.3 KiB
GDScript
class_name PlayerRow
|
|
extends Control
|
|
|
|
signal change_character_clicked
|
|
signal player_removed
|
|
|
|
## The player shown in this row.
|
|
var player_object: PlayerObject
|
|
|
|
## Position in Settings.player_array. Only used for the keybinds: Alt+<list_index + 1>
|
|
## gives this player a point and Ctrl+Alt+<list_index + 1> takes one away.
|
|
var list_index: int
|
|
|
|
@onready var player_name_field: Label = %Name
|
|
@onready var add_button: Button = %AddPoint
|
|
@onready var minus_button: Button = %RemovePoint
|
|
@onready var character: TextureButton = %Character
|
|
@onready var remove_player: TextureButton = %RemovePlayer
|
|
|
|
|
|
func _ready() -> void:
|
|
add_button.pressed.connect(add_point)
|
|
add_button.set_shortcut(create_button_shortcut(list_index, false))
|
|
minus_button.pressed.connect(minus_point)
|
|
minus_button.set_shortcut(create_button_shortcut(list_index, true))
|
|
character.pressed.connect(change_character)
|
|
remove_player.pressed.connect(func() -> void: player_removed.emit())
|
|
update_score()
|
|
set_player_character()
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
remove_player.visible = Settings.edit_players
|
|
|
|
|
|
func create_button_shortcut(index: int, ctrl_pressed: bool) -> Shortcut:
|
|
var button_shortcut: Shortcut = Shortcut.new()
|
|
var button_event: InputEventKey = InputEventKey.new()
|
|
button_event.keycode = KEY_1 + index
|
|
button_event.alt_pressed = true
|
|
button_event.ctrl_pressed = ctrl_pressed
|
|
button_shortcut.events.append(button_event)
|
|
return button_shortcut
|
|
|
|
|
|
func add_point() -> void:
|
|
player_object.add_point()
|
|
update_score()
|
|
|
|
|
|
func minus_point() -> void:
|
|
player_object.minus_point()
|
|
update_score()
|
|
|
|
|
|
func change_character() -> void:
|
|
change_character_clicked.emit()
|
|
|
|
|
|
func new_character_selected(character_texture: Texture, character_name: String) -> void:
|
|
GameLog.debug("Back in player list with new")
|
|
player_object.set_character(character_texture, character_name)
|
|
set_player_character()
|
|
|
|
|
|
func set_player_character() -> void:
|
|
character.custom_minimum_size = Vector2(80, 40)
|
|
character.ignore_texture_size = true
|
|
character.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
|
character.texture_normal = player_object.character
|
|
|
|
|
|
func update_score() -> void:
|
|
if OS.has_feature("debug"):
|
|
player_name_field.text = "%d %s: %d" % [list_index + 1, player_object.player_name,
|
|
player_object.player_score]
|
|
else:
|
|
player_name_field.text = player_object.player_name + ": " + str(player_object.player_score)
|