godot-webrtc-mplayer-testing/scripts/global/global.gd
2021-12-07 16:19:54 -06:00

52 lines
1.2 KiB
GDScript

extends Node
const MultiplayerClient = preload("multiplayer_client.gd")
onready var client = MultiplayerClient.new()
# for command line flags
onready var goto_multiplayer = false
onready var create_lobby = false
onready var join_first_available_lobby = false
func _ready():
# client.signaller.connect("websocket_connected", self, "signaller_disconnected")
add_child(client)
client.signaller.connect("websocket_connected", self, "_signaller_connected")
for arg in OS.get_cmdline_args():
match arg:
"--multiplayer": goto_multiplayer = true
"--create-lobby": create_lobby = true
"--join-first-available-lobby": join_first_available_lobby = true
var a: print("Unknown command line arg: %s" % a)
if goto_multiplayer:
goto_multiplayer = false
lobby_browser()
func goto_scene(scene_resource_name):
var _result = get_tree().change_scene("res://%s.tscn" % scene_resource_name)
func main_menu():
client.close()
goto_scene("main")
func start_singleplayer_game():
client.close()
goto_scene("game")
func _signaller_connected():
goto_scene("multiplayer")
func lobby_browser():
client.close()
Global.client.connect_to_signaller()
func lobby():
goto_scene("lobby")
func quit():
client.close()
get_tree().quit()