diff options
Diffstat (limited to 'client/menu/main.gd')
-rw-r--r-- | client/menu/main.gd | 85 |
1 files changed, 1 insertions, 84 deletions
diff --git a/client/menu/main.gd b/client/menu/main.gd index dbb096f1..9b809776 100644 --- a/client/menu/main.gd +++ b/client/menu/main.gd @@ -17,24 +17,12 @@ # extends Menu -var url_regex: RegEx = RegEx.new() - @onready var quit_button = $side/margin/options/first/quit -@onready var connect_uri = $side/margin/options/second/connect/uri -@onready var server = $side/margin/options/second/server -@onready var server_control = $side/margin/options/second/server/control -@onready var server_connect = $side/margin/options/second/server/connect - -@onready var first_menu = $side/margin/options/first -@onready var second_menu = $side/margin/options/second func _ready(): super() - url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$") if OS.has_feature("web"): quit_button.hide() - server.hide() - connect_uri.text = Global.get_profile("last_server_url") Sound.play_music("MainMenu") func _menu_cover(state): @@ -46,82 +34,11 @@ func _on_quit_pressed(): func _on_credits_pressed(): submenu("res://menu/credits.tscn") -func _on_connect_pressed(): - var url = connect_uri.text - var result := url_regex.search(url) - if result != null: - if result.get_string(1) == "": - url = "ws://" + url - # only set default port for non-tls websocket connections - if result.get_string(3) == "" and result.get_string(1) != "wss": - url = url + ":27032" - connect_uri.text = url - Global.set_profile("last_server_url", url) - connect_to(url) - - -func _on_quick_connect_pressed(): - if OS.has_feature("JavaScript"): - connect_to(JavaScriptBridge.eval(""" - window.location.protocol.endsWith("s:") - ? `wss://${window.location.host}/` - : `ws://${window.location.hostname}:27032/` - """)) - else: - connect_to("wss://hurrycurry.metamuffin.org/") - -func connect_to(url: String): - print("Connecting to %s" % url) - Global.server_url = url - replace_menu("res://menu/game.tscn") - func _on_change_character_pressed(): replace_menu("res://menu/character.tscn") func _on_settings_pressed(): submenu("res://menu/settings.tscn") -func _on_server_pressed(): - match Server.state: - Server.State.RUNNING: Server.stop() - Server.State.STOPPED: Server.start() - Server.State.FAILED: Server.start() - -func _on_server_connect_pressed(): - connect_to("ws://127.0.0.1:27032/") - -func _process(_delta): - server_control.disabled = false - server_connect.visible = Server.state == Server.State.RUNNING - server_control.modulate = Color.WHITE - match Server.state: - Server.State.RUNNING: - server_control.text = tr("Stop Server") - server_control.modulate = Color.AQUAMARINE - Server.State.TESTING: - server_control.text = tr("Server (Testing)") - server_control.disabled = true - Server.State.STARTING: - server_control.text = tr("Server is starting...") - server_control.disabled = true - Server.State.STOPPED: - server_control.text = tr("Start Server") - Server.State.FAILED: - server_control.text = tr("Server (Failed)") - server_control.modulate = Color(1,0.4,0.5) - server_control.tooltip_text = tr("The server crashed or exited in some way or another.\nGodot's APIs are so bad however, that we really can't know why that happend.\nYou should try starting the server from the command-line.") - Server.State.UNAVAILABLE: - server_control.text = tr("Server (Unavailable)") - server_control.disabled = true - server_control.tooltip_text = tr("Server binary was not found. Please install the server separately.") - -func _on_uri_text_changed(new_text): - connect_uri.modulate = Color.WHITE if url_regex.search(new_text) else Color.RED - func _on_play_pressed(): - first_menu.hide() - second_menu.show() - -func _on_back_pressed(): - first_menu.show() - second_menu.hide() + submenu("res://menu/play.tscn") |