Move server calls to MusicServerClient and give players stable ids
Server requests move out of Settings into a new MusicServerClient autoload with one function per endpoint. It sends requests through a swappable HttpTransport so tests can fake the server, and it frees its HTTPRequest nodes after use. Players now have a UUID that never changes. Their position in Settings.player_array is only used for the Alt+<number> keybinds. Previously the position doubled as the id, so removing a player made points and wins land on the wrong player, and could delete another player's point from a song. Also fixes: - format_time showed 59.6 seconds as "00:60" - searches containing regex characters such as "Q*bert" broke search - SongObject and PlayerObject were Nodes that were never freed; they are now RefCounted - search matching is split out of the UI code into find_matches()
This commit is contained in:
1 parent
ab338b0696
commit
56e9fe66d3
18 files changed
+281
-162
No files matched your search
@@ -19,15 +19,19 @@ var remove_player := $HBoxContainer/RemovePlayer
|
||||
signal change_character_clicked
|
||||
signal player_removed
|
||||
|
||||
@export
|
||||
var id: int
|
||||
## 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
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
add_button.pressed.connect(add_point)
|
||||
add_button.set_shortcut(create_button_shortcut(id, false))
|
||||
add_button.set_shortcut(create_button_shortcut(list_index, false))
|
||||
minus_button.pressed.connect(minus_point)
|
||||
minus_button.set_shortcut(create_button_shortcut(id, true))
|
||||
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()
|
||||
@@ -36,21 +40,21 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
remove_player.visible = Settings.edit_players
|
||||
|
||||
func create_button_shortcut(scancode : int, ctrl_pressed: bool) -> Shortcut:
|
||||
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 = scancode + 49
|
||||
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:
|
||||
Settings.player_array[id].add_point()
|
||||
player_object.add_point()
|
||||
update_score()
|
||||
|
||||
func minus_point() -> void:
|
||||
Settings.player_array[id].minus_point()
|
||||
player_object.minus_point()
|
||||
update_score()
|
||||
|
||||
func change_character() -> void:
|
||||
@@ -58,22 +62,22 @@ func change_character() -> void:
|
||||
|
||||
func character_selected(file_name: String) -> void:
|
||||
print("Back in player list with: " + file_name)
|
||||
Settings.player_array[id].character = load("res://characters/" + file_name)
|
||||
player_object.character = load("res://characters/" + file_name)
|
||||
set_player_character()
|
||||
|
||||
func new_character_selected(character_texture: ImageTexture) -> void:
|
||||
print("Back in player list with new")
|
||||
Settings.player_array[id].character = character_texture
|
||||
player_object.character = character_texture
|
||||
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 = Settings.player_array[id].character
|
||||
character.texture_normal = player_object.character
|
||||
|
||||
func update_score() -> void:
|
||||
if OS.has_feature("debug"):
|
||||
player_name_field.text = str(Settings.player_array[id].id) + " " + Settings.player_array[id].player_name + ": " + str(Settings.player_array[id].player_score)
|
||||
player_name_field.text = str(list_index + 1) + " " + player_object.player_name + ": " + str(player_object.player_score)
|
||||
else:
|
||||
player_name_field.text = Settings.player_array[id].player_name + ": " + str(Settings.player_array[id].player_score)
|
||||
player_name_field.text = player_object.player_name + ": " + str(player_object.player_score)
|
||||
Reference in new issue
Block a user