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()
63 lines
1.7 KiB
GDScript
63 lines
1.7 KiB
GDScript
extends Control
|
|
|
|
@onready
|
|
var winner_panel: Panel = %WinnerPanel
|
|
|
|
@onready
|
|
var winner_picture: TextureRect = %WinnerPicture
|
|
|
|
@onready
|
|
var winner_label: Label = %WinnerLabel
|
|
|
|
@onready
|
|
var players_list: VBoxContainer = %PlayersList
|
|
|
|
|
|
func _ready() -> void:
|
|
visible = false
|
|
|
|
|
|
func show_winner(winner: PlayerObject) -> void:
|
|
visible = true
|
|
# Set winner info
|
|
winner_label.text = winner.player_name + " won with " + str(winner.player_score) + \
|
|
" points!!"
|
|
winner_picture.texture = winner.character
|
|
winner_picture.custom_minimum_size = Vector2(480, 200)
|
|
winner_picture.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
|
|
winner_picture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
|
|
# Clear previous player list entries
|
|
for child: Node in players_list.get_children():
|
|
child.queue_free()
|
|
|
|
# Sort players by score (descending) and add to list
|
|
var sorted_players: Array = Settings.player_array.duplicate()
|
|
sorted_players.sort_custom(
|
|
func(a: PlayerObject, b: PlayerObject) -> bool:
|
|
return a.player_score > b.player_score
|
|
)
|
|
|
|
var placing: int = 2
|
|
for player: PlayerObject in sorted_players:
|
|
if player == winner:
|
|
continue # Skip the winner, already shown above
|
|
var label: Label = Label.new()
|
|
label.text = str(placing) + ". " + player.player_name + " - " + \
|
|
str(player.player_score) + " points"
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
players_list.add_child(label)
|
|
placing += 1
|
|
|
|
|
|
func hide_window() -> void:
|
|
visible = false
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if visible:
|
|
if event is InputEventMouseButton and event.is_pressed():
|
|
var ev_local: InputEvent = make_input_local(event)
|
|
if !Rect2(Vector2(0, 0), winner_panel.size).has_point(ev_local.position):
|
|
visible = false
|