refactor: decouple game networking from lobby client

* Replace direct client/server networking references with GameClient/GameServer scenes
* Refactor message bus to support local emission and argument expansion
* Move lobby connection lifecycle handling to message bus events
* Remove multiplayer connection wait helpers and direct lobby client coupling
* Rename Server to ServerNetworking and update lobby client references
* Update scene resources and export configuration
This commit is contained in:
2026-08-09 18:41:18 -05:00
parent 50439bc8e0
commit 93a2be399c
20 changed files with 174 additions and 77 deletions

View File

@@ -2,17 +2,18 @@ class_name Lobby extends LobbyBase
func _ready() -> void:
Globals.lobby_data.lobby_ui = self
setup_signals()
func _exit_tree() -> void:
# TODO: Maybe no longer needed...
if Globals.multiplayer_data.is_multiplayer_active: return
client._do_wait_close_connection()
if client.peer:
client.close_connection()
func setup_signals() -> void:
MessageBus.subscribe("lobby_wait_for_connection", client._do_wait_for_connection)
MessageBus.subscribe("lobby_close_connection", client._do_wait_close_connection)
MessageBus.subscribe("receive_match_list", _on_receive_match_list)
MessageBus.subscribe("match_list_activate_entry", _on_match_list_entry_activated)
MessageBus.subscribe("match_list_add_entry", _on_match_list_entry_added)
@@ -23,7 +24,7 @@ func setup_signals() -> void:
func _server_host_started() -> void:
host_connect_bttn.visible = false
# NOTE: 'matches_list' can be empty but so long as we get the call from the
# NOTE: 'matches_list' can be empty; so long as we get the call from the
# server we know we are connected and thus hide respective UI elements.
func _on_receive_match_list(matches_list: Array) -> void:
push_warning("Client Joined Host: Full Match List Recieved...\n", matches_list)
@@ -36,6 +37,8 @@ func _on_receive_match_list(matches_list: Array) -> void:
for match_entry in matches_list:
_create_match_entry(match_entry)
client.lobby_fully_connected = true
func _on_match_list_entry_activated(match_id: String) -> void:
for match_entry in match_list.get_children():
match_entry.join_bttn.visible = false

View File

@@ -3,7 +3,7 @@
[ext_resource type="Script" uid="uid://dk7afnf7ol7dy" path="res://scenes/screens/lobby_screen/lobby.gd" id="1_hhiik"]
[ext_resource type="PackedScene" uid="uid://dg7pgj6i5pk8p" path="res://scenes/ui_controls/lobby_screen/lobby_ui.tscn" id="2_lqt48"]
[ext_resource type="Script" uid="uid://sihv0kwbcr33" path="res://scenes/screens/lobby_screen/lobby_rpc.gd" id="3_rurl6"]
[ext_resource type="Script" uid="uid://ci57tiuqsx1jp" path="res://scripts/client_networking.gd" id="4_glu7g"]
[ext_resource type="Script" uid="uid://dv7j35h2ngiq7" path="res://scenes/screens/lobby_screen/lobby_client.gd" id="4_glu7g"]
[node name="lobby" type="Node"]
script = ExtResource("1_hhiik")

View File

@@ -16,7 +16,7 @@ const MATCH_ENTRY = preload("res://scenes/screens/lobb
@onready var new_match_name_input: LineEdit = $ui/body/right_body/create_match_hbox/new_match_name_input
@onready var rpc_signals: Node = $rpc_signals
@onready var client: Node = $client
@onready var client: LobbyClient = $client
var active_mode: String = "snooker"
var active_match: HBoxContainer = null
@@ -52,7 +52,8 @@ func _on_match_create_bttn_pressed() -> void:
"type": active_mode
}
MessageBus.emit_request.rpc_id(1, "match_list_add_entry", match_entry)
#MessageBus.emit_request.rpc_id(1, "match_list_add_entry", match_entry)
MessageBus.emit_request.rpc("match_list_add_entry", match_entry)
func _on_mode_bttn_pressed(button: Button) -> void:
active_mode = button.text.remove_chars("-").to_lower()

View File

@@ -0,0 +1,35 @@
class_name LobbyClient extends ClientNetworking
var lobby_fully_connected: bool = false
func _ready() -> void:
pass
func _process(_delta: float) -> void:
pass
func _do_wait_for_connection() -> void:
_wait_for_connection()
while not lobby_fully_connected:
await get_tree().process_frame
func _do_wait_close_connection():
_wait_close_connection()
lobby_fully_connected = false
func client_connected_to_server() -> void:
push_warning("Connected to server!")
func client_disconnected_from_server() -> void:
push_warning("Disconnected from, server...")
func client_connection_failed_to_server() -> void:
push_warning("Connection failed!")
unset_client()

View File

@@ -0,0 +1 @@
uid://dv7j35h2ngiq7