refactored lobby logic; streamlined commands and added PeerMessages to client for more cohesive socket messaging

This commit is contained in:
2025-07-20 17:37:10 +02:00
parent b97d454402
commit 08799a3809
9 changed files with 170 additions and 125 deletions
+6 -37
View File
@@ -12,12 +12,6 @@ extends Control
@export var name_input: LineEdit
@export var lobby_code_input: LineEdit
@export var output: Label
func _write_line(text: String) -> void:
#output.text += text + "\n"
pass
func _on_create_lobby_button_pressed() -> void:
client.create_lobby(name_input.text.strip_edges())
@@ -28,34 +22,6 @@ func _on_disconnect_lobby_button_pressed() -> void:
leave_lobby_button.disabled = true
client.leave_lobby()
func _on_web_client_tcp_connected_to_server() -> void:
_write_line("You are connected to the server")
func _on_web_client_tcp_connection_error_occurred() -> void:
#connect_button.disabled = false
pass
func _on_web_client_tcp_disconnected_from_server() -> void:
_write_line("You were disconnected from the server")
func _on_web_client_tcp_connected_to_lobby(lobby_id: String) -> void:
lobby_code_input.text = lobby_id
_write_line("You connected to lobby {lobby_id}".format({"lobby_id": lobby_id}))
func _on_web_client_tcp_disconnected_from_lobby() -> void:
_write_line("You disconnected from the lobby")
func _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array) -> void:
_write_line("{client_name} joined the lobby{you}".format({
"client_name": client_name,
"you": " (that's you!)" if client_name == name_input.text.strip_edges() else ""
}))
_update_connected_players(connected_client_names)
func _on_web_client_tcp_client_left_lobby(client_name: String, connected_client_names: Array) -> void:
_write_line("{client_name} left the lobby".format({"client_name": client_name}))
_update_connected_players(connected_client_names)
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
match new_status:
WebClient.ConnectionStatus.DISCONNECTED:
@@ -96,8 +62,11 @@ func _on_web_client_tcp_connection_status_changed(new_status: WebClient.Connecti
name_input.editable = false
lobby_code_input.editable = false
func _on_web_client_tcp_received_connection_message(message: String) -> void:
_write_line(message)
func _update_connected_players(new_client_names: Array[String]) -> void:
connected_players_label.text = "Connected Players:\n" + "\n".join(new_client_names)
func _on_web_client_connected_to_lobby(lobby_id: String, client_id: String) -> void:
lobby_code_input.text = lobby_id
func _on_web_client_connected_clients_changed(connected_client_names: Array[String]) -> void:
_update_connected_players(connected_client_names)