summaryrefslogtreecommitdiff
path: root/UI
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-27 14:36:20 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-27 14:36:20 +0100
commita854a1862a30632e49520f6e1e11333d5c8ff241 (patch)
tree2b10c4d19bb66b270a7726d660ed85d7fcf9482e /UI
parentcb9bb9d1c757b53707c741a3c8c218b513ffb5ec (diff)
next commit
Diffstat (limited to 'UI')
-rw-r--r--UI/GameLobby/game_lobby.gd6
-rw-r--r--UI/GameLobby/lobby_game.gd15
-rw-r--r--UI/PlayerLobby/lobby.gd9
-rw-r--r--UI/Start.gd13
-rw-r--r--UI/Start.tscn2
5 files changed, 17 insertions, 28 deletions
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"]