Skip to content

Commit ab960a8

Browse files
committed
Attempt to fix Game States. Edit is gone.
1 parent 6e7bff0 commit ab960a8

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

artifacts/game-client/src/apps/adepts-game-2/hooks/useGameState.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type GameState = {
2626
/** Текущий ход: индекс места игрока 0..4 */
2727
currentTurnSeat: number;
2828
quizBoardHoverCell?: QuizBoardHoverCell;
29+
/** Идентификатор доски — проверяется в sync-обработчике для отклонения данных чужой доски */
30+
boardRoom?: string;
2931
};
3032

3133
function gd(id: string) {
@@ -382,8 +384,10 @@ export function useGameState() {
382384
hadRoster &&
383385
typeof localStorage !== "undefined" &&
384386
localStorage.getItem("player_role") === "host";
387+
const isSameBoard = incoming.boardRoom === ROOM;
385388
const nextState = {
386389
...incoming,
390+
themes: isSameBoard ? (incoming.themes ?? DEFAULT_STATE.themes) : DEFAULT_STATE.themes,
387391
players: merged,
388392
activeQuizCard: incoming.activeQuizCard ?? null,
389393
currentTurnSeat: hostResetTurn
@@ -394,15 +398,17 @@ export function useGameState() {
394398
questions: DEFAULT_STATE.questions.map((themeQs, tIdx) =>
395399
themeQs.map((defaultQ, qIdx) => ({
396400
...defaultQ,
397-
used: incoming.questions?.[tIdx]?.[qIdx]?.used ?? defaultQ.used,
401+
used: isSameBoard
402+
? (incoming.questions?.[tIdx]?.[qIdx]?.used ?? defaultQ.used)
403+
: defaultQ.used,
398404
}))
399405
),
400406
};
401407
skipEmitRef.current = true;
402408
setState(nextState);
403409
if (hadRoster) {
404410
skipEmitRef.current = false;
405-
queueMicrotask(() => socketRef.current?.emit("update", nextState));
411+
queueMicrotask(() => socketRef.current?.emit("update", { ...nextState, boardRoom: ROOM }));
406412
}
407413
});
408414

@@ -421,7 +427,7 @@ export function useGameState() {
421427
return;
422428
}
423429

424-
socketRef.current?.emit("update", state);
430+
socketRef.current?.emit("update", { ...state, boardRoom: ROOM });
425431
}, [state]);
426432

427433
useEffect(() => {

artifacts/game-client/src/apps/adepts-game-3/hooks/useGameState.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export type GameState = {
2626
/** Текущий ход: индекс места игрока 0..4 */
2727
currentTurnSeat: number;
2828
quizBoardHoverCell?: QuizBoardHoverCell;
29+
/** Идентификатор доски — проверяется в sync-обработчике для отклонения данных чужой доски */
30+
boardRoom?: string;
2931
};
3032

3133
function gd(id: string) {
@@ -568,8 +570,10 @@ export function useGameState() {
568570
hadRoster &&
569571
typeof localStorage !== "undefined" &&
570572
localStorage.getItem("player_role") === "host";
573+
const isSameBoard = incoming.boardRoom === ROOM;
571574
const nextState = {
572575
...incoming,
576+
themes: isSameBoard ? (incoming.themes ?? DEFAULT_STATE.themes) : DEFAULT_STATE.themes,
573577
players: merged,
574578
activeQuizCard: incoming.activeQuizCard ?? null,
575579
currentTurnSeat: hostResetTurn
@@ -580,15 +584,17 @@ export function useGameState() {
580584
questions: DEFAULT_STATE.questions.map((themeQs, tIdx) =>
581585
themeQs.map((defaultQ, qIdx) => ({
582586
...defaultQ,
583-
used: incoming.questions?.[tIdx]?.[qIdx]?.used ?? defaultQ.used,
587+
used: isSameBoard
588+
? (incoming.questions?.[tIdx]?.[qIdx]?.used ?? defaultQ.used)
589+
: defaultQ.used,
584590
}))
585591
),
586592
};
587593
skipEmitRef.current = true;
588594
setState(nextState);
589595
if (hadRoster) {
590596
skipEmitRef.current = false;
591-
queueMicrotask(() => socketRef.current?.emit("update", nextState));
597+
queueMicrotask(() => socketRef.current?.emit("update", { ...nextState, boardRoom: ROOM }));
592598
}
593599
});
594600

@@ -607,7 +613,7 @@ export function useGameState() {
607613
return;
608614
}
609615

610-
socketRef.current?.emit("update", state);
616+
socketRef.current?.emit("update", { ...state, boardRoom: ROOM });
611617
}, [state]);
612618

613619
useEffect(() => {

artifacts/game-client/src/apps/adepts-game/hooks/useGameState.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export type GameState = {
2929
/** Подсветка ячейки доски под курсором ведущего / игрока с ходом */
3030
quizBoardHoverCell?: QuizBoardHoverCell;
3131
dataVersion?: number;
32+
/** Идентификатор доски — проверяется в sync-обработчике для отклонения данных чужой доски */
33+
boardRoom?: string;
3234
};
3335

3436
const DEFAULT_STATE: GameState = {
@@ -226,21 +228,31 @@ export function useGameState() {
226228
hadRoster &&
227229
typeof localStorage !== "undefined" &&
228230
localStorage.getItem("player_role") === "host";
231+
const isSameBoard = incoming.boardRoom === ROOM;
229232
const nextState = restoreLegacyWheelCards({
230233
...incoming,
234+
themes: isSameBoard ? (incoming.themes ?? DEFAULT_STATE.themes) : DEFAULT_STATE.themes,
231235
players: merged,
232236
activeQuizCard: incoming.activeQuizCard ?? null,
233237
currentTurnSeat: hostResetTurn
234238
? 0
235239
: Number.isInteger(incoming.currentTurnSeat)
236240
? ((Number(incoming.currentTurnSeat) % 5) + 5) % 5
237241
: 0,
242+
questions: DEFAULT_STATE.questions.map((themeQs, tIdx) =>
243+
themeQs.map((defaultQ, qIdx) => ({
244+
...defaultQ,
245+
used: isSameBoard
246+
? (incoming.questions?.[tIdx]?.[qIdx]?.used ?? defaultQ.used)
247+
: defaultQ.used,
248+
}))
249+
),
238250
});
239251
skipEmitRef.current = true;
240252
setState(nextState);
241253
if (hadRoster) {
242254
skipEmitRef.current = false;
243-
queueMicrotask(() => socketRef.current?.emit("update", nextState));
255+
queueMicrotask(() => socketRef.current?.emit("update", { ...nextState, boardRoom: ROOM }));
244256
}
245257
});
246258

@@ -260,7 +272,7 @@ export function useGameState() {
260272
return;
261273
}
262274

263-
socketRef.current?.emit("update", state);
275+
socketRef.current?.emit("update", { ...state, boardRoom: ROOM });
264276
}, [state]);
265277

266278
// Cross-tab sync via StorageEvent (same machine, different tabs)

0 commit comments

Comments
 (0)