Skip to content

Commit 1d5faf9

Browse files
committed
исправлен оверлей победителя
1 parent a4d3788 commit 1d5faf9

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,13 @@ export function useGameState(boardId: AdeptsBoardId) {
688688
? { ...nextState, activeQuizCard: null, quizBoardHoverCell: null }
689689
: nextState;
690690

691-
if (boardId === 4) {
691+
if (boardId === 4 && !stateToApply.superTttWinner) {
692692
const row0 = stateToApply.questions[0];
693693
const fourPrizeCardsDone =
694694
Array.isArray(row0) &&
695695
row0.length >= 4 &&
696696
row0.slice(0, 4).every((q) => q.used === true);
697+
/** Не трогаем фазу победы: иначе при малом рассинхроне сетки и `questions` оверлей победителя исчезал. */
697698
if (!fourPrizeCardsDone && stateToApply.superTtt) {
698699
stateToApply = { ...stateToApply, superTtt: null, superTttWinner: null };
699700
}

artifacts/game-client/src/apps/adepts-game/pages/Home.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,21 @@ export default function Home({ boardId }: { boardId: AdeptsBoardId }) {
118118
};
119119
}, [boardId, Boolean(state.superTtt), state.superTttWinner?.atMs, state.superTttWinner?.nick]);
120120

121+
/** 5 с показа с момента появления победителя у клиента (не только по server `atMs` — иначе поздний sync = 0 с на экране). */
122+
const [superWinnerUntilMs, setSuperWinnerUntilMs] = useState<number | null>(null);
121123
const [, setWinnerTick] = useState(0);
122124
useEffect(() => {
123125
const w = state.superTttWinner;
124-
if (!w || typeof w.atMs !== "number") return;
125-
const left = Math.max(0, w.atMs + 5000 - Date.now());
126+
if (!w) {
127+
setSuperWinnerUntilMs(null);
128+
return;
129+
}
130+
setSuperWinnerUntilMs(Date.now() + 5000);
131+
}, [state.superTttWinner?.atMs, state.superTttWinner?.nick]);
132+
133+
useEffect(() => {
134+
if (superWinnerUntilMs == null) return;
135+
const left = Math.max(0, superWinnerUntilMs - Date.now());
126136
if (left <= 0) return;
127137
const t = window.setInterval(() => setWinnerTick((n) => n + 1), 200);
128138
const done = window.setTimeout(() => {
@@ -133,12 +143,13 @@ export default function Home({ boardId }: { boardId: AdeptsBoardId }) {
133143
clearInterval(t);
134144
clearTimeout(done);
135145
};
136-
}, [state.superTttWinner?.atMs, state.superTttWinner?.nick]);
146+
}, [superWinnerUntilMs]);
137147

138148
const superWinnerOverlay =
139149
boardId === 4 &&
140150
state.superTttWinner &&
141-
Date.now() - state.superTttWinner.atMs < 5000 ? (
151+
superWinnerUntilMs != null &&
152+
Date.now() < superWinnerUntilMs ? (
142153
<div
143154
className="pointer-events-none fixed inset-0 z-[190] flex items-center justify-center bg-black/50 p-4"
144155
aria-live="polite"

0 commit comments

Comments
 (0)