feat: sync player name and role on state patch

Persist name and role to localStorage and URL parameters when
received via patch to ensure synchronization. Broadcast full state
upon successful connection.
This commit is contained in:
hypercross 2026-07-12 10:39:53 +08:00
parent 241c8609f1
commit 40f2190307
2 changed files with 7 additions and 0 deletions

View File

@ -154,6 +154,12 @@ function handlePatch(patch: WorkerPatch): void {
s.players = patch.state.players; s.players = patch.state.players;
}), }),
); );
// Persist name/role so URL and localStorage stay in sync
if (patch.state.myName) {
saveName(patch.state.myName);
syncUrlParam("player", patch.state.myName);
}
saveRole(patch.state.myRole);
// Rebuild derived state (revealedPaths, stats) by replaying reducers // Rebuild derived state (revealedPaths, stats) by replaying reducers
replayReducers(); replayReducers();
break; break;

View File

@ -190,6 +190,7 @@ async function connectStream(
); );
notifySubscribers({ type: "connectionStatus", status: "connected" }); notifySubscribers({ type: "connectionStatus", status: "connected" });
broadcastFullState();
resolve(); resolve();
}); });