Moving some of game to use MessageBus

This commit is contained in:
2026-08-08 01:22:54 -05:00
parent 6ebee75920
commit 50439bc8e0
7 changed files with 54 additions and 83 deletions

View File

@@ -13,18 +13,19 @@ func _exit_tree() -> void:
client.close_connection()
func setup_signals() -> void:
rpc_signals.match_list_entries.connect(_match_list_entries)
rpc_signals.match_list_entry_activated.connect(_on_match_list_entry_activated)
rpc_signals.match_list_entry_added.connect(_on_match_list_entry_added)
rpc_signals.match_list_entry_removed.connect(_on_match_list_entry_removed)
rpc_signals.match_list_entry_load_match.connect(_on_match_list_entry_load_match)
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)
MessageBus.subscribe("match_list_remove_entry", _on_match_list_entry_removed)
MessageBus.subscribe("match_list_entry_load_match", _on_match_list_entry_load_match)
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
# server we know we are connected and thus hide respective UI elements.
func _match_list_entries(matches_list: Array) -> void:
func _on_receive_match_list(matches_list: Array) -> void:
push_warning("Client Joined Host: Full Match List Recieved...\n", matches_list)
match_create_vbox.visible = true
@@ -94,7 +95,7 @@ func _create_match_entry(match_entry: Dictionary) -> void:
container.join_bttn.visible = false
func _join_match(match_id: String) -> void:
Globals.lobby_data.rpc_id(1, "match_list_join_entry", match_id)
MessageBus.emit_request.rpc_id(1, "match_list_join_entry", match_id)
func _delete_match(match_id: String) -> void:
Globals.lobby_data.rpc_id(1, "match_list_remove_entry", match_id)
MessageBus.emit_request.rpc_id(1, "match_list_remove_entry", match_id)

View File

@@ -52,7 +52,7 @@ func _on_match_create_bttn_pressed() -> void:
"type": active_mode
}
Globals.lobby_data.rpc_id(1, "match_list_add_entry", match_entry)
MessageBus.emit_request.rpc_id(1, "match_list_add_entry", match_entry)
func _on_mode_bttn_pressed(button: Button) -> void:
active_mode = button.text.remove_chars("-").to_lower()

View File

@@ -1,35 +1 @@
extends Node
signal match_list_entries(match_list: Array)
signal match_list_entry_activated(match_id: String)
signal match_list_entry_added(match_entry: Dictionary)
signal match_list_entry_removed(match_id: String)
signal match_list_entry_load_match(
match_entry: Dictionary, is_player_1: bool
)
@rpc("authority", "call_local", "reliable")
func match_list_add_entry(match_entry: Dictionary) -> void:
push_warning("Client received new match entry...")
match_list_entry_added.emit(match_entry)
@rpc("authority", "call_local", "reliable")
func match_list_remove_entry(match_id: String) -> void:
push_warning("Client received delete match entry...")
match_list_entry_removed.emit(match_id)
@rpc("authority", "reliable")
func receive_match_list(match_list: Array) -> void:
push_warning("Client received match list...")
match_list_entries.emit(match_list)
@rpc("authority", "reliable")
func match_list_activate_entry(match_id: String) -> void:
push_warning("Client set active match entry...")
match_list_entry_activated.emit(match_id)
func load_game_scene(match_entry: Dictionary, is_player_1: bool) -> void:
push_warning("Client load game scene...")
match_list_entry_load_match.emit(match_entry, is_player_1)