diff options
Diffstat (limited to 'Game/Client.gd')
-rw-r--r-- | Game/Client.gd | 56 |
1 files changed, 14 insertions, 42 deletions
diff --git a/Game/Client.gd b/Game/Client.gd index fd24a07..6e08a58 100644 --- a/Game/Client.gd +++ b/Game/Client.gd @@ -11,10 +11,6 @@ signal multi_select_finished(nodes) var previous_scene: String -var game_lobby_url := "http://localhost:8910" -@onready var game_lobby_server: HTTPRequest = %GameLobbyServer -var current_game_id := "" - var state: State : set(value): state = value @@ -109,12 +105,26 @@ func update_unit(path: NodePath, data: Unit.NetworkData): func change_scene_to_instance(scene: Node): (func(): + previous_scene = get_tree().current_scene.get_path() + get_tree().current_scene.queue_free() get_tree().root.add_child(scene) get_tree().current_scene = scene ).call_deferred() +func get_config() -> ConfigFile: + var config := ConfigFile.new() + config.load("user://config") + + if not FileAccess.file_exists("user://config"): + config.set_value("general", "host_default_port", 1234) + config.set_value("general", "game_lobby_server_base_url", "http://localhost:8910") + config.save("user://config") + + return config + + func array_intersect(first, second): var compare = {} for value in first: @@ -125,41 +135,3 @@ func array_intersect(first, second): return true return false - - -class HTTPResponse extends Resource: - var result_code: HTTPRequest.Result - var response_code: int - var headers: PackedStringArray - var body: PackedByteArray - func parse_json() -> Dictionary: - return JSON.parse_string(body.get_string_from_utf8()) - -func request( - url: String, - custom_headers: PackedStringArray = PackedStringArray(), - method: HTTPClient.Method = HTTPClient.METHOD_GET, - request_data: String = "" -) -> HTTPResponse: - var response = HTTPResponse.new() - - %GameLobbyServer.request_completed.connect( - func ( - result_code: int, - response_code: int, - headers: PackedStringArray, - body: PackedByteArray - ): - response.result_code = result_code - response.response_code = response_code - response.headers = headers - response.body = body - ) - %GameLobbyServer.request(url, custom_headers, method, request_data) - - await %GameLobbyServer.request_completed - return response - -func check_game_lobby_available() -> bool: - var response = await Client.request("%s" % [Client.game_lobby_url], [], HTTPClient.METHOD_GET) - return response.result_code == HTTPRequest.RESULT_SUCCESS |