godot-webrtc-mplayer-testing/scripts/global/global.gd

52 lines
1.2 KiB
GDScript3
Raw Normal View History

2021-11-15 15:43:33 -06:00
extends Node
2021-11-15 16:25:13 -06:00
const MultiplayerClient = preload("multiplayer_client.gd")
2021-11-15 15:43:33 -06:00
2021-11-15 16:25:13 -06:00
onready var client = MultiplayerClient.new()
2021-11-15 15:43:33 -06:00
2021-12-06 21:56:37 -06:00
# for command line flags
onready var goto_multiplayer = false
onready var create_lobby = false
onready var join_first_available_lobby = false
2021-11-15 15:43:33 -06:00
func _ready():
2021-11-17 16:24:00 -06:00
# client.signaller.connect("websocket_connected", self, "signaller_disconnected")
2021-11-15 16:25:13 -06:00
add_child(client)
2021-11-17 16:24:00 -06:00
client.signaller.connect("websocket_connected", self, "_signaller_connected")
2021-11-15 15:43:33 -06:00
2021-12-06 21:56:37 -06:00
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()
2021-11-17 08:18:12 -06:00
func goto_scene(scene_resource_name):
2021-12-07 16:43:37 -06:00
var _result = get_tree().change_scene("res://screens/%s.tscn" % scene_resource_name)
2021-11-15 16:25:13 -06:00
2021-11-17 08:18:12 -06:00
func main_menu():
2021-11-17 13:57:45 -06:00
client.close()
2021-12-07 16:43:37 -06:00
goto_scene("main_menu")
2021-11-15 16:25:13 -06:00
2021-11-17 08:18:12 -06:00
func start_singleplayer_game():
2021-11-17 13:57:45 -06:00
client.close()
2021-11-17 08:18:12 -06:00
goto_scene("game")
2021-11-15 15:43:33 -06:00
2021-11-17 16:24:00 -06:00
func _signaller_connected():
2021-12-07 16:43:37 -06:00
goto_scene("lobby_browser")
2021-11-17 16:24:00 -06:00
2021-11-17 13:57:45 -06:00
func lobby_browser():
client.close()
2021-11-17 16:24:00 -06:00
Global.client.connect_to_signaller()
2021-11-15 16:25:13 -06:00
2021-11-17 13:57:45 -06:00
func lobby():
2021-12-07 16:43:37 -06:00
goto_scene("multiplayer_lobby")
2021-11-17 13:57:45 -06:00
2021-11-17 08:18:12 -06:00
func quit():
2021-11-17 13:57:45 -06:00
client.close()
2021-11-17 08:18:12 -06:00
get_tree().quit()