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
+8
-9
@@ -1,4 +1,4 @@
|
||||
extends Node
|
||||
extends RefCounted
|
||||
|
||||
class_name SongObject
|
||||
|
||||
@@ -8,7 +8,8 @@ var song_title: String
|
||||
|
||||
var soundtrack_title: String
|
||||
|
||||
var players_given_point: Array[int] = []
|
||||
## Ids of the players who got a point for this song.
|
||||
var players_given_point: Array[String] = []
|
||||
|
||||
var is_answered: bool = false
|
||||
|
||||
@@ -40,16 +41,14 @@ func get_song_info() -> String:
|
||||
else:
|
||||
return "??? - ???"
|
||||
|
||||
func add_point(id: int) -> void:
|
||||
func add_point(player_id: String) -> void:
|
||||
print("add_point")
|
||||
players_given_point.append(id)
|
||||
players_given_point.sort()
|
||||
if !players_given_point.has(player_id):
|
||||
players_given_point.append(player_id)
|
||||
|
||||
func remove_point(id: int) -> void:
|
||||
func remove_point(player_id: String) -> void:
|
||||
print("remove_point")
|
||||
if players_given_point.has(id):
|
||||
players_given_point.remove_at(players_given_point.find(id))
|
||||
players_given_point.sort()
|
||||
players_given_point.erase(player_id)
|
||||
|
||||
func _to_string() -> String:
|
||||
var format_string: String = "song_number: %d | soundtrack_title: %s | song_title: %s | is_answered: %s | has_played: %s | is_playing: %s"
|
||||
|
||||
Reference in new issue
Block a user