fix: restore lobby state on refresh, handle game.status heartbeat
- Extract maxPlayers from game object in #applyGameAdded so the meter works immediately when a game is added - Read playerName field in lobby.player-joined (matches API payload) - Handle game.status 20s heartbeat to keep overlay in sync - Restore in-progress game on page refresh using status-live endpoint for full shard state including player names Made-with: Cursor
This commit is contained in:
@@ -217,6 +217,15 @@ export class OverlayManager {
|
||||
this.#transitionTo('idle');
|
||||
break;
|
||||
|
||||
case 'game.status':
|
||||
this.#applyGameStatus(d);
|
||||
if (this.#state === 'idle' && d.gameState === 'Lobby') {
|
||||
this.#transitionTo('lobby');
|
||||
} else {
|
||||
this.#broadcastUpdate();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'player-count.updated':
|
||||
this.#applyPlayerCountUpdated(d);
|
||||
this.#broadcastUpdate();
|
||||
@@ -286,6 +295,8 @@ export class OverlayManager {
|
||||
const code =
|
||||
game.room_code ?? game.roomCode ?? game.code;
|
||||
if (code != null) this.#context.roomCode = String(code);
|
||||
const mp = game.max_players ?? game.maxPlayers;
|
||||
if (mp != null) this.#context.maxPlayers = Number(mp);
|
||||
this.#context.game = { ...game };
|
||||
}
|
||||
|
||||
@@ -306,8 +317,8 @@ export class OverlayManager {
|
||||
if (d.maxPlayers != null) this.#context.maxPlayers = Number(d.maxPlayers);
|
||||
if (d.playerCount != null) this.#context.playerCount = Number(d.playerCount);
|
||||
if (Array.isArray(d.players)) this.#context.players = [...d.players];
|
||||
if (d.player !== undefined) this.#context.lastJoinedPlayer = d.player;
|
||||
if (d.lastJoinedPlayer !== undefined) this.#context.lastJoinedPlayer = d.lastJoinedPlayer;
|
||||
const joined = d.playerName ?? d.player ?? d.lastJoinedPlayer;
|
||||
if (joined !== undefined) this.#context.lastJoinedPlayer = joined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,6 +329,17 @@ export class OverlayManager {
|
||||
if (d.playerCount != null) this.#context.playerCount = Number(d.playerCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown>} d
|
||||
*/
|
||||
#applyGameStatus(d) {
|
||||
if (d.roomCode != null) this.#context.roomCode = String(d.roomCode);
|
||||
if (d.maxPlayers != null) this.#context.maxPlayers = Number(d.maxPlayers);
|
||||
if (d.playerCount != null) this.#context.playerCount = Number(d.playerCount);
|
||||
if (Array.isArray(d.players)) this.#context.players = [...d.players];
|
||||
if (d.lobbyState !== undefined) this.#context.lobbyState = d.lobbyState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown>} d
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user