summaryrefslogtreecommitdiff
path: root/UI/GameLobby/game_lobby.gd
diff options
context:
space:
mode:
Diffstat (limited to 'UI/GameLobby/game_lobby.gd')
-rw-r--r--UI/GameLobby/game_lobby.gd57
1 files changed, 57 insertions, 0 deletions
diff --git a/UI/GameLobby/game_lobby.gd b/UI/GameLobby/game_lobby.gd
new file mode 100644
index 0000000..9f13882
--- /dev/null
+++ b/UI/GameLobby/game_lobby.gd
@@ -0,0 +1,57 @@
+extends Control
+
+
+var games := []
+
+var refresh_interval := 15.0
+
+@onready var lobby_game_scene := preload("res://UI/GameLobby/lobby_game.tscn")
+
+
+func _ready() -> void:
+ %GamesList.get_child(0).queue_free()
+
+ if await check_game_lobby_available():
+ get_server_list()
+ $RefreshTimer.wait_time = refresh_interval
+ $RefreshTimer.start()
+ else:
+ %ServerNotReachable.text = %ServerNotReachable.text.replace("%SERVER%", Client.game_lobby_url)
+
+
+func check_game_lobby_available():
+ var is_available = await Client.check_game_lobby_available()
+
+ %ServerNotReachable.visible = !is_available
+
+ return is_available
+
+
+func get_server_list():
+ var response = await Client.request("%s/?get-list" % [Client.game_lobby_url], [], HTTPClient.METHOD_GET)
+ var result = response.parse_json()
+ print(result)
+
+ if result["success"]:
+ for node in %GamesList.get_children():
+ node.queue_free()
+
+ for game in result["data"]:
+ var lobby_game = lobby_game_scene.instantiate()
+ lobby_game.game_id = game["id"]
+ lobby_game.game_name = game["name"]
+ %GamesList.add_child(lobby_game)
+
+
+func _on_back_button_pressed() -> void:
+ get_tree().change_scene_to_file("res://UI/Start.tscn")
+
+
+func _on_refresh_pressed() -> void:
+ if await check_game_lobby_available():
+ get_server_list()
+ $RefreshTimer.start(refresh_interval)
+
+
+func _on_refresh_timer_timeout() -> void:
+ get_server_list()