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

55 lines
1.2 KiB
GDScript

extends Node
const SignalledWebRTCMultiplayer = preload("./signalled_webrtc_multiplayer.gd")
onready var client = SignalledWebRTCMultiplayer.new()
onready var onetime_cmd_flags = {
"--singleplayer": false,
"--multiplayer": false,
"--create-lobby": false,
"--join-first-available-lobby": false,
}
func _ready():
get_tree().use_font_oversampling = true
add_child(client)
for flag in onetime_cmd_flags.keys():
if flag in OS.get_cmdline_args():
onetime_cmd_flags[flag] = true
func check_onetime_flag(flag):
var result = onetime_cmd_flags["--%s" % flag]
onetime_cmd_flags["--%s" % flag] = false
return result
func goto_scene(scene_resource_name):
var _result = get_tree().change_scene("res://screens/%s.tscn" % scene_resource_name)
func main_menu():
client.close()
goto_scene("main_menu")
func start_singleplayer_game():
client.singleplayer()
goto_game()
func goto_game():
goto_scene("game")
func lobby_browser():
goto_scene("lobby_browser")
func lobby():
goto_scene("multiplayer_lobby")
func quit():
client.close()
get_tree().quit()
func key_shortcut(code):
var sc = ShortCut.new()
sc.shortcut = InputEventKey.new()
sc.shortcut.scancode = code
return sc