extends Control onready var GC = $GCClient onready var MM = $MainMenu enum { MENU, INGAME } var game_state : int = MENU onready var game_scene_base : PackedScene = preload("res://pages/GameTable.tscn") var game_scene = null func _ready(): if OS.get_name() == "HTML5": # running on web var lobby_id = JavaScript.eval("new URLSearchParams(document.location.search).get('lobby_id')") var gc_url = JavaScript.eval("new URLSearchParams(document.location.search).get('gc_url')") var password = JavaScript.eval("new URLSearchParams(document.location.search).get('pw')") if gc_url: Globals.update_gc_url(gc_url) if lobby_id: var pw : String = password if password else "" MM.join_menu_button_pressed(lobby_id, pw) GC.connect("join_request_success", self, "on_join_request_success") GC.connect("host_success", self, "on_host_success") GC.connect("host_failure", self, "on_host_failure") GC.connect("join_success", self, "on_join_success") GC.connect("join_failure", self, "on_join_failure") GC.connect("gc_connection_failed", self, "on_gc_connection_failure") MM.connect("game_host_request", GC, "host_lobby") MM.connect("game_join_request", GC, "join_lobby") func _process(_delta): if GC.state > 1 and (game_state == MENU): GC.receive() func to_main_menu(): if game_state == MENU: return if game_scene: remove_child(game_scene) game_scene.queue_free() GC.reset_gc_client() GC.close_socket() MM.visible = true game_state = MENU func to_game(args = null): if game_state == INGAME: return MM.close_popup() MM.visible = false game_scene = game_scene_base.instance() game_scene.set_up(GC) if args: game_scene.set_up_args(args) add_child(game_scene) game_state = INGAME # GC FUNCTIONS func on_gc_connection_failure(): MM.open_popup("Error", "Could not connect to game coordinator.") func on_join_request_success(): MM.close_popup() MM.open_popup("Connected", "Waiting for acknowledgment from host...") func on_host_success(): to_game() func on_host_failure(reason): MM.open_popup("Error", "Could not host game: %s" % reason) func on_join_success(join_args): to_game(join_args) func on_join_failure(reason): MM.open_popup("Error", "Could not join game: %s" % reason)