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:
Sansan committed 2026-10-05 19:33:41 +02:00
1 parent 4a275e6a88
commit 87ff3d899b
18 files changed
+281 -162

No files matched your search

+12 -5
View File
@@ -1,4 +1,4 @@
extends Node
extends RefCounted
class_name PlayerObject
signal first_point_triggerd
@@ -8,8 +8,8 @@ signal point_given_sound
signal player_point_given
signal player_point_taken
@export
var id: int
## Unique id that never changes, unlike the player's position in Settings.player_array.
var id: String = _generate_uuid()
@export
var player_name: String
@@ -21,11 +21,18 @@ var is_first_point: bool = true
var character: Texture = load("res://noCharacter.png")
func _init(new_name: String, new_id: int) -> void:
func _init(new_name: String) -> void:
player_name = new_name
id = new_id
player_score = 0
## 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)
bytes[6] = (bytes[6] & 0x0f) | 0x40
bytes[8] = (bytes[8] & 0x3f) | 0x80
var hex: String = bytes.hex_encode()
return "%s-%s-%s-%s-%s" % [hex.substr(0, 8), hex.substr(8, 4), hex.substr(12, 4), hex.substr(16, 4), hex.substr(20, 12)]
func add_point() -> void:
if player_score < Settings.winning_score:
player_score += 1