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-06 08:32:55 +02:00
1 parent ab338b0696
commit 56e9fe66d3
18 files changed
+281 -162

No files matched your search

+26 -17
View File
@@ -66,12 +66,18 @@ func perform_search(search_text: String) -> void:
child.visible = false
label_pool.append(child)
for soundtrack: String in find_matches(search_text):
add_soundtrack_reuse(soundtrack)
## Returns the soundtracks matching [param search_text], best matches first: plain
## case-insensitive matches, then matches ignoring spaces and special characters,
## then matches with the letters in order but not next to each other.
func find_matches(search_text: String) -> Array[String]:
var seen: Dictionary = {}
var search_text_lower: String = search_text.to_lower()
var clean_search_text: String = clean_term(search_text)
# Collect all matches first, then display in order
var matches: Array = []
var matches: Array[String] = []
# Pass 1: Exact case-insensitive contains match on lowercase versions
for i in range(precomputed_soundtracks.size()):
@@ -98,9 +104,7 @@ func perform_search(search_text: String) -> void:
seen[st_data["original"]] = true
matches.append(st_data["original"])
# Display all matches in the order they appear in soundtracks
for soundtrack: String in matches:
add_soundtrack_reuse(soundtrack)
return matches
# Cleans a term by removing spaces and replacing special characters.
# Matches MusicServer's clean_term() function.
@@ -113,6 +117,9 @@ func compile_regex_cached(search_term: String) -> RegEx:
var regex = RegEx.new()
var regText: String = ".*"
for letter: String in search_term:
# Escape regex metacharacters so searches like "Q*bert" or "(Remix)" work
if "\\^$.|?*+()[]{}".contains(letter):
regText += "\\"
regText += letter + ".*"
regex.compile(regText)
regex_cache[search_term] = regex
@@ -149,26 +156,28 @@ func get_list_of_soundtracks() -> void:
print("get_list_of_soundtracks")
var handle_soundtracks: Callable = func handle_soundtracks(array) -> void:
if typeof(array) == TYPE_ARRAY:
soundtracks = []
precomputed_soundtracks = []
# Reuse existing labels: hide all and add to pool
for child: Label in search_list.get_children():
child.visible = false
label_pool.append(child)
soundtracks.append_array(array)
# Precompute cleaned versions for all soundtracks
set_soundtracks(array)
for soundtrack: String in soundtracks:
var cleaned = clean_term(soundtrack)
precomputed_soundtracks.append({
"original": soundtrack,
"lowercase": soundtrack.to_lower(),
"cleaned": cleaned
})
add_soundtrack_reuse(soundtrack)
else:
print("Unexpected data")
Settings.make_request2("/music/all/order", handle_soundtracks, true)
MusicServerClient.fetch_all_soundtracks_ordered(handle_soundtracks)
## Replaces the searchable soundtracks and precomputes their search forms.
func set_soundtracks(list: Array) -> void:
soundtracks = []
precomputed_soundtracks = []
soundtracks.append_array(list)
for soundtrack: String in soundtracks:
precomputed_soundtracks.append({
"original": soundtrack,
"lowercase": soundtrack.to_lower(),
"cleaned": clean_term(soundtrack)
})
func _input(event: InputEvent) -> void:
if self.visible == true: