Moving some of lobby to use MessageBus
This commit is contained in:
@@ -13,26 +13,56 @@ func _exit_tree() -> void:
|
||||
server.close_connection()
|
||||
|
||||
func setup_signals() -> void:
|
||||
rpc_signals.server_host_started.connect(_server_host_started)
|
||||
rpc_signals.match_list_entry_added.connect(_on_match_list_entry_added)
|
||||
rpc_signals.match_list_entry_removed.connect(_on_match_list_entry_removed)
|
||||
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_join_entry", _on_match_list_join_entry)
|
||||
|
||||
|
||||
func _server_host_started() -> void:
|
||||
host_start_bttn.visible = false
|
||||
host_stop_bttn.visible = true
|
||||
|
||||
func _on_match_list_entry_added(match_entry: Dictionary) -> void:
|
||||
push_warning("Client: Added Match List Entry... ", match_entry)
|
||||
Globals.lobby_data.match_list_add_entry(match_entry)
|
||||
if not match_entry.has("match_id"): return
|
||||
|
||||
push_warning("Client Added Match List Entry... ", match_entry)
|
||||
|
||||
_create_match_entry(match_entry)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc(
|
||||
"match_list_add_entry", match_entry
|
||||
)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc_id(
|
||||
multiplayer.get_remote_sender_id(),
|
||||
"match_list_activate_entry",
|
||||
match_entry.match_id
|
||||
)
|
||||
|
||||
func _on_match_list_entry_removed(match_id: String) -> void:
|
||||
push_warning("Client: Removed Match List Entry... ", match_id)
|
||||
Globals.lobby_data.match_list_remove_entry(match_id)
|
||||
if Globals.lobby_data.match_pool.has(match_id): return
|
||||
|
||||
push_warning("Removed Match List Entry... ", match_id)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc(
|
||||
"match_list_remove_entry",
|
||||
match_id
|
||||
)
|
||||
|
||||
for match_entry in match_list.get_children():
|
||||
if not match_id == match_entry.match_id: continue
|
||||
match_entry.queue_free()
|
||||
|
||||
func _on_match_list_join_entry(match_id: String) -> void:
|
||||
Globals.lobby_data.match_list_join_entry(match_id)
|
||||
push_warning("Client Joining Match List Entry... ", match_id)
|
||||
|
||||
if Globals.lobby_data.match_pool.has(match_id): return
|
||||
|
||||
_on_match_list_entry_removed(match_id)
|
||||
|
||||
func _create_match_entry(match_entry: Dictionary) -> void:
|
||||
var container = MATCH_ENTRY.instantiate()
|
||||
match_list.add_child(container)
|
||||
|
||||
@@ -1,29 +1 @@
|
||||
extends Node
|
||||
|
||||
|
||||
@warning_ignore_start("unused_signal")
|
||||
signal server_host_started()
|
||||
signal match_list_entry_added(match_entry: Dictionary)
|
||||
signal match_list_entry_removed(match_id: String)
|
||||
@warning_ignore_restore("unused_signal")
|
||||
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func match_list_add_entry(match_entry: Dictionary) -> void:
|
||||
push_warning("Received new match entry...")
|
||||
|
||||
emit_signal("match_list_entry_added", match_entry)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func match_list_remove_entry(match_id: String) -> void:
|
||||
push_warning("Received delete match entry...")
|
||||
|
||||
emit_signal("match_list_entry_removed", match_id)
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func receive_match_list(_match_list: Array) -> void:
|
||||
pass
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func match_list_activate_entry(_match_id: String) -> void:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user