63 lines
1.8 KiB
GDScript
63 lines
1.8 KiB
GDScript
extends MarginContainer
|
|
|
|
onready var peers = $v/body/peers/peers
|
|
onready var lobby_info_label = $v/head/lobby_info
|
|
onready var cursors = {}
|
|
|
|
func _ready():
|
|
Global.client.signaller.connect("peer_joined", self, "_peer_joined")
|
|
Global.client.signaller.connect("peer_left", self, "_peer_left")
|
|
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
|
|
lobby_info_label.text = "%s (%s)" % [Global.client.signaller.lobby_id, get_tree().get_network_unique_id()]
|
|
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
|
|
Global.client.signaller.request_peer_list()
|
|
|
|
func _signaller_disconnected():
|
|
Global.main_menu()
|
|
|
|
func _peer_joined(joined_peers):
|
|
print("Joined Peers: %s" % [joined_peers])
|
|
for i in range(len(joined_peers)):
|
|
var id = joined_peers[i]["id"]
|
|
var exists = false
|
|
for j in range(peers.get_item_count()):
|
|
if id == peers.get_item_metadata(j)["id"]:
|
|
print("Already have this one")
|
|
exists = true
|
|
break
|
|
if not exists:
|
|
var peerId = joined_peers[i]["peerId"]
|
|
var name = joined_peers[i]["name"]
|
|
print("New Lobby Peer ID: %s, Name: %s, PeerID: %s" % [id, name, peerId])
|
|
peers.add_item("%s (%s)" % [name, peerId])
|
|
peers.set_item_metadata(peers.get_item_count() - 1, { "id": id })
|
|
|
|
func _peer_left(ids):
|
|
for data in ids:
|
|
var id = data["id"]
|
|
for i in range(peers.get_item_count()):
|
|
if id == peers.get_item_metadata(i)["id"]:
|
|
peers.remove_item(i)
|
|
return
|
|
|
|
func _on_Button_pressed():
|
|
rpc("shift_cursor")
|
|
# move cursor a bit
|
|
|
|
remotesync func shift_cursor():
|
|
print("Shifting cursor...")
|
|
$shifter.rect_position.x += 10
|
|
|
|
func do_ping():
|
|
print(rpc("ping"))
|
|
|
|
remotesync func ping():
|
|
print("pinged")
|
|
return 0
|
|
|
|
func _lobby_left(_id):
|
|
Global.lobby_browser()
|
|
|
|
func _on_leave_button_pressed():
|
|
Global.lobby_browser()
|