ce7a66b3e6
Replaces the Phase 10 map stub with live planet rendering driven by `user.games.report`, and wires the header turn counter to the same data. Phase 11's frontend sits on a per-game `GameStateStore` that lives in `lib/game-state.svelte.ts`: the in-game shell layout instantiates one per game, exposes it through Svelte context, and disposes it on remount. The store discovers the game's current turn through `lobby.my.games.list`, fetches the matching report, and exposes a TS-friendly snapshot to the header turn counter, the map view, and the inspector / order / calculator tabs that later phases will plug onto the same instance. The pipeline forced one cross-stage decision: the user surface needs the current turn number to know which report to fetch, but `GameSummary` did not expose it. Phase 11 extends the lobby catalogue (FB schema, transcoder, Go model, backend gameSummaryWire, gateway decoders, openapi, TS bindings, api/lobby.ts) with `current_turn:int32`. The data was already tracked in backend's `RuntimeSnapshot.CurrentTurn`; surfacing it is a wire change only. Two alternatives were rejected: a brand-new `user.games.state` message (full wire-flow for one field) and hard-coding `turn=0` (works for the dev sandbox, which never advances past zero, but renders the initial state for any real game). The change crosses Phase 8's already-shipped catalogue per the project's "decisions baked back into the live plan" rule — existing tests and fixtures are updated in the same patch. The state binding lives in `map/state-binding.ts::reportToWorld`: one Point primitive per planet across all four kinds (local / other / uninhabited / unidentified) with distinct fill colours, fill alphas, and point radii so the user can tell them apart at a glance. The planet engine number is reused as the primitive id so a hit-test result resolves directly to a planet without an extra lookup table. Zero-planet reports yield a well-formed empty world; malformed dimensions fall back to 1×1 so a bad report cannot crash the renderer. The map view's mount effect creates the renderer once and skips re-mount on no-op refreshes (same turn, same wrap mode); a turn change or wrap-mode flip disposes and recreates it. The renderer's external API does not yet expose `setWorld`; Phase 24 / 34 will extract it once high-frequency updates land. The store installs a `visibilitychange` listener that calls `refresh()` when the tab regains focus. Wrap-mode preference uses `Cache` namespace `game-prefs`, key `<gameId>/wrap-mode`, default `torus`. Phase 11 reads through `store.wrapMode`; Phase 29 wires the toggle UI on top of `setWrapMode`. Tests: Vitest unit coverage for `reportToWorld` (every kind, ids, styling, empty / zero-dimension edges, priority order) and for the store lifecycle (init success, missing-membership error, forbidden-result error, `setTurn`, wrap-mode persistence across instances, `failBootstrap`). Playwright e2e mocks the gateway for `lobby.my.games.list` and `user.games.report` and asserts the live data path: turn counter shows the reported turn, `active-view-map` flips to `data-status="ready"`, and `data-planet-count` matches the fixture count. The zero-planet regression and the missing-membership error path are covered. Phase 11 status stays `pending` in `ui/PLAN.md` until the local-ci run lands green; flipping to `done` follows in the next commit per the per-stage CI gate in `CLAUDE.md`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
189 lines
5.0 KiB
Plaintext
189 lines
5.0 KiB
Plaintext
// lobby contains FlatBuffers payloads used by the authenticated gateway
|
|
// boundary for Game Lobby. The wire shapes here mirror the trusted
|
|
// internal lobby REST surface; gateway derives the calling `user_id`
|
|
// from the verified session and forwards it as `X-User-Id` to lobby.
|
|
namespace lobby;
|
|
|
|
// GameSummary stores one game record returned by the lobby list
|
|
// endpoints. owner_user_id is empty for public games (no human owner).
|
|
// current_turn carries the runtime's most recent observed turn number
|
|
// (zero before the engine produces its first snapshot); the user
|
|
// surface uses it to read the corresponding `user.games.report`
|
|
// without an extra round-trip. The shape matches `lobby/openapi.yaml`
|
|
// `MyGameSummary`.
|
|
table GameSummary {
|
|
game_id:string;
|
|
game_name:string;
|
|
game_type:string;
|
|
status:string;
|
|
owner_user_id:string;
|
|
min_players:int32;
|
|
max_players:int32;
|
|
enrollment_ends_at_ms:int64;
|
|
created_at_ms:int64;
|
|
updated_at_ms:int64;
|
|
current_turn:int32;
|
|
}
|
|
|
|
// MyGamesListRequest stores the authenticated read request for the
|
|
// caller's games. Empty body — gateway derives identity from the
|
|
// authenticated session.
|
|
table MyGamesListRequest {
|
|
}
|
|
|
|
// MyGamesListResponse stores the list of games the caller participates
|
|
// in.
|
|
table MyGamesListResponse {
|
|
items:[GameSummary];
|
|
}
|
|
|
|
// PublicGamesListRequest stores the paginated read request for joinable
|
|
// public games. Page numbers start at 1; backend caps page_size.
|
|
table PublicGamesListRequest {
|
|
page:int32;
|
|
page_size:int32;
|
|
}
|
|
|
|
// PublicGamesListResponse stores one page of public games together with
|
|
// the pagination metadata.
|
|
table PublicGamesListResponse {
|
|
items:[GameSummary];
|
|
page:int32;
|
|
page_size:int32;
|
|
total:int32;
|
|
}
|
|
|
|
// ApplicationSummary stores one application record. decided_at_ms is 0
|
|
// while the application is pending.
|
|
table ApplicationSummary {
|
|
application_id:string;
|
|
game_id:string;
|
|
applicant_user_id:string;
|
|
race_name:string;
|
|
status:string;
|
|
created_at_ms:int64;
|
|
decided_at_ms:int64;
|
|
}
|
|
|
|
// MyApplicationsListRequest stores the authenticated read request for
|
|
// the caller's applications. Empty body.
|
|
table MyApplicationsListRequest {
|
|
}
|
|
|
|
// MyApplicationsListResponse stores the caller's applications in the
|
|
// order the backend returns them.
|
|
table MyApplicationsListResponse {
|
|
items:[ApplicationSummary];
|
|
}
|
|
|
|
// InviteSummary stores one invite record. invited_user_id is empty for
|
|
// code-based invites; code is empty for user-bound invites;
|
|
// decided_at_ms is 0 while the invite is still pending.
|
|
table InviteSummary {
|
|
invite_id:string;
|
|
game_id:string;
|
|
inviter_user_id:string;
|
|
invited_user_id:string;
|
|
code:string;
|
|
race_name:string;
|
|
status:string;
|
|
created_at_ms:int64;
|
|
expires_at_ms:int64;
|
|
decided_at_ms:int64;
|
|
}
|
|
|
|
// MyInvitesListRequest stores the authenticated read request for the
|
|
// caller's invites. Empty body.
|
|
table MyInvitesListRequest {
|
|
}
|
|
|
|
// MyInvitesListResponse stores the caller's invite list.
|
|
table MyInvitesListResponse {
|
|
items:[InviteSummary];
|
|
}
|
|
|
|
// OpenEnrollmentRequest stores the owner-only command that transitions
|
|
// a game from `draft` to `enrollment_open`.
|
|
table OpenEnrollmentRequest {
|
|
game_id:string;
|
|
}
|
|
|
|
// OpenEnrollmentResponse stores the resulting game status.
|
|
table OpenEnrollmentResponse {
|
|
game_id:string;
|
|
status:string;
|
|
}
|
|
|
|
// GameCreateRequest stores the create-game command. Visibility is
|
|
// always `private` for the user surface; the gateway rejects any other
|
|
// value before forwarding to backend.
|
|
table GameCreateRequest {
|
|
game_name:string;
|
|
description:string;
|
|
min_players:int32;
|
|
max_players:int32;
|
|
start_gap_hours:int32;
|
|
start_gap_players:int32;
|
|
enrollment_ends_at_ms:int64;
|
|
turn_schedule:string;
|
|
target_engine_version:string;
|
|
}
|
|
|
|
// GameCreateResponse wraps the freshly created game projected onto the
|
|
// shared GameSummary shape.
|
|
table GameCreateResponse {
|
|
game:GameSummary;
|
|
}
|
|
|
|
// ApplicationSubmitRequest stores the submit-application command for a
|
|
// public game in `enrollment_open`.
|
|
table ApplicationSubmitRequest {
|
|
game_id:string;
|
|
race_name:string;
|
|
}
|
|
|
|
// ApplicationSubmitResponse wraps the freshly created application
|
|
// record.
|
|
table ApplicationSubmitResponse {
|
|
application:ApplicationSummary;
|
|
}
|
|
|
|
// InviteRedeemRequest accepts a pending invite and creates the
|
|
// corresponding membership.
|
|
table InviteRedeemRequest {
|
|
game_id:string;
|
|
invite_id:string;
|
|
}
|
|
|
|
// InviteRedeemResponse wraps the updated invite record (status
|
|
// transitioned to `accepted`).
|
|
table InviteRedeemResponse {
|
|
invite:InviteSummary;
|
|
}
|
|
|
|
// InviteDeclineRequest terminally declines a pending invite.
|
|
table InviteDeclineRequest {
|
|
game_id:string;
|
|
invite_id:string;
|
|
}
|
|
|
|
// InviteDeclineResponse wraps the updated invite record (status
|
|
// transitioned to `declined`).
|
|
table InviteDeclineResponse {
|
|
invite:InviteSummary;
|
|
}
|
|
|
|
// ErrorBody stores the canonical lobby error envelope code/message
|
|
// pair.
|
|
table ErrorBody {
|
|
code:string;
|
|
message:string;
|
|
}
|
|
|
|
// ErrorResponse wraps ErrorBody for the FlatBuffers payload boundary.
|
|
table ErrorResponse {
|
|
error:ErrorBody;
|
|
}
|
|
|
|
root_type MyGamesListResponse;
|