From ed3588dd2f750d511de992a6db3ea8ba257dae8d Mon Sep 17 00:00:00 2001 From: Adrien Jaguenet Date: Tue, 15 Sep 2026 21:55:57 +0200 Subject: [PATCH] Removed stupid requirement about game creation --- scenes/ui/new_game_screen.gd | 11 +++-------- scripts/classes/network.gd | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/scenes/ui/new_game_screen.gd b/scenes/ui/new_game_screen.gd index f738490..3d6881c 100644 --- a/scenes/ui/new_game_screen.gd +++ b/scenes/ui/new_game_screen.gd @@ -39,11 +39,6 @@ func _ready() -> void: func _on_start_game_pressed() -> void: - # A browser cannot spawn a server process; the web client joins a dedicated - # server instead, and its first player configures the game as admin. - if OS.has_feature("web"): - status_label.text = "Creating a game needs the desktop client. Use \"Join a game\" instead." - return var player: CivDescription = CIVILISATIONS[player_civ_option.selected] var civilisations: Array[CivDescription] = [player] for civ in CIVILISATIONS: @@ -59,10 +54,10 @@ func _on_start_game_pressed() -> void: status_label.text = "Enter a name and a password." return _set_input_enabled(false) - status_label.text = "Starting the game server..." - var error := Network.host_game() + status_label.text = "Starting the game..." + var error := Network.create_game() if error != OK: - _on_session_failed("Could not start the game server.") + _on_session_failed("Could not start the game.") func _on_session_started() -> void: diff --git a/scripts/classes/network.gd b/scripts/classes/network.gd index 231964f..4077fcb 100644 --- a/scripts/classes/network.gd +++ b/scripts/classes/network.gd @@ -9,9 +9,11 @@ extends Node ## `ws://` or `wss://` URL. On the web the client defaults to the page's own ## origin, so a server and its web client can share one host and port. ## -## Creating a new game spawns the server as a separate headless instance of the -## game and then connects this process to it as a client. The first player to -## log in becomes the game's admin and stays admin across reconnections, +## Creating a new game connects this process to an authoritative server as its +## first player, who becomes the game's admin and configures it. On the web the +## server is the dedicated instance already serving the page (a browser cannot +## spawn processes); elsewhere a dedicated headless instance is spawned and the +## client connects to that. Admin stays with the player across reconnections, ## because admin is tied to the player's name rather than their peer id. ## ## Joining requires a name and a password. A new name sets its password on its @@ -115,6 +117,15 @@ func send_game_state(peer_id: int, snapshot: Dictionary) -> void: _rpc_game_state.rpc_id(peer_id, snapshot) +## Starts a new game. The web client cannot spawn a server, so it creates the +## game on the dedicated server already serving the page; elsewhere a dedicated +## server process is spawned and the client connects to it. +func create_game() -> Error: + if OS.has_feature("web"): + return join_game_url(default_server_url()) + return host_game() + + ## Spawns a dedicated server process and connects to it as a client. func host_game() -> Error: var port := _find_free_port()