Files

66 lines
1.9 KiB
GDScript3
Raw Permalink Normal View History

2026-08-07 03:02:53 -05:00
class_name Lobby extends LobbyBase
func _ready() -> void:
setup_signals()
func _exit_tree() -> void:
if server.peer:
server.close_connection()
func setup_signals() -> void:
2026-08-08 01:20:58 -05:00
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)
2026-08-07 03:02:53 -05:00
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:
2026-08-08 01:20:58 -05:00
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)
2026-08-07 03:02:53 -05:00
_create_match_entry(match_entry)
2026-08-08 01:20:58 -05:00
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
)
2026-08-07 03:02:53 -05:00
func _on_match_list_entry_removed(match_id: String) -> void:
2026-08-08 01:20:58 -05:00
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
)
2026-08-07 03:02:53 -05:00
for match_entry in match_list.get_children():
if not match_id == match_entry.match_id: continue
match_entry.queue_free()
2026-08-08 01:20:58 -05:00
func _on_match_list_join_entry(match_id: String) -> void:
push_warning("Client Joining Match List Entry... ", match_id)
Globals.lobby_data.match_list_join_entry(match_id)
2026-08-08 01:20:58 -05:00
2026-08-07 03:02:53 -05:00
func _create_match_entry(match_entry: Dictionary) -> void:
var container = MATCH_ENTRY.instantiate()
match_list.add_child(container)
container.name_lbl.text = match_entry.name
container.type_lbl.text = match_entry.type
container.match_id = match_entry.match_id