R4: push enrichment — events carry a state delta, kill the last poll
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 13s
CI / ui (pull_request) Successful in 37s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m8s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 13s
CI / ui (pull_request) Successful in 37s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m8s
Enrich the in-app live stream into a delta channel so the UI renders a move from the event without a follow-up game.state, and make the matchmaking poll a stream-down fallback. - pkg/fbs: trailing fields on opponent_moved (move+game+bag_len), your_turn (move_count), match_found (state), game_over (game), notify (account/invitation/state), MoveResult (rack+bag_len); regenerate Go + TS. - backend: notify owns the FB encoding (encode.go + payload.go input structs); game/lobby/social map their domain types in. emitMove builds the move delta; game.Service.InitialState feeds match_found/game_started the recipient's initial StateView; friends/invitations notify carry their account/invitation. The move-commit response (submit_play/pass/exchange/resign) returns the actor's refilled rack + bag size. - gateway: MoveResult transcode carries rack+bag_len. - ui: pure lib/gamedelta.ts reducer advances the per-game cache keyed on move_count (idempotent + gap-safe); app.svelte seeds the cache on match_found/game_started; Game.svelte applies the delta (commit/pass/exchange/resign drop their load()); NewGame polls only while app.streamAlive is false. - docs: ARCHITECTURE §10, FUNCTIONAL(+ru), backend/gateway/ui READMEs; PRERELEASE R4 marked done + Refinements.
This commit is contained in:
+51
-9
@@ -322,12 +322,12 @@ export function decodeProfile(buf: Uint8Array): Profile {
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeStateView(buf: Uint8Array): StateView {
|
||||
const v = fb.StateView.getRootAsStateView(new ByteBuffer(buf));
|
||||
// decodeStateViewTable projects a StateView table (a root or one nested in an event) to the
|
||||
// model. It caches the alphabet when present (a per-variant cache miss) and decodes the index
|
||||
// rack to display letters with it (Stage 13).
|
||||
function decodeStateViewTable(v: fb.StateView): StateView {
|
||||
const g = v.game();
|
||||
const variant = (g ? s(g.variant()) : 'scrabble_en') as Variant;
|
||||
// Cache the alphabet table when the server included it (a per-variant cache miss), then
|
||||
// decode the index rack to display letters with it (Stage 13).
|
||||
if (v.alphabetLength() > 0) {
|
||||
const entries: AlphabetEntryWire[] = [];
|
||||
for (let i = 0; i < v.alphabetLength(); i++) {
|
||||
@@ -347,11 +347,24 @@ export function decodeStateView(buf: Uint8Array): StateView {
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeStateView(buf: Uint8Array): StateView {
|
||||
return decodeStateViewTable(fb.StateView.getRootAsStateView(new ByteBuffer(buf)));
|
||||
}
|
||||
|
||||
export function decodeMoveResult(buf: Uint8Array): MoveResult {
|
||||
const r = fb.MoveResult.getRootAsMoveResult(new ByteBuffer(buf));
|
||||
const m = r.move();
|
||||
const g = r.game();
|
||||
return { move: m ? decodeMove(m) : emptyMove(), game: g ? decodeGameView(g) : emptyGame() };
|
||||
// The actor's refilled rack rides back as alphabet indices (R4); decode it with the game's variant.
|
||||
const variant = (g ? s(g.variant()) : 'scrabble_en') as Variant;
|
||||
const rack: string[] = [];
|
||||
for (let i = 0; i < r.rackLength(); i++) rack.push(letterForIndex(variant, r.rack(i) ?? 0));
|
||||
return {
|
||||
move: m ? decodeMove(m) : emptyMove(),
|
||||
game: g ? decodeGameView(g) : emptyGame(),
|
||||
rack,
|
||||
bagLen: r.bagLen(),
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeHintResult(buf: Uint8Array): HintResult {
|
||||
@@ -424,11 +437,30 @@ export function decodeEvent(kind: string, payload: Uint8Array): PushEvent | null
|
||||
switch (kind) {
|
||||
case 'your_turn': {
|
||||
const e = fb.YourTurnEvent.getRootAsYourTurnEvent(bb);
|
||||
return { kind: 'your_turn', gameId: s(e.gameId()), deadlineUnix: Number(e.deadlineUnix()) };
|
||||
return { kind: 'your_turn', gameId: s(e.gameId()), deadlineUnix: Number(e.deadlineUnix()), moveCount: e.moveCount() };
|
||||
}
|
||||
case 'opponent_moved': {
|
||||
const e = fb.OpponentMovedEvent.getRootAsOpponentMovedEvent(bb);
|
||||
return { kind: 'opponent_moved', gameId: s(e.gameId()), seat: e.seat(), action: s(e.action()), score: e.score(), total: e.total() };
|
||||
const m = e.move();
|
||||
const g = e.game();
|
||||
return {
|
||||
kind: 'opponent_moved',
|
||||
gameId: s(e.gameId()),
|
||||
move: m ? decodeMove(m) : undefined,
|
||||
game: g ? decodeGameView(g) : undefined,
|
||||
bagLen: e.bagLen(),
|
||||
};
|
||||
}
|
||||
case 'game_over': {
|
||||
const e = fb.GameOverEvent.getRootAsGameOverEvent(bb);
|
||||
const g = e.game();
|
||||
return {
|
||||
kind: 'game_over',
|
||||
gameId: s(e.gameId()),
|
||||
result: s(e.result()),
|
||||
scoreLine: s(e.scoreLine()),
|
||||
game: g ? decodeGameView(g) : undefined,
|
||||
};
|
||||
}
|
||||
case 'chat_message':
|
||||
return { kind: 'chat_message', message: decodeChatMsg(fb.ChatMessage.getRootAsChatMessage(bb)) };
|
||||
@@ -438,11 +470,21 @@ export function decodeEvent(kind: string, payload: Uint8Array): PushEvent | null
|
||||
}
|
||||
case 'match_found': {
|
||||
const e = fb.MatchFoundEvent.getRootAsMatchFoundEvent(bb);
|
||||
return { kind: 'match_found', gameId: s(e.gameId()) };
|
||||
const st = e.state();
|
||||
return { kind: 'match_found', gameId: s(e.gameId()), state: st ? decodeStateViewTable(st) : undefined };
|
||||
}
|
||||
case 'notify': {
|
||||
const e = fb.NotificationEvent.getRootAsNotificationEvent(bb);
|
||||
return { kind: 'notify', sub: s(e.kind()) };
|
||||
const acc = e.account();
|
||||
const inv = e.invitation();
|
||||
const st = e.state();
|
||||
return {
|
||||
kind: 'notify',
|
||||
sub: s(e.kind()),
|
||||
account: acc ? decodeAccountRef(acc) : undefined,
|
||||
invitation: inv ? decodeInvitationTable(inv) : undefined,
|
||||
state: st ? decodeStateViewTable(st) : undefined,
|
||||
};
|
||||
}
|
||||
case 'heartbeat':
|
||||
return { kind: 'heartbeat' };
|
||||
|
||||
Reference in New Issue
Block a user