diff --git a/apps/server/src/rooms/room.test.ts b/apps/server/src/rooms/room.test.ts
index 9fef98a..c7f8efb 100644
--- a/apps/server/src/rooms/room.test.ts
+++ b/apps/server/src/rooms/room.test.ts
@@ -107,6 +107,7 @@ describe('Room timers', () => {
room.settled('B', room.seq);
room.clearTimer();
// A plays; B (to move) has not reported this new state yet
+ clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, (room.def.legalActions!(room.game!.state, 'A') as unknown[])[0]);
room.clearTimer();
const base = clock.now() + 10_000;
@@ -127,6 +128,7 @@ describe('Room timers', () => {
room.start('A');
room.settled('A', room.seq);
room.settled('B', room.seq);
+ clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, (room.def.legalActions!(room.game!.state, 'A') as unknown[])[0]);
room.clearTimer();
const base = clock.now() + 10_000;
@@ -399,6 +401,7 @@ describe('Room clocks after the animation (shared steps)', () => {
room.start('A');
room.settled('A', room.seq);
room.settled('B', room.seq);
+ clock.advance(100); // a moment later (a new step has a new clock)
room.act('A', 1, { type: 'go' }); // → only B answers now, A is the timed stand-in
room.clearTimer();
const base = clock.now() + 10_000;
@@ -426,4 +429,44 @@ describe('Room clocks after the animation (shared steps)', () => {
room.clearTimer();
expect((room.game!.state as any).chats).toBe(1);
});
+ // A re-vote: A and B both vote under one shared clock that the room times through A.
+ const revote: AnyGameDefinition = {
+ ...guess,
+ id: 'revote',
+ actionSchema: z.object({ type: z.enum(['go', 'vote', 'chat']) }),
+ setup: ({ players, now }) => ({ players, step: 'start', deadlineAt: now + 10_000, voted: [] as string[], chats: 0 }),
+ apply: (s: any, p, a: any, { now }) => ({
+ state: a.type === 'go' ? { ...s, step: 'vote', deadlineAt: now + 10_000 } : a.type === 'vote' ? { ...s, voted: [...s.voted, p] } : { ...s, chats: s.chats + 1 },
+ events: [],
+ }),
+ activePlayers: (s: any) => (s.step === 'vote' ? s.players.filter((p: string) => !s.voted.includes(p)) : s.players),
+ timeoutPlayers: (s: any) => (s.step === 'vote' ? [s.players[0]] : s.players),
+ };
+
+ test('a shared vote: the clock waits for the slowest voter\'s screen, and someone voting keeps that time', () => {
+ const { room, clock, conn } = harness({ revote });
+ const a = conn('A');
+ const b = conn('B');
+ room.join(a, 'player');
+ room.join(b, 'player');
+ room.start('A');
+ room.settled('A', room.seq);
+ room.settled('B', room.seq);
+ clock.advance(100); // a moment later (a new step has a new clock)
+ room.act('A', 1, { type: 'go' });
+ room.clearTimer();
+ const base = clock.now() + 10_000;
+ clock.advance(220);
+ room.settled('A', room.seq); // A (also the timed stand-in) is done in 0.22 s …
+ clock.advance(5_780);
+ room.settled('B', room.seq); // … B only after 6 s: the shared clock gives everybody those 6 s
+ room.clearTimer();
+ expect(room.effectiveDeadline()).toBe(base + 6_000);
+ expect(a.msgs.at(-1)).toEqual({ t: 'deadline', deadline: base + 6_000 });
+ // A votes: only B is left to answer, same clock: still 6 s more.
+ room.act('A', 2, { type: 'vote' });
+ room.clearTimer();
+ expect(room.effectiveDeadline()).toBe(base + 6_000);
+ expect((b.msgs.filter((m) => m.t === 'state').at(-1) as { deadline: number }).deadline).toBe(base + 6_000);
+ });
});
diff --git a/apps/server/src/rooms/room.ts b/apps/server/src/rooms/room.ts
index 8df1313..3a08553 100644
--- a/apps/server/src/rooms/room.ts
+++ b/apps/server/src/rooms/room.ts
@@ -1168,22 +1168,22 @@ export class Room {
return provisional ? Math.min(cap, Math.max(0, this.now() - r.at)) : cap;
}
- /** What a step is: its clock and who acts / is timed in it. */
+ /**
+ * What a step is: its clock. Players answering one by one inside a shared clock (votes) or a chat line keep the
+ * time already given; a new clock (next turn, next phase) is a new step.
+ */
private revealKey(): string {
- const g = this.game!;
- const def = this.def;
- return JSON.stringify([def.deadline?.(g.state) ?? null, def.activePlayers(g.state), def.timeoutPlayers?.(g.state) ?? null]);
+ return JSON.stringify(this.def.deadline?.(this.game!.state) ?? null);
}
/**
- * Extra time on `u`'s clock. A player who has to answer gets their own screen's animation time; a player timed for
- * a step others answer (the room times one stand-in for a shared clock) gets the slowest answerer's, so the
- * people who really answer are never cut short by someone else's faster screen.
+ * Extra time on `u`'s clock: the slowest screen among the players who still have to answer (and `u`). A shared
+ * clock (a vote, a stand-in the room times for everybody) thus never cuts short someone whose screen is still
+ * animating because another screen was faster.
*/
private clockExtra(u: string, provisional = false): number {
const answer = this.def.activePlayers(this.game!.state);
- if (answer.includes(u)) return this.revealExtra(u, provisional);
- return Math.max(0, ...answer.map((p) => this.revealExtra(p, provisional)));
+ return Math.max(this.revealExtra(u, provisional), ...answer.map((p) => this.revealExtra(p, provisional)));
}
/** A player's screen finished animating the state `seq` (or a later one): their clock starts now. */
diff --git a/apps/web/src/games/baduk/index.tsx b/apps/web/src/games/baduk/index.tsx
index 7b4168a..d570343 100644
--- a/apps/web/src/games/baduk/index.tsx
+++ b/apps/web/src/games/baduk/index.tsx
@@ -506,7 +506,7 @@ function ScoreTable({ score, heading }: { score: ScoreBreakdown; heading?: boole
);
}
-function ScoringPanel({ view: v, act, pending }: { view: BadukView; act: (a: unknown) => void; pending: boolean }) {
+function ScoringPanel({ view: v, act, pending, deadline }: { view: BadukView; act: (a: unknown) => void; pending: boolean; deadline: number | null }) {
const [confirmResume, setConfirmResume] = useState(false);
const sc = v.scoring!;
const p = sc.preview;
@@ -516,7 +516,7 @@ function ScoringPanel({ view: v, act, pending }: { view: BadukView; act: (a: unk
사석 확인
-
+
대국이 멈췄어요. 판 위의 죽은 돌을 눌러 ✕ 표시를 맞춘 뒤 두 사람 모두 동의하면 계가가 끝나요. 처음 표시는 컴퓨터의 추정이라 틀릴 수 있어요.
@@ -585,7 +585,7 @@ function BadukSide({ view: v, me, players, act, pending, deadline }: BoardProps<
{/* The counted score and the result show once the 계가 banner / territory marks / winner banner have played. */}
{v.phase === 'scoring' && (
-
+
)}
{v.phase === 'finished' && v.result?.score && (
diff --git a/apps/web/src/games/bang/index.tsx b/apps/web/src/games/bang/index.tsx
index 341cd5e..0ea4115 100644
--- a/apps/web/src/games/bang/index.tsx
+++ b/apps/web/src/games/bang/index.tsx
@@ -374,6 +374,7 @@ function Seat({
mark,
onPick,
style,
+ shift,
}: {
p: PlayerView;
v: BangView;
@@ -382,6 +383,8 @@ function Seat({
mark: TargetMark | null;
onPick: (id: string) => void;
style?: CSSProperties;
+ /** How much later than its own the room times this table (see BangBoard). */
+ shift: number;
}) {
const u = userOf(players, p.id);
const r = v.reactions.find((x) => x.who === p.id);
@@ -389,9 +392,9 @@ function Seat({
const alive = useAfterMotionValue(p.alive);
const role = shownRole(p, v, me);
const timer = r ? (
-
+
) : p.isTurn && !v.reactions.length && !v.winner ? (
-
+
) : null;
const cls = `bg-seat${p.isTurn ? ` turn${v.winner ? '' : ' anim-glow'}` : ''}${r ? ' react' : ''}${p.id === me ? ' me' : ''}${!alive ? ' dead' : ''}`;
const body = (
@@ -820,7 +823,7 @@ function DrawPanel({ prompt, act, pending, players }: { prompt: Extract void; pending: boolean; players: Record }) {
+function PromptModal({ v, act, pending, players, shift }: { v: BangView; act: (a: unknown) => void; pending: boolean; players: Record; shift: number }) {
const my = v.my!;
const p = my.prompt;
const [picked, setPicked] = useState([]);
@@ -836,7 +839,7 @@ function PromptModal({ v, act, pending, players }: { v: BangView; act: (a: unkno
}, [p?.kind]); // eslint-disable-line react-hooks/exhaustive-deps
if (!p || p.kind === 'discard' || p.kind === 'draw') return null;
const r = v.reactions.find((x) => x.who === v.me);
- const timer = r ? : null;
+ const timer = r ? : null;
const n = (id: string) => `${nick(players, id)}님`;
const hand = my.hand;
const sidBox = my.canSidHeal && (
@@ -1056,8 +1059,13 @@ function logText(e: LogEntry, players: Record): string {
// ---------------------------------------------------------------- board
-function BangBoard({ view: v, me, players, act, pending }: BoardProps) {
+function BangBoard({ view: v, me, players, act, pending, deadline }: BoardProps) {
const [sel, setSel] = useState(null);
+ // The room's deadline is the game's (the earliest reaction, else the turn) plus the time the screens took to finish
+ // animating: every clock on the table moves by that much.
+ const ds = v.reactions.flatMap((r) => (r.deadline === null ? [] : [r.deadline]));
+ const own = v.winner ? null : ds.length ? Math.min(...ds) : v.reactions.length ? null : v.turnDeadline;
+ const shift = own !== null && deadline !== null ? Math.max(0, deadline - own) : 0;
const [announce, setAnnounce] = useState('');
const mine = isMyTurn(v, me);
const prevMine = useRef(false);
@@ -1110,6 +1118,7 @@ function BangBoard({ view: v, me, players, act, pending }: BoardProps)
me={me}
mark={markOf(p.id)}
onPick={pick}
+ shift={shift}
style={{ '--x': `${50 + 41 * Math.cos(ang)}%`, '--y': `${50 + 37 * Math.sin(ang)}%`, order: rel } as CSSProperties}
/>
);
@@ -1120,7 +1129,7 @@ function BangBoard({ view: v, me, players, act, pending }: BoardProps)
{/* A reaction / choice window opens once the card that caused it has landed (it mounts then, so focus works). */}
{v.my && (
-
+
)}
diff --git a/apps/web/src/games/liar/index.tsx b/apps/web/src/games/liar/index.tsx
index e9abc4d..45afb6b 100644
--- a/apps/web/src/games/liar/index.tsx
+++ b/apps/web/src/games/liar/index.tsx
@@ -834,7 +834,7 @@ function useLiarFx(v: LiarView, me: string | null, players: Record) {
+function LiarBoard({ view: v, me, players, act, pending, deadline }: BoardProps) {
// The room chat is closed while playing, so the 토론 chat lines play the chat sound.
useChatSound(v.chat.at(-1)?.n);
const ph = v.phase;
@@ -881,7 +881,8 @@ function LiarBoard({ view: v, me, players, act, pending }: BoardProps)
{sub}
-
+ {/* The room's deadline is the phase clock plus the time the screens took to finish animating (it only moves later). */}
+
{my && }
diff --git a/apps/web/src/games/mafia/index.tsx b/apps/web/src/games/mafia/index.tsx
index b67a958..c6414fb 100644
--- a/apps/web/src/games/mafia/index.tsx
+++ b/apps/web/src/games/mafia/index.tsx
@@ -883,7 +883,7 @@ function useShownEvents(v: MafiaView): PublicEvent[] {
return useMemo(() => (v.events.at(-1)?.n ?? 0) <= shownN ? v.events : v.events.filter((e) => e.n <= shownN), [v.events, shownN]);
}
-function MafiaBoard({ view: v, me, players, act, pending }: BoardProps) {
+function MafiaBoard({ view: v, me, players, act, pending, deadline }: BoardProps) {
// The room chat is closed while playing, so this game's own chat lines play the chat sound.
useChatSound(v.chat.at(-1)?.key);
const ph = v.phase;
@@ -956,7 +956,8 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps
{sub}
-
+ {/* The room's deadline is the phase clock plus the time the screens took to finish animating (it only moves later). */}
+
{my && }
diff --git a/apps/web/src/games/mahjong/index.tsx b/apps/web/src/games/mahjong/index.tsx
index 73e5760..c92bb77 100644
--- a/apps/web/src/games/mahjong/index.tsx
+++ b/apps/web/src/games/mahjong/index.tsx
@@ -738,12 +738,12 @@ function MyArea({
)}
{riichiMode && 밝은 패를 버리면 리치예요. 리치하면 1,000점을 공탁에 내고, 그다음부터는 쯔모한 패만 버려요.
}
{!myTurn && v.phase === 'playing' && v.turn !== null && v.stage !== 'claim' && {nick(players, v.seats[v.turn]!.id)}님 차례예요.
}
-
+
);
}
-function ClaimPanel({ v, my, act, pending, players }: { v: MahjongView; my: MyView; act: (a: unknown) => void; pending: boolean; players: Record }) {
+function ClaimPanel({ v, my, act, pending, players, deadline }: { v: MahjongView; my: MyView; act: (a: unknown) => void; pending: boolean; players: Record; deadline: number | null }) {
const c = my.claim;
const beginner = my.prefs.beginner && v.options.beginnerMode;
const [chiPick, setChiPick] = useState(false);
@@ -780,7 +780,7 @@ function ClaimPanel({ v, my, act, pending, players }: { v: MahjongView; my: MyVi
{from}님이 {what} {tileShort(c.tile)}
-
+
{c.ron && (
diff --git a/e2e/motion.e2e.ts b/e2e/motion.e2e.ts
index afe9a23..eb8a9f4 100644
--- a/e2e/motion.e2e.ts
+++ b/e2e/motion.e2e.ts
@@ -39,7 +39,12 @@ let cs = 1_000_000;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type AnyRoom = any;
-async function practice(gameId: string, nick: string, options?: (o: Record) => Record): Promise<{ p: Page; room: AnyRoom; me: string; bot: string }> {
+async function practice(
+ gameId: string,
+ nick: string,
+ options?: (o: Record) => Record,
+ bots = 1,
+): Promise<{ p: Page; room: AnyRoom; me: string; bot: string }> {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 860 }, locale: 'ko-KR' });
await ctx.addInitScript((g) => localStorage.setItem(`bg:qs:${g}`, '1'), gameId);
const p = await ctx.newPage();
@@ -55,6 +60,10 @@ async function practice(gameId: string, nick: string, options?: (o: Record !u.startsWith('bot:'))!;
@@ -228,6 +237,34 @@ try {
await p.context().close();
setSpeed(1);
});
+
+ await step('라이어 게임: 연출이 끝난 만큼 늘어난 마감이 화면 시계에도 그대로', async () => {
+ const { p, room, me } = await practice('liar', '호랑이', undefined, 2);
+ // My screen is made to look 6 s slow to finish each step: the room gives 6 s more, and my clock must show it.
+ const report = room.settled.bind(room);
+ room.settled = (u: string, seq: number) => {
+ if (u === me && room.reveal && !room.reveal.done.has(u)) room.reveal.at -= 6_000;
+ return report(u, seq);
+ };
+ let checked = 0;
+ for (let i = 0; i < 400 && checked < 3; i++) {
+ await Bun.sleep(250);
+ const ph = room.game?.state?.phase;
+ const done = room.reveal?.done.get(me);
+ if (!ph || ph.endsAt == null || done === undefined || Date.now() - done < 1_000) continue;
+ const label = (await p.locator('.lg-clock[role="timer"]').first().getAttribute('aria-label').catch(() => null)) ?? '';
+ const shown = Number(label.match(/(\d+)초/)?.[1] ?? NaN);
+ const left = (room.publicDeadline() - Date.now()) / 1000;
+ const plain = (ph.endsAt - Date.now()) / 1000;
+ if (room.reveal?.done.get(me) !== done || room.game.state.phase !== ph) continue; // the step moved on meanwhile
+ if (left - plain < 5) throw new Error(`room deadline not moved: ${left.toFixed(1)}s vs phase ${plain.toFixed(1)}s`);
+ if (!(Math.abs(shown - left) <= 1.5)) throw new Error(`clock says ${shown}s, the room has ${left.toFixed(1)}s (phase alone ${plain.toFixed(1)}s)`);
+ checked++;
+ }
+ if (checked < 3) throw new Error(`only ${checked} clock checks happened`);
+ console.log(' liar: the clock follows the moved deadline (3 checks)');
+ await p.context().close();
+ });
} finally {
await browser.close();
app.stop?.();