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:
@@ -1,9 +1,6 @@
|
||||
class_name LobbyData extends Node
|
||||
|
||||
|
||||
@onready var lobby_ui: Node
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.lobby_data = self
|
||||
|
||||
@@ -11,15 +8,16 @@ func _init() -> void:
|
||||
@rpc("authority", "reliable")
|
||||
func connect_to_game() -> void:
|
||||
# NOTE: Leave the lobby
|
||||
lobby_ui.client.close_connection()
|
||||
|
||||
Globals.multiplayer_data.wait_for_connection_close()
|
||||
MessageBus.emit_local("lobby_close_connection", null)
|
||||
|
||||
# NOTE: Join target game server
|
||||
# TODO: Don't use libby client... Use a created game client.
|
||||
lobby_ui.client.start_client(
|
||||
Globals.game_data.game_address,
|
||||
Globals.game_data.game_port
|
||||
MessageBus.emit_local(
|
||||
"game_start_client",
|
||||
[
|
||||
Globals.game_data.game_address,
|
||||
Globals.game_data.game_port
|
||||
],
|
||||
true
|
||||
)
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
|
||||
@@ -44,17 +44,6 @@ func init_match():
|
||||
true
|
||||
)
|
||||
|
||||
func wait_for_connection() -> void:
|
||||
while not Globals.lobby_data.lobby_ui.client.peer:
|
||||
await get_tree().process_frame
|
||||
|
||||
while Globals.lobby_data.lobby_ui.client.peer.get_connection_status() != 2:
|
||||
await get_tree().process_frame
|
||||
|
||||
func wait_for_connection_close() -> void:
|
||||
while Globals.lobby_data.lobby_ui.client.peer:
|
||||
await get_tree().process_frame
|
||||
|
||||
|
||||
func set_multiplayer_inactive() -> void:
|
||||
is_multiplayer_active = false
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
35
scenes/screens/lobby_screen/lobby_client.gd
Normal file
35
scenes/screens/lobby_screen/lobby_client.gd
Normal 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()
|
||||
1
scenes/screens/lobby_screen/lobby_client.gd.uid
Normal file
1
scenes/screens/lobby_screen/lobby_client.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dv7j35h2ngiq7
|
||||
Reference in New Issue
Block a user