aboutsummaryrefslogtreecommitdiff
path: root/client/menu/play.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/menu/play.gd')
-rw-r--r--client/menu/play.gd30
1 files changed, 11 insertions, 19 deletions
diff --git a/client/menu/play.gd b/client/menu/play.gd
index 65da0372..1fe19224 100644
--- a/client/menu/play.gd
+++ b/client/menu/play.gd
@@ -28,31 +28,20 @@ var url_regex: RegEx = RegEx.new()
@onready var server_connect = $side/margin/options/second/server/connect
func _ready():
- super()
url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$")
if OS.has_feature("web"):
server.hide()
connect_uri.text = Global.get_profile("last_server_url")
Sound.play_music("MainMenu")
- update_server_list()
-
-func update_server_list():
- server_list_loading.visible = true
- req.request_completed.connect(_on_request_completed)
- req.request("https://hurrycurry-registry.metamuffin.org/v1/list", [
- "Accept: application/json",
- "User-Agent: Hurry Curry! %s" % Global.VERSION
- ])
+
+ ServerList.update_server_list.connect(update_server_list)
+ ServerList.update_loading.connect(update_server_list_loading)
+ update_server_list(ServerList.current_list)
+ update_server_list_loading(ServerList.loading)
+
+ super()
-func _on_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray):
- server_list_loading.visible = false
- if result != 0:
- push_warning("Fetching server list failed with code %d" % result)
- return
- var json = JSON.parse_string(body.get_string_from_utf8())
- if json == null:
- push_error("Server list response invalid")
- return
+func update_server_list(json: Array):
for c in server_list.get_children():
c.queue_free()
for i in json:
@@ -65,6 +54,9 @@ func _on_request_completed(result: int, _response_code: int, _headers: PackedStr
b.pressed.connect(connect_to.bind(i.address[0]))
server_list.add_child(b)
+func update_server_list_loading(status: bool):
+ server_list_loading.visible = status
+
func _menu_cover(state):
$side.visible = not state