godot-webrtc-mplayer-testing/multiplayer.gd

49 lines
1.4 KiB
GDScript3
Raw Normal View History

2021-11-17 08:18:12 -06:00
extends Control
2021-11-17 13:57:45 -06:00
# TODO: rename to server browser
2021-11-17 08:18:12 -06:00
onready var is_loaded = false
func _ready():
2021-11-17 13:57:45 -06:00
Global.client.signaller.connect("lobby_new", self, "_lobby_new")
Global.client.signaller.connect("lobby_delete", self, "_lobby_delete")
Global.client.signaller.connect("lobby_joined", self, "_lobby_joined")
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
2021-11-17 16:24:00 -06:00
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
Global.client.signaller.request_lobby_list()
func _signaller_disconnected():
Global.main_menu()
2021-11-17 08:18:12 -06:00
2021-11-17 16:24:00 -06:00
func _lobby_joined(_id, _peerId):
2021-11-17 13:57:45 -06:00
Global.lobby()
func _lobby_left(_id):
Global.lobby_browser()
2021-11-17 08:18:12 -06:00
func _on_back_pressed():
2021-11-17 13:57:45 -06:00
Global.main_menu()
func _on_create_lobby_pressed():
Global.client.signaller.create_lobby()
func _on_join_pressed():
var items = $lobbies.get_selected_items()
if len(items) > 0:
Global.client.signaller.join_lobby($lobbies.get_item_metadata(items[0])["id"])
func _lobby_new(lobbies):
for i in range(len(lobbies)):
var id = lobbies[i]["id"]
var name = lobbies[i]["name"]
print("New Lobby ", id, name)
# TODO: could keep an index of IDs and indexes
$lobbies.add_item("%s" % name)
$lobbies.set_item_metadata($lobbies.get_item_count() - 1, { "id": id })
func _lobby_delete(id):
for i in range($lobbies.get_item_count()):
if id == $lobbies.get_item_metadata(i)["id"]:
$lobbies.remove_item(i)
return