extends Node ## Autoload "Session" -- carries the "which world am I joining" handoff from ## the world browser to the game scene. ## ## world_list.gd calls begin() with the address returned by ## POST /api/worlds/{id}/join; game.gd reads it in _ready() to decide whether ## to run networked or fall back to local single-player (e.g. game.tscn opened ## directly, or the backend has no orchestration). ## ## world_list.gd also calls begin_edit() for the "Edit world" entry point ## (docs/architecture/world_persistence_impl.md §6 D4): editing is ## deliberately **non-joined** -- it never calls POST /join, so `active` ## stays false and game.gd never opens an ENet connection for it. `editing` ## is the separate signal game.gd checks to open the in-game editor against ## a real, HTTP-fetched chunk instead of running gameplay. var world_id: int = 0 var host: String = "" var port: int = 0 var active: bool = false var editing: bool = false func begin(p_world_id: int, p_host: String, p_port: int) -> void: world_id = p_world_id host = p_host port = p_port active = true editing = false ## Enter "Edit world" (world_persistence_impl.md §6 D4): non-joined, no ## ENet connection, no dedicated server. game.gd loads/saves chunks over ## HTTP instead. func begin_edit(p_world_id: int) -> void: world_id = p_world_id host = "" port = 0 active = false editing = true func clear() -> void: world_id = 0 host = "" port = 0 active = false editing = false func _unhandled_input(event: InputEvent) -> void: if event is InputEventKey and event.pressed and not event.echo: if event.keycode == KEY_F11 or (event.keycode == KEY_ENTER and event.alt_pressed): toggle_fullscreen() get_viewport().set_input_as_handled() func toggle_fullscreen() -> void: if DisplayServer.get_name() == "headless": return var current_mode := DisplayServer.window_get_mode() if current_mode == DisplayServer.WINDOW_MODE_FULLSCREEN or current_mode == DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) var screen_id := DisplayServer.window_get_current_screen() var screen_rect := DisplayServer.screen_get_usable_rect(screen_id) var target_w := mini(1280, int(screen_rect.size.x * 0.9)) var target_h := mini(720, int(screen_rect.size.y * 0.9)) DisplayServer.window_set_size(Vector2i(target_w, target_h)) var pos := screen_rect.position + (screen_rect.size - Vector2i(target_w, target_h)) / 2 DisplayServer.window_set_position(pos) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)