Files
modbison/scripts/session.gd
daddy dba865ae4b PC3 Phase 2.3: networked play path in the game
- Session autoload: carries {world_id, host, port} from the world browser
  to the game scene.
- world_list.gd "Enter World": POST /api/worlds/{id}/join -> Session.begin
  -> load game.tscn. On 503 (backend has no orchestration) falls back to
  local single-player; other errors surface on the card.
- api_client.gd: join_world().
- game.gd (new, on game.tscn root): local single-player by default; when
  Session.active, connects a NetworkClient to the world's dedicated server
  and runs networked -- forwards the local Player's input each physics
  frame, snaps to the server position past a generous drift threshold
  (the Player keeps predicting locally with real collision), renders other
  players from snapshots (labelled capsules, lerped -- avatar appearance
  sync is a follow-up, the server doesn't replicate loadouts yet), and
  returns to the world list on disconnect.
- player.gd: exposes net_input (the input frame it applied) and
  apply_server_correction().
- network_client.gd: send_input() + get_own_server_state() for callers that
  do their own collision-aware prediction.
- scripts/mp_game_flow_client.gd + run_game_multiplayer_test.sh: two real
  clients each register -> join via the API -> game.tscn -> networked;
  A sees B and moves. PASS.

Verified end to end against an orchestration-enabled backend. Non-networked
smokes green (enter_world 9/9, world_list 5/5, player 15/15,
avatar_in_world 10/10, main_menu_full_flow 12/12).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015jtxAiu5dAW4WxCNdGkrkJ
2026-09-05 22:07:06 +00:00

28 lines
700 B
GDScript

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).
var world_id: int = 0
var host: String = ""
var port: int = 0
var active: 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
func clear() -> void:
world_id = 0
host = ""
port = 0
active = false