summaryrefslogtreecommitdiff
path: root/UI/Start.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-26 17:13:40 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-26 17:13:40 +0100
commitcb9bb9d1c757b53707c741a3c8c218b513ffb5ec (patch)
tree1e3741a70672504d71685db98b22f7fe61e0e6cb /UI/Start.gd
parent72863ffa31e27f4c6be862d80472cfb897fccaea (diff)
next commit
Diffstat (limited to 'UI/Start.gd')
-rw-r--r--UI/Start.gd40
1 files changed, 30 insertions, 10 deletions
diff --git a/UI/Start.gd b/UI/Start.gd
index fbfa8db..b078d65 100644
--- a/UI/Start.gd
+++ b/UI/Start.gd
@@ -6,9 +6,11 @@ func _ready():
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
if OS.has_environment("USER"):
- %Name.text = OS.get_environment("USER")
+ %Username.text = OS.get_environment("USER")
elif OS.has_environment("USERNAME"):
- %Name.text = OS.get_environment("USERNAME")
+ %Username.text = OS.get_environment("USERNAME")
+
+ %GameName.text = "%s's Game" % [%Username.text]
func get_ip() -> String:
@@ -27,19 +29,37 @@ func get_port() -> int:
return port
+func _on_peer_connected(id):
+ Network._on_peer_connected(id)
+func _on_peer_disconnected(id):
+ Network._on_peer_disconnected(id)
+
+
func _on_host_pressed() -> void:
- Client.player.username = %Name.text
+ 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})
+ )
+
+ if response.result_code == HTTPRequest.RESULT_SUCCESS:
+ var result = response.parse_json()
+ if result["success"]:
+ Client.current_game_id = result["data"]
+
Network.host_game(get_port())
- get_tree().change_scene_to_file("res://UI/Lobby.tscn")
+ get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn")
func _on_join_pressed() -> void:
- Client.player.username = %Name.text
+ Client.player.username = %Username.text
Network.join_game(get_ip(), get_port())
- get_tree().change_scene_to_file("res://UI/Lobby.tscn")
+ get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn")
-func _on_peer_connected(id):
- Network._on_peer_connected(id)
-func _on_peer_disconnected(id):
- Network._on_peer_disconnected(id)
+func _on_search_pressed() -> void:
+ Client.player.username = %Username.text
+ get_tree().change_scene_to_file("res://UI/GameLobby/game_lobby.tscn")