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:
parent
241c8609f1
commit
40f2190307
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,7 @@ async function connectStream(
|
||||||
);
|
);
|
||||||
|
|
||||||
notifySubscribers({ type: "connectionStatus", status: "connected" });
|
notifySubscribers({ type: "connectionStatus", status: "connected" });
|
||||||
|
broadcastFullState();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue