clients now auto-connect to server, omitting the connection step and hiding the server URL from the frontend

This commit is contained in:
2025-07-20 15:02:05 +02:00
parent f11cb19348
commit b97d454402
11 changed files with 385 additions and 635 deletions
+9 -30
View File
@@ -1,16 +1,12 @@
class_name ClientInterface
extends Control
@export var client: WebClientTCP
@export var client: WebClient
@export var connect_button: Button
@export var create_lobby_button: Button
@export var join_lobby_button: Button
@export var leave_lobby_button: Button
@export var chat_message_input: LineEdit
@export var send_chat_message_button: Button
@export var connected_players_label: Label
@export var name_input: LineEdit
@@ -25,9 +21,6 @@ func _write_line(text: String) -> void:
func _on_create_lobby_button_pressed() -> void:
client.create_lobby(name_input.text.strip_edges())
func _on_connect_button_pressed() -> void:
client.connect_to_server($MarginContainer/VBoxContainer/ServerInputs/URLInput.text)
func _on_join_lobby_button_pressed() -> void:
client.join_lobby(lobby_code_input.text.strip_edges(), name_input.text.strip_edges())
@@ -39,7 +32,8 @@ 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
#connect_button.disabled = false
pass
func _on_web_client_tcp_disconnected_from_server() -> void:
_write_line("You were disconnected from the server")
@@ -62,60 +56,45 @@ func _on_web_client_tcp_client_left_lobby(client_name: String, connected_client_
_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: WebClientTCP.ConnectionStatus) -> void:
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
match new_status:
WebClientTCP.ConnectionStatus.DISCONNECTED:
connect_button.disabled = false
WebClient.ConnectionStatus.DISCONNECTED:
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = true
name_input.editable = true
lobby_code_input.editable = false
lobby_code_input.text = ""
chat_message_input.editable = false
send_chat_message_button.disabled = true
WebClientTCP.ConnectionStatus.ATTEMPTING_CONNECTION:
connect_button.disabled = true
WebClient.ConnectionStatus.ATTEMPTING_CONNECTION:
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = true
name_input.editable = true
lobby_code_input.editable = false
lobby_code_input.text = ""
chat_message_input.editable = false
send_chat_message_button.disabled = true
WebClientTCP.ConnectionStatus.LOBBYLESS:
connect_button.disabled = true
WebClient.ConnectionStatus.LOBBYLESS:
create_lobby_button.disabled = false
join_lobby_button.disabled = false
leave_lobby_button.disabled = true
name_input.editable = true
lobby_code_input.editable = true
lobby_code_input.text = ""
chat_message_input.editable = false
send_chat_message_button.disabled = true
WebClientTCP.ConnectionStatus.ATTEMPTING_JOIN:
connect_button.disabled = true
WebClient.ConnectionStatus.ATTEMPTING_JOIN:
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = true
name_input.editable = false
lobby_code_input.editable = false
chat_message_input.editable = false
send_chat_message_button.disabled = true
WebClientTCP.ConnectionStatus.JOINED:
connect_button.disabled = true
WebClient.ConnectionStatus.JOINED:
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = false
name_input.editable = false
lobby_code_input.editable = false
chat_message_input.editable = true
send_chat_message_button.disabled = false
func _on_web_client_tcp_received_connection_message(message: String) -> void:
_write_line(message)