Still need to centralize a lot of stuff into the new module
This commit is contained in:
parent
68a35b25ac
commit
9c41eaa3b4
|
@ -11,9 +11,7 @@ onready var onetime_cmd_flags = {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
client.connect("signaller_connected", self, "_signaller_connected")
|
|
||||||
add_child(client)
|
add_child(client)
|
||||||
|
|
||||||
for flag in onetime_cmd_flags.keys():
|
for flag in onetime_cmd_flags.keys():
|
||||||
if flag in OS.get_cmdline_args():
|
if flag in OS.get_cmdline_args():
|
||||||
onetime_cmd_flags[flag] = true
|
onetime_cmd_flags[flag] = true
|
||||||
|
@ -37,12 +35,9 @@ func start_singleplayer_game():
|
||||||
func goto_game():
|
func goto_game():
|
||||||
goto_scene("game")
|
goto_scene("game")
|
||||||
|
|
||||||
func _signaller_connected():
|
|
||||||
goto_scene("lobby_browser")
|
|
||||||
|
|
||||||
func lobby_browser():
|
func lobby_browser():
|
||||||
client.close()
|
client.close()
|
||||||
client.connect_to_signaller()
|
goto_scene("lobby_browser")
|
||||||
|
|
||||||
func lobby():
|
func lobby():
|
||||||
goto_scene("multiplayer_lobby")
|
goto_scene("multiplayer_lobby")
|
||||||
|
|
|
@ -18,7 +18,7 @@ signal lobby_delete(id)
|
||||||
|
|
||||||
signal peer_data(peers)
|
signal peer_data(peers)
|
||||||
signal peer_left(id)
|
signal peer_left(id)
|
||||||
signal peer_init(peer_id)
|
signal peer_init(id)
|
||||||
|
|
||||||
signal candidate_received(cand)
|
signal candidate_received(cand)
|
||||||
signal offer_received(data)
|
signal offer_received(data)
|
||||||
|
@ -61,12 +61,6 @@ func _ready():
|
||||||
websocket.connect("connection_error", self, "_signaller_error", [false])
|
websocket.connect("connection_error", self, "_signaller_error", [false])
|
||||||
websocket.connect("connection_failed", self, "_signaller_error", [false])
|
websocket.connect("connection_failed", self, "_signaller_error", [false])
|
||||||
|
|
||||||
print(self)
|
|
||||||
print(websocket)
|
|
||||||
print(webrtc)
|
|
||||||
add_child(websocket)
|
|
||||||
add_child(webrtc)
|
|
||||||
|
|
||||||
func connect_to_signaller(url = signaller_url):
|
func connect_to_signaller(url = signaller_url):
|
||||||
signaller_url = url
|
signaller_url = url
|
||||||
close()
|
close()
|
||||||
|
@ -89,6 +83,9 @@ func request_lobby_list():
|
||||||
func join_lobby(id: String):
|
func join_lobby(id: String):
|
||||||
return _send("lobby_join:%s" % id)
|
return _send("lobby_join:%s" % id)
|
||||||
|
|
||||||
|
func get_lobby_name():
|
||||||
|
return current_lobby.name
|
||||||
|
|
||||||
func create_lobby():
|
func create_lobby():
|
||||||
return _send("lobby_create")
|
return _send("lobby_create")
|
||||||
|
|
||||||
|
@ -172,7 +169,8 @@ func _process_signaller_message(data: Dictionary):
|
||||||
emit_signal("lobby_joined", data)
|
emit_signal("lobby_joined", data)
|
||||||
"lobby_left": emit_signal("lobby_left", data.id)
|
"lobby_left": emit_signal("lobby_left", data.id)
|
||||||
|
|
||||||
"peer_data": emit_signal("peer_data", [data] if data.has("id") else data.data)
|
"peer_data":
|
||||||
|
emit_signal("peer_data", [data] if data.has("id") else data.data)
|
||||||
"peer_left": emit_signal("peer_left", data.data)
|
"peer_left": emit_signal("peer_left", data.data)
|
||||||
|
|
||||||
"candidate":
|
"candidate":
|
||||||
|
|
|
@ -13,15 +13,16 @@ onready var lobby = preload("res://objects/lobby.tscn")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
display_name_edit.text = Global.client.display_name
|
display_name_edit.text = Global.client.display_name
|
||||||
Global.signaller_client.connect("lobby_data", self, "_lobby_data")
|
Global.client.connect("lobby_data", self, "_lobby_data")
|
||||||
Global.signaller_client.connect("lobby_delete", self, "_lobby_delete")
|
Global.client.connect("lobby_delete", self, "_lobby_delete")
|
||||||
Global.signaller_client.connect("lobby_joined", self, "_lobby_joined")
|
Global.client.connect("lobby_joined", self, "_lobby_joined")
|
||||||
Global.signaller_client.connect("lobby_left", self, "_lobby_left")
|
Global.client.connect("lobby_left", self, "_lobby_left")
|
||||||
Global.signaller_client.connect("disconnected", self, "_signaller_disconnected")
|
Global.client.connect("signaller_connected", self, "_signaller_connected")
|
||||||
Global.signaller_client.request_lobby_list()
|
Global.client.connect("signaller_disconnected", self, "_signaller_disconnected")
|
||||||
|
Global.client.connect_to_signaller()
|
||||||
|
|
||||||
if Global.check_onetime_flag("create-lobby"):
|
if Global.check_onetime_flag("create-lobby"):
|
||||||
Global.signaller_client.create_lobby()
|
Global.client.create_lobby()
|
||||||
|
|
||||||
# TODO: add search
|
# TODO: add search
|
||||||
func _input(ev):
|
func _input(ev):
|
||||||
|
@ -37,6 +38,9 @@ func _input(ev):
|
||||||
func _signaller_disconnected():
|
func _signaller_disconnected():
|
||||||
Global.main_menu()
|
Global.main_menu()
|
||||||
|
|
||||||
|
func _signaller_connected():
|
||||||
|
Global.client.request_lobby_list()
|
||||||
|
|
||||||
func _lobby_joined(data):
|
func _lobby_joined(data):
|
||||||
print("Lobby Joined: %s" % data)
|
print("Lobby Joined: %s" % data)
|
||||||
Global.lobby()
|
Global.lobby()
|
||||||
|
@ -48,12 +52,12 @@ func _on_back_pressed():
|
||||||
Global.main_menu()
|
Global.main_menu()
|
||||||
|
|
||||||
func _on_create_lobby_pressed():
|
func _on_create_lobby_pressed():
|
||||||
Global.signaller_client.create_lobby()
|
Global.client.create_lobby()
|
||||||
|
|
||||||
func _on_join_pressed():
|
func _on_join_pressed():
|
||||||
var items = lobbies.get_selected_items()
|
var items = lobbies.get_selected_items()
|
||||||
if len(items) > 0:
|
if len(items) > 0:
|
||||||
Global.signaller_client.join_lobby(lobbies.get_item_metadata(items[0])["id"])
|
Global.client.join_lobby(lobbies.get_item_metadata(items[0])["id"])
|
||||||
|
|
||||||
func _lobby_data(new_lobbies: Array):
|
func _lobby_data(new_lobbies: Array):
|
||||||
for l in new_lobbies:
|
for l in new_lobbies:
|
||||||
|
@ -61,7 +65,7 @@ func _lobby_data(new_lobbies: Array):
|
||||||
else: _add_lobby(l.id, l)
|
else: _add_lobby(l.id, l)
|
||||||
|
|
||||||
if Global.check_onetime_flag("join-first-available-lobby"):
|
if Global.check_onetime_flag("join-first-available-lobby"):
|
||||||
Global.signaller_client.join_lobby(l.id)
|
Global.client.join_lobby(l.id)
|
||||||
|
|
||||||
func _lobby_delete(id: String):
|
func _lobby_delete(id: String):
|
||||||
print("Lobby Deleted: %s" % id)
|
print("Lobby Deleted: %s" % id)
|
||||||
|
@ -100,4 +104,4 @@ func _update_lobbies_text():
|
||||||
lobbies_grid.remove_child(zero_state)
|
lobbies_grid.remove_child(zero_state)
|
||||||
|
|
||||||
func _on_display_name_text_changed(new_text):
|
func _on_display_name_text_changed(new_text):
|
||||||
Global.signaller_client.display_name = new_text
|
Global.client.display_name = new_text
|
||||||
|
|
|
@ -18,21 +18,21 @@ onready var peers_id_mappings = {}
|
||||||
onready var is_host = false
|
onready var is_host = false
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Global.signaller_client.connect("peer_data", self, "_peer_data")
|
Global.client.connect("peer_data", self, "_peer_data")
|
||||||
Global.signaller_client.connect("peer_left", self, "_peer_left")
|
Global.client.connect("peer_left", self, "_peer_left")
|
||||||
Global.signaller_client.connect("lobby_left", self, "_lobby_left")
|
Global.client.connect("lobby_left", self, "_lobby_left")
|
||||||
Global.signaller_client.connect("lobby_data", self, "_lobby_data")
|
Global.client.connect("lobby_data", self, "_lobby_data")
|
||||||
|
|
||||||
Global.signaller_client.connect("disconnected", self, "_signaller_disconnected")
|
Global.client.connect("signaller_disconnected", self, "_signaller_disconnected")
|
||||||
Global.negotiator.connect("connection_succeeded", self, "_connection_succeeded")
|
Global.client.connect("webrtc_connection_succeeded", self, "_connection_succeeded")
|
||||||
|
|
||||||
# lobby_name.text = "%s" % Global.signaller_client.lobby_name
|
# lobby_name.text = "%s" % Global.client.lobby_name
|
||||||
|
|
||||||
Global.signaller_client.call_deferred("request_peer_list")
|
Global.client.call_deferred("request_peer_list")
|
||||||
call_deferred("add_chat", "# Connected to %s" % Global.signaller_client.get_lobby_name())
|
call_deferred("add_chat", "# Connected to %s" % Global.client.get_lobby_name())
|
||||||
|
|
||||||
# hide/show controls depending on whether or not we're the host
|
# hide/show controls depending on whether or not we're the host
|
||||||
is_host = Global.signaller_client.is_host()
|
is_host = Global.client.is_host()
|
||||||
if is_host:
|
if is_host:
|
||||||
ready_up.queue_free()
|
ready_up.queue_free()
|
||||||
else:
|
else:
|
||||||
|
@ -43,13 +43,14 @@ func _ready():
|
||||||
|
|
||||||
# until we fully connect
|
# until we fully connect
|
||||||
ready_up.disabled = true
|
ready_up.disabled = true
|
||||||
chat_edit.disabled = true
|
chat_edit.editable = false
|
||||||
send_button.disabled = true
|
send_button.disabled = true
|
||||||
print("Setting up lobby... %s %s" % [Global.signaller_client.peer_id, is_host])
|
print("Setting up lobby... %s %s" % [get_tree().get_network_unique_id(), is_host])
|
||||||
|
|
||||||
func _connection_succeeded():
|
func _connection_succeeded():
|
||||||
ready_up.disabled = false
|
ready_up.disabled = false
|
||||||
send_button.disabled = false
|
send_button.disabled = false
|
||||||
|
chat_edit.editable = true
|
||||||
|
|
||||||
func _lobby_update(l):
|
func _lobby_update(l):
|
||||||
for u in l:
|
for u in l:
|
||||||
|
@ -118,7 +119,7 @@ func preserve_chat_scroll(n, tl, fl, tc, fc):
|
||||||
func send_chat_message():
|
func send_chat_message():
|
||||||
var message = chat_edit.text
|
var message = chat_edit.text
|
||||||
if message != "":
|
if message != "":
|
||||||
rpc("add_chat", "%s: %s" % [Global.signaller_client.display_name, message])
|
rpc("add_chat", "%s: %s" % [Global.client.display_name, message])
|
||||||
chat_edit.text = ""
|
chat_edit.text = ""
|
||||||
|
|
||||||
func update_can_start():
|
func update_can_start():
|
||||||
|
@ -154,5 +155,5 @@ func _on_leave_button_pressed(): Global.lobby_browser()
|
||||||
func update_player_count(): peers_list_label.text = "Players: %d" % peers.size()
|
func update_player_count(): peers_list_label.text = "Players: %d" % peers.size()
|
||||||
func _on_Button_pressed(): send_chat_message()
|
func _on_Button_pressed(): send_chat_message()
|
||||||
func _on_ready_up_toggled(button_pressed: bool): rpc("set_ready", button_pressed)
|
func _on_ready_up_toggled(button_pressed: bool): rpc("set_ready", button_pressed)
|
||||||
func _on_lobby_info_text_changed(new_text: String): Global.signaller_client.set_lobby_name(new_text)
|
func _on_lobby_info_text_changed(new_text: String): Global.client.set_lobby_name(new_text)
|
||||||
func _signaller_disconnected(): Global.main_menu()
|
func _signaller_disconnected(): Global.main_menu()
|
||||||
|
|
Loading…
Reference in a new issue