From a854a1862a30632e49520f6e1e11333d5c8ff241 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 27 Nov 2024 14:36:20 +0100 Subject: next commit --- UI/GameLobby/game_lobby.gd | 6 +++--- UI/GameLobby/lobby_game.gd | 15 +++++++++------ UI/PlayerLobby/lobby.gd | 9 +-------- UI/Start.gd | 13 ++++--------- UI/Start.tscn | 2 -- 5 files changed, 17 insertions(+), 28 deletions(-) (limited to 'UI') diff --git a/UI/GameLobby/game_lobby.gd b/UI/GameLobby/game_lobby.gd index 9f13882..85a8a91 100644 --- a/UI/GameLobby/game_lobby.gd +++ b/UI/GameLobby/game_lobby.gd @@ -16,11 +16,11 @@ func _ready() -> void: $RefreshTimer.wait_time = refresh_interval $RefreshTimer.start() else: - %ServerNotReachable.text = %ServerNotReachable.text.replace("%SERVER%", Client.game_lobby_url) + %ServerNotReachable.text = %ServerNotReachable.text.replace("%SERVER%", GameLobby.server_base_url) func check_game_lobby_available(): - var is_available = await Client.check_game_lobby_available() + var is_available = await GameLobby.check_available() %ServerNotReachable.visible = !is_available @@ -28,7 +28,7 @@ func check_game_lobby_available(): func get_server_list(): - var response = await Client.request("%s/?get-list" % [Client.game_lobby_url], [], HTTPClient.METHOD_GET) + var response = await GameLobby.request_get("/get-list") var result = response.parse_json() print(result) diff --git a/UI/GameLobby/lobby_game.gd b/UI/GameLobby/lobby_game.gd index 4736d44..2433dfd 100644 --- a/UI/GameLobby/lobby_game.gd +++ b/UI/GameLobby/lobby_game.gd @@ -11,9 +11,12 @@ func set_game_name(value): func _on_join_pressed() -> void: - var response = await Network.request("%s/?join=%s" % [Client.game_lobby_url, game_id]) - var result = response.parse_json() - var game_data = result["data"] - - Network.join_game(game_data["ip"], game_data["port"]) - get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn") + var response = await GameLobby.request_get("/join?id=%s" % [game_id]) + if response.response_code == 200: + var result = response.parse_json() + var game_data = result["data"] + + Network.join_game(game_data["ip"], game_data["port"]) + get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn") + else: + print(response.response_code) diff --git a/UI/PlayerLobby/lobby.gd b/UI/PlayerLobby/lobby.gd index 6506097..4169478 100644 --- a/UI/PlayerLobby/lobby.gd +++ b/UI/PlayerLobby/lobby.gd @@ -45,7 +45,7 @@ func _ready() -> void: if multiplayer.is_server(): $KeepAliveTimer.start() $KeepAliveTimer.timeout.connect(func(): - Client.request(Client.game_lobby_url, [], HTTPClient.METHOD_POST, JSON.stringify({"keep-alive": Client.current_game_id})) + GameLobby.request_post("/keep-alive") ) @@ -92,13 +92,6 @@ func _on_start_button_pressed() -> void: func _on_cancel_button_pressed() -> void: multiplayer.multiplayer_peer.close() - await Client.request( - "%s" % [Client.game_lobby_url], - [], - HTTPClient.METHOD_POST, - JSON.stringify({"close": Client.current_game_id}) - ) - # TODO: if was host => Start. if was joined and connected from list => List get_tree().change_scene_to_file("res://UI/Start.tscn") diff --git a/UI/Start.gd b/UI/Start.gd index b078d65..85a7946 100644 --- a/UI/Start.gd +++ b/UI/Start.gd @@ -22,7 +22,7 @@ func get_ip() -> String: func get_port() -> int: - var port := 1234 + var port: int = Client.get_config().get_value("general", "host_default_port") if %Port.text: port = int(%Port.text) @@ -38,17 +38,12 @@ func _on_peer_disconnected(id): func _on_host_pressed() -> void: Client.player.username = %Username.text - var response = await Client.request( - "%s" % [Client.game_lobby_url], - [], - HTTPClient.METHOD_POST, - JSON.stringify({"host": true, "port": get_port(), "name" : %GameName.text}) - ) - + var response = await GameLobby.request_post("/host", {"port": get_port(), "name" : %GameName.text}) if response.result_code == HTTPRequest.RESULT_SUCCESS: var result = response.parse_json() if result["success"]: - Client.current_game_id = result["data"] + GameLobby.current_game_id = result["data"]["id"] + GameLobby.current_secret = result["data"]["secret"] Network.host_game(get_port()) get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn") diff --git a/UI/Start.tscn b/UI/Start.tscn index efa061c..b0d4ac2 100644 --- a/UI/Start.tscn +++ b/UI/Start.tscn @@ -100,8 +100,6 @@ mouse_default_cursor_shape = 2 theme_override_font_sizes/font_size = 24 text = "Search" -[node name="ServerHost" type="HTTPRequest" parent="."] - [connection signal="pressed" from="CenterContainer/VBoxContainer/Host" to="." method="_on_host_pressed"] [connection signal="pressed" from="CenterContainer/VBoxContainer/Join" to="." method="_on_join_pressed"] [connection signal="pressed" from="CenterContainer/VBoxContainer/Search" to="." method="_on_search_pressed"] -- cgit v1.2.3