fix(offline): keep the local game's composition across a state reload
A local (offline) game persisted no draft: draftGet returned an empty string and draftSave was a no-op, on the assumption that the arrangement is only ever rebuilt from the rack when the game is reopened. The game screen, however, refetches the state on several triggers, and every one of them applied that empty draft over the live composition — dropping the player's pending tiles back into the rack and resetting the rack order. Offline the most visible trigger fires on its own: with no network the live-stream watchdog declares the stream dead after 25 s, the reconnect 4 s later flips app.streamAlive back to true, and the game screen's reconnect effect refetches. Composing a move offline was therefore reset roughly every half minute. Store the draft in the game's own record instead, so a reload restores it and it survives leaving and reopening the app, and clear it wherever the turn advances (a committed move, a resignation, a host skip) so a hotseat seat never inherits the previous player's arrangement. Gate the two stream-driven refetches on the game being a network one: a local game takes its events from the source, so reacting to the stream only cost it a pointless reload.
This commit is contained in:
@@ -53,6 +53,13 @@ export interface LocalGameRecord {
|
||||
* read through a sanitiser (cap at now + window) so a device clock set back cannot freeze it —
|
||||
* see lib/hints. */
|
||||
hintUnlockAtMs: number;
|
||||
/** The seated player's in-progress composition (rack order + pending board tiles) as the draft
|
||||
* JSON the game screen serialises, or absent when there is none. A local game keeps it here —
|
||||
* there is no server to hold it — so a reload of the game state restores the arrangement instead
|
||||
* of dropping the tiles back into the rack. It belongs to the turn: the source clears it wherever
|
||||
* the turn advances (a committed move, a resignation, a host skip), so a hotseat seat never
|
||||
* inherits the previous player's arrangement. */
|
||||
draft?: string;
|
||||
}
|
||||
|
||||
/** The record fields the caller owns (the engine supplies the rest). */
|
||||
@@ -64,6 +71,7 @@ export interface RecordMeta {
|
||||
createdAtUnix: number;
|
||||
updatedAtUnix: number;
|
||||
hintUnlockAtMs: number;
|
||||
draft?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +96,7 @@ export function serializeGame(game: LocalGame, meta: RecordMeta): LocalGameRecor
|
||||
createdAtUnix: meta.createdAtUnix,
|
||||
updatedAtUnix: meta.updatedAtUnix,
|
||||
hintUnlockAtMs: meta.hintUnlockAtMs,
|
||||
draft: meta.draft,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user