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%", GameLobby.server_base_url) func check_game_lobby_available(): var is_available = await GameLobby.check_available() %ServerNotReachable.visible = !is_available return is_available func get_server_list(): var response = await GameLobby.request_get("/get-list") 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()