도둑잡기 화면 개선: 뽑기 방향 제목을 "[아바타] 뽑는 사람님 → [아바타] 뽑히는 사람의 카드 N장"으로 바로잡고(내가/내 카드, 움직이는 화살표), 뒷면 카드와 내 손패를 손에 쥔 부채처럼 겹쳐 호로 펼침(띠 28px 미만이면 여러 줄), 뽑은 카드가 부채에서 들려 날아가기, 섞기 리플·내 손패 자리 바꾸기, 펠트 테이블·지난 뽑기·버린 짝 정리, 자리 카드 뒷면 부채

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 22:27:53 +09:00
parent 9564e4604c
commit 265a0c2ebf
4 changed files with 463 additions and 105 deletions

View File

@@ -0,0 +1,47 @@
import { describe, expect, test } from 'bun:test';
import { fanCard, fanLayout } from './fan';
const PC = { cw: 70, prefer: 54, wrapCw: 52 };
const PHONE = { cw: 50, prefer: 39, wrapCw: 44 };
describe('old-maid fan layout', () => {
test('a few cards on a PC table: held fan with the preferred strip, fits the width', () => {
const l = fanLayout(8, 900, PC);
expect(l.wrap).toBe(false);
expect(l.step).toBe(54);
expect(7 * l.step + l.cw + 2 * l.pad).toBeLessThanOrEqual(900);
});
test('phone: overlap grows with the count but every strip stays ≥ 28 px, then it wraps', () => {
for (let n = 2; n <= 27; n++) {
for (const w of [270, 330, 360]) {
const l = fanLayout(n, w, PHONE);
if (l.wrap) continue;
expect(l.step).toBeGreaterThanOrEqual(28);
expect((n - 1) * l.step + l.cw + 2 * l.pad).toBeLessThanOrEqual(w);
}
}
expect(fanLayout(8, 330, PHONE).wrap).toBe(false);
const many = fanLayout(20, 330, PHONE);
expect(many.wrap).toBe(true);
expect(many.cw).toBe(44);
});
test('not measured yet → wrapped rows; one card → no tilt', () => {
expect(fanLayout(5, 0, PC).wrap).toBe(true);
const one = fanLayout(1, 300, PC);
expect(one.wrap).toBe(false);
expect(fanCard(0, 1, one)).toEqual({ r: 0, y: 0, t: 0 });
});
test('arc: symmetric tilt, middle card highest', () => {
const l = fanLayout(5, 900, PC);
const cards = [0, 1, 2, 3, 4].map((i) => fanCard(i, 5, l));
expect(cards[0]!.r).toBe(-l.spread);
expect(cards[4]!.r).toBe(l.spread);
expect(cards[2]!.r).toBe(0);
expect(cards[2]!.y).toBe(0);
expect(cards[0]!.y).toBe(l.arc);
expect(cards[1]!.y).toBeLessThan(cards[0]!.y);
});
});

View File

@@ -0,0 +1,53 @@
/**
* 도둑잡기 card rows (docs/games/old-maid.md §9): a held fan (overlapping cards on a gentle arc) when every card still
* shows a strip of at least `minStrip` px (the part you can tap), otherwise plain wrapped rows.
*/
export interface FanLayout {
/** Card width (px). */
cw: number;
/** Distance between the left edges of neighbouring cards = the visible (tappable) strip of every card but the last. */
step: number;
/** Too many cards for one row: plain wrapped rows, no tilt. */
wrap: boolean;
/** Tilt of the outermost cards (deg); the ones in between are spread evenly. */
spread: number;
/** How much lower the outermost cards sit than the middle one (px). */
arc: number;
/** Room kept free on both sides for the tilted outer cards (px). */
pad: number;
}
export interface FanOpts {
/** Card width in the fan. */
cw: number;
/** Preferred strip when there is room (less overlap looks loose, more looks like a real hand). */
prefer: number;
/** Smallest strip still allowed (default 30: ≥ 28 px stays tappable even with the small tilt between neighbours). */
minStrip?: number;
/** Card width when it falls back to wrapped rows. */
wrapCw?: number;
}
const RAD = Math.PI / 180;
/** Layout for `n` cards in a row `width` px wide. Unknown width (not measured yet) → wrapped rows. */
export function fanLayout(n: number, width: number, o: FanOpts): FanLayout {
const minStrip = o.minStrip ?? 30;
const wrapCw = o.wrapCw ?? o.cw;
const wrap: FanLayout = { cw: wrapCw, step: wrapCw, wrap: true, spread: 0, arc: 0, pad: 0 };
if (width <= 0 || n <= 0) return wrap;
if (n === 1) return o.cw <= width ? { cw: o.cw, step: o.cw, wrap: false, spread: 0, arc: 0, pad: 0 } : wrap;
const spread = Math.min(12, 2 + n * 0.8);
// The outer cards turn around a point a little below their bottom edge, so their top corners stick out sideways.
const pad = Math.ceil(o.cw * 1.4 * 1.15 * Math.sin(spread * RAD)) + 2;
const step = Math.floor(Math.min(o.prefer, (width - 2 * pad - o.cw) / (n - 1)));
if (step < minStrip) return wrap;
return { cw: o.cw, step, wrap: false, spread, arc: Math.round(spread * 0.7), pad };
}
/** Tilt / drop of card `i` of `n` (`t` runs from -1 at the left end to 1 at the right end). */
export function fanCard(i: number, n: number, l: FanLayout): { r: number; y: number; t: number } {
if (l.wrap || n < 2) return { r: 0, y: 0, t: 0 };
const t = (2 * i) / (n - 1) - 1;
return { r: Math.round(t * l.spread * 100) / 100, y: Math.round(t * t * l.arc * 10) / 10, t };
}

View File

@@ -1,5 +1,5 @@
/** 도둑잡기 화면 (docs/games/old-maid.md §9). Cards are the shared trump card SVGs. */
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
import type { LogEntry, OldMaidOptions, OldMaidView } from '@bg/games/old-maid';
import type { PublicUser } from '@bg/shared/lite';
import { Avatar } from '../../components/ui';
@@ -8,7 +8,8 @@ import { PlayingCard, cardAria } from '../../components/cards/PlayingCard';
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
import { toast } from '../../store/toast';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { bump, cssEsc, flyFrom, flyGhost, fxEl, seatEl, useBanner, useChange, useNewEntries } from '../card-fx';
import { bump, cssEsc, flyFrom, flyGhost, fxEl, reducedMotion, seatEl, useBanner, useChange, useNewEntries } from '../card-fx';
import { fanCard, fanLayout, type FanLayout } from './fan';
import { helpNow } from './help';
import { quickStart } from './quick';
@@ -42,12 +43,66 @@ const omSfx = {
/** Where I clicked the card I drew (its button is gone once the view arrives), so the new card flies in from there. */
let myDrawRect: DOMRect | null = null;
/** The fan as it was last painted ([x, y, w, h] of every card, relative to the table), so someone else's draw lifts that card. */
let fanSnap: { target: string; rects: (readonly [number, number, number, number])[] } | null = null;
const handCardEl = (c: string) => document.querySelector(`.om-hand [data-card="${cssEsc(c)}"]`);
const pairKey = (p: [string, string]) => `${p[0]}-${p[1]}`;
const LIFT_MS = 640;
/** Where card `index` of `from`'s fan was last painted (see `fanSnap`), in today's page coordinates. */
function fanCardRect(from: string, index: number): DOMRect | null {
const r = fanSnap?.target === from ? fanSnap.rects[index] : undefined;
const t = fxEl('om-table')?.getBoundingClientRect();
if (!r || !t || typeof DOMRect !== 'function') return null;
return new DOMRect(t.left + r[0], t.top + r[1], r[2], r[3]);
}
/** A face-down copy of the drawn card rises out of the fan, then flies to `to`. False when nothing was shown (reduced motion …). */
function liftFly(from: DOMRect, to: Element | null | undefined, delay: number): boolean {
const b = to?.getBoundingClientRect();
if (!b || (b.width === 0 && b.height === 0) || reducedMotion() || typeof document === 'undefined') return false;
const g = document.createElement('div');
if (typeof g.animate !== 'function') return false;
g.className = 'om-ghost';
g.setAttribute('aria-hidden', 'true');
Object.assign(g.style, { left: `${from.left}px`, top: `${from.top}px`, width: `${from.width}px`, height: `${from.height}px` });
document.body.appendChild(g);
const dx = b.left + b.width / 2 - (from.left + from.width / 2);
const dy = b.top + b.height / 2 - (from.top + from.height / 2);
// Onto a card in my hand: shrink to its size. Onto a seat: a small card.
const s = b.width <= 120 ? Math.max(0.4, Math.min(1.2, b.width / from.width)) : 0.6;
const anim = g.animate(
[
{ transform: 'translate(0px, 0px) scale(1) rotate(0deg)', opacity: 1 },
{ transform: 'translate(0px, -28px) scale(1.08) rotate(-4deg)', opacity: 1, offset: 0.3 },
{ transform: `translate(${dx}px, ${dy}px) scale(${s}) rotate(6deg)`, opacity: 1, offset: 0.88 },
{ transform: `translate(${dx}px, ${dy}px) scale(${s}) rotate(0deg)`, opacity: 0 },
],
{ duration: LIFT_MS, delay, easing: 'cubic-bezier(.35,.6,.3,1)', fill: 'both' },
);
const done = () => g.remove();
anim.onfinish = done;
anim.oncancel = done;
setTimeout(done, LIFT_MS + delay + 1500);
return true;
}
/** My new card stays hidden while its face-down copy flies in, then pops up face-up. */
function reveal(el: Element, delay: number): void {
const h = el as HTMLElement;
if (typeof h.animate !== 'function') return;
h.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 120, delay, fill: 'backwards' });
h.animate([{ transform: 'scale(.8)' }, { transform: 'scale(1.1)', offset: 0.6 }, { transform: 'scale(1)' }], { duration: 280, delay, easing: 'ease-out', composite: 'add' });
}
const nick = (players: Record<string, PublicUser>, id: string) => players[id]?.nickname ?? '알 수 없음';
const userOf = (players: Record<string, PublicUser>, id: string): PublicUser => players[id] ?? { id, nickname: '알 수 없음', avatar: null, kind: 'guest' };
const who = (players: Record<string, PublicUser>, id: string, me: string | null) => (id === me ? '나' : `${nick(players, id)}님`);
/** "내가" / "친구님이": who drew. */
const drawerSubj = (players: Record<string, PublicUser>, id: string, me: string | null) => (id === me ? '내가' : `${nick(players, id)}님이`);
/** "내" / "친구님의": whose cards. */
const whose = (players: Record<string, PublicUser>, id: string, me: string | null) => (id === me ? '내' : `${nick(players, id)}님의`);
/** "♥7", "조커". */
function cardName(c: string): string {
@@ -59,7 +114,7 @@ function cardName(c: string): string {
function logText(e: LogEntry, players: Record<string, PublicUser>, me: string | null): string {
switch (e.t) {
case 'draw': {
const base = `${who(players, e.drawer, me)}${e.drawer === me ? '는' : '이'} ${who(players, e.from, me)}의 ${e.index + 1}번째 카드를 뽑았어요`;
const base = `${drawerSubj(players, e.drawer, me)} ${whose(players, e.from, me)} ${e.index + 1}번째 카드를 뽑았어요`;
const pair = e.pair ? ` → ${cardName(e.pair[0])}·${cardName(e.pair[1])} 짝을 버렸어요` : '';
return `${base}${pair}${e.auto ? ' (시간 초과)' : ''}`;
}
@@ -76,7 +131,7 @@ function logText(e: LogEntry, players: Record<string, PublicUser>, me: string |
const CSS = `
.om-board { width: 100%; max-width: 1040px; max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px; }
.om-seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.om-seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; padding-top: 6px; }
.om-seat { position: relative; background: var(--surface); border-radius: var(--radius-lg); padding: 8px 10px; box-shadow: var(--shadow); border: 3px solid transparent; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.om-seat.turn { border-color: var(--focus); }
.om-seat.target { border-color: var(--primary); border-style: dashed; }
@@ -86,73 +141,134 @@ const CSS = `
.om-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.om-badges { display: flex; gap: 4px; flex-wrap: wrap; min-height: 22px; }
.om-badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-weight: 800; font-size: .78rem; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.om-badge.turn { background: var(--focus); color: #1c1e21; }
.om-badge.turn { background: var(--focus); color: #1c1e21; animation: om-beat 1.6s ease-in-out infinite; }
.om-badge.target { background: var(--primary-soft); color: var(--text); }
.om-badge.win { background: var(--success-soft); color: var(--success); }
.om-badge.lose { background: var(--danger-soft); color: var(--danger); }
.om-meta { font-size: .85rem; color: var(--text-sub); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.om-mini { display: inline-flex; align-items: center; }
.om-mini i { width: 12px; height: 17px; border-radius: 3px; background: #1e3a8a; border: 1.5px solid #fff; box-shadow: 0 0 0 1px #1e3a8a; margin-left: -6px; display: inline-block; }
.om-mini i:first-child { margin-left: 0; }
.om-meta strong { color: var(--text); font-variant-numeric: tabular-nums; }
.om-mini { position: relative; display: inline-block; flex: none; height: 24px; }
.om-mini i { position: absolute; bottom: 1px; width: 13px; height: 19px; border-radius: 3px; background: #1e3a8a; border: 1.5px solid #fff;
box-shadow: 0 0 0 1px #1e3a8a, 0 1px 2px rgba(0,0,0,.35); transform: rotate(var(--r)); transform-origin: 50% 140%; }
.om-mini i::after { content: ''; position: absolute; inset: 3px 2px; border: 1px solid #93c5fd; border-radius: 1px; }
.om-mini.empty { width: 15px; }
.om-mini.empty i { background: none; border-style: dashed; border-color: var(--border); box-shadow: none; }
.om-mini.empty i::after { display: none; }
.om-bubble { position: absolute; right: 8px; top: -12px; background: var(--text); color: var(--surface); border-radius: 12px; padding: 2px 10px; font-weight: 800; font-size: .8rem; box-shadow: var(--shadow); animation: om-pop .25s ease-out; z-index: 2; }
.om-table { background: var(--felt); color: #fff; border-radius: var(--radius-lg); padding: 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; min-height: 200px; }
.om-table .small { color: #fff; opacity: .92; }
.om-title { font-weight: 900; font-size: 1.05rem; text-align: center; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.om-title .arrow { opacity: .85; }
.om-fan { --cw: 60px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 14px 4px 4px; max-width: 760px; }
.om-fan.many { --cw: 50px; gap: 5px; }
.om-fan.shake { animation: om-shake .5s ease-in-out; }
.om-back { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); padding: 0; border: 0; background: none; border-radius: 9px; cursor: default; transition: transform .12s ease; }
.om-table { position: relative; color: #fff; border-radius: 22px; padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; align-items: center; min-height: 200px;
background: radial-gradient(ellipse 75% 60% at 50% 36%, rgba(255,255,255,.15), rgba(255,255,255,0) 70%), var(--felt);
border: 6px solid var(--wood); box-shadow: inset 0 0 0 2px rgba(255,255,255,.07), inset 0 0 48px rgba(0,0,0,.32), var(--shadow); }
.om-table .small { color: #fff; opacity: .92; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.om-title { font-weight: 900; font-size: 1.02rem; display: flex; align-items: center; gap: 6px 8px; flex-wrap: wrap; justify-content: center; text-shadow: 0 1px 2px rgba(0,0,0,.45); }
.om-who { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; background: rgba(0,0,0,.24); border-radius: 999px; padding: 3px 12px 3px 4px; }
.om-who.me { box-shadow: inset 0 0 0 2px rgba(253,224,71,.65); }
.om-who .lbl { display: inline-flex; min-width: 0; white-space: nowrap; }
.om-who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 12em; }
.om-who b { color: #fde047; white-space: nowrap; }
.om-arrow { display: inline-flex; color: #fde047; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); animation: om-nudge 1.1s ease-in-out infinite; }
.om-fan { --cw: 70px; --sw: var(--cw); width: 100%; display: flex; justify-content: center; align-items: flex-start; padding: 26px 0 16px; }
.om-fan.wrap { flex-wrap: wrap; gap: 6px; padding-top: 18px; }
.om-card { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); display: inline-block; }
.om-strip { position: relative; flex: none; width: var(--sw); height: calc(var(--cw) * 1.4); transform: translateY(calc(var(--y, 0px) + var(--lift, 0px))) rotate(var(--r, 0deg));
transform-origin: calc(var(--cw) / 2) 115%; transition: transform .16s ease; }
.om-strip.last, .wrap .om-strip { width: var(--cw); }
.om-strip > .om-face { position: absolute; left: 0; top: 0; width: var(--cw); height: 100%; border-radius: 9px; filter: drop-shadow(-2px 2px 3px rgba(0,0,0,.3)); }
.om-back { padding: 0; border: 0; background: none; border-radius: 9px; cursor: default; color: inherit; }
button.om-back { cursor: pointer; }
button.om-back:hover:not(:disabled) { transform: translateY(-5px); }
.om-back[aria-pressed='true'] { transform: translateY(-12px); box-shadow: 0 0 0 4px #fde047; z-index: 2; }
.om-back:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; z-index: 3; }
.om-back:disabled { cursor: default; }
.om-back .om-no { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; font-size: .7rem; font-weight: 800; border-radius: 6px; padding: 0 4px; pointer-events: none; }
button.om-back:focus-visible { outline: none; --lift: -10px; }
button.om-back:focus-visible > .om-face { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) {
button.om-back:hover:not(:disabled) { --lift: -12px; }
button.om-back:hover:not(:disabled) > .om-face { filter: drop-shadow(0 0 7px rgba(253,224,71,.85)); }
.om-hand .om-card.om-strip:hover { --lift: -12px; }
}
button.om-back[aria-pressed='true'], button.om-back[aria-pressed='true']:hover:not(:disabled) { --lift: -22px; }
button.om-back[aria-pressed='true'] > .om-face { box-shadow: 0 0 0 3px #fde047, 0 0 18px 4px rgba(253,224,71,.75); }
.om-back .om-no { position: absolute; left: 50%; bottom: 5px; transform: translateX(-50%); background: rgba(0,0,0,.6); color: #fff; font-size: .72rem; font-weight: 800; border-radius: 6px; padding: 0 4px; pointer-events: none; z-index: 1; font-variant-numeric: tabular-nums; }
.om-fan.riffle .om-face { animation: om-riffle .62s cubic-bezier(.3,.7,.3,1) both; animation-delay: calc(var(--i, 0) * 14ms); }
.om-face { display: block; width: 100%; height: 100%; }
.om-face svg, .om-face > span { width: 100% !important; height: 100% !important; display: block; }
.om-last { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.22); border-radius: 12px; padding: 8px 10px; width: 100%; flex-wrap: wrap; justify-content: center; }
.om-last .cards { display: flex; gap: 4px; }
.om-last .cards .om-card { --cw: 40px; }
.om-card { position: relative; flex: none; width: var(--cw); height: calc(var(--cw) * 1.4); display: inline-block; }
.om-pile { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; align-items: center; font-size: .85rem; }
.om-pile .pair { display: inline-flex; gap: 2px; }
.om-pile .om-card { --cw: 28px; }
.om-ghost { position: fixed; z-index: 60; pointer-events: none; box-sizing: border-box; border-radius: 7px; background: #1e3a8a; border: 2px solid #fff;
box-shadow: 0 6px 16px rgba(0,0,0,.4), inset 0 0 0 4px #1e3a8a, inset 0 0 0 6px #93c5fd; will-change: transform, opacity; }
.om-ghost::after { content: ''; position: absolute; left: 50%; top: 50%; width: 34%; height: 24%; background: #3b82f6; transform: translate(-50%, -50%) rotate(45deg); border-radius: 2px; }
.om-last { display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.24); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; padding: 8px 14px; width: 100%; max-width: 620px; justify-content: center; }
.om-last .cards { display: flex; flex: none; padding: 2px 4px; }
.om-last .cards .om-card { --cw: 40px; transform-origin: 50% 100%; filter: drop-shadow(-1px 2px 2px rgba(0,0,0,.3)); }
.om-last .cards .om-card:first-child:not(:last-child) { transform: rotate(-7deg); }
.om-last .cards .om-card + .om-card { margin-left: -12px; transform: rotate(7deg); }
.om-last .txt { line-height: 1.45; min-width: 0; }
.om-pile { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; align-items: center; font-size: .85rem; }
.om-pile .lbl { background: rgba(0,0,0,.26); border-radius: 999px; padding: 2px 12px; font-weight: 800; white-space: nowrap; }
.om-pile .pairs { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; }
.om-pile .pair { display: inline-flex; padding: 2px 3px 0; }
.om-pile .om-card { --cw: 28px; transform-origin: 50% 100%; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.om-pile .pair .om-card:first-child { transform: rotate(-9deg); }
.om-pile .pair .om-card + .om-card { margin-left: -12px; transform: rotate(8deg); }
.om-me { position: relative; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 10px 12px; border: 3px solid var(--primary); display: flex; flex-direction: column; gap: 8px; }
.om-me.turn { border-color: var(--focus); }
.om-me.target { border-style: dashed; }
.om-me .om-bubble { right: auto; left: 16px; top: -14px; }
.om-hand { --cw: 64px; display: flex; flex-wrap: wrap; gap: 6px; }
.om-hand.many { --cw: 52px; }
.om-hand .om-card.joker { box-shadow: 0 0 0 3px var(--danger); border-radius: 9px; }
.om-hand .om-card.fresh { animation: om-pop .45s ease-out; box-shadow: 0 0 0 3px #f59e0b; border-radius: 9px; }
.om-hand { --cw: 72px; --sw: var(--cw); width: 100%; display: flex; justify-content: center; align-items: flex-start; padding: 18px 0 12px; }
.om-hand.wrap { flex-wrap: wrap; gap: 6px; justify-content: flex-start; padding-top: 4px; }
.om-hand .om-card.joker > .om-face { box-shadow: 0 0 0 3px var(--danger); border-radius: 9px; }
.om-hand .om-card.fresh > .om-face { animation: om-pop .45s ease-out; box-shadow: 0 0 0 3px #f59e0b, 0 0 14px 2px rgba(245,158,11,.7); border-radius: 9px; }
.om-mine { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.om-shuffle { min-height: 44px; }
.om-note { font-size: .85rem; color: var(--text-sub); }
.om-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .88rem; }
@keyframes om-pop { 0% { transform: scale(.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes om-shake { 0%, 100% { transform: none; } 20% { transform: translateX(-8px) rotate(-1deg); } 40% { transform: translateX(8px) rotate(1deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes om-nudge { 0%, 100% { transform: translateX(-2px); } 50% { transform: translateX(4px); } }
@keyframes om-beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes om-riffle { 0%, 100% { transform: none; } 35% { transform: translate(var(--sx, 0px), -10px) rotate(calc(var(--r, 0deg) * -1)); } 68% { transform: translate(calc(var(--sx, 0px) * -.35), -3px); } }
@media (max-width: 719px) {
.om-board { max-height: none; overflow: visible; }
.om-seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.om-seat { padding: 6px 8px; }
.om-fan { --cw: 46px; gap: 5px; }
.om-fan.many { --cw: 44px; gap: 4px; }
.om-hand { --cw: 50px; gap: 5px; }
.om-hand.many { --cw: 44px; gap: 4px; }
.om-table { min-height: 0; padding: 10px 8px; }
.om-table { min-height: 0; padding: 10px 8px 12px; border-width: 5px; border-radius: 18px; }
.om-title { font-size: .95rem; }
.om-who .nm { max-width: 7.5em; }
.om-last { padding: 8px 10px; gap: 10px; }
.om-last .cards .om-card { --cw: 36px; }
}
@media (prefers-reduced-motion: reduce) {
.om-fan.shake, .om-bubble, .om-hand .om-card.fresh { animation: none; }
.om-back, .om-back[aria-pressed='true'] { transition: none; }
.om-fan.riffle .om-face, .om-bubble, .om-hand .om-card.fresh > .om-face, .om-arrow, .om-badge.turn { animation: none; }
.om-strip { transition: none; }
}
`;
// ---------------------------------------------------------------- pieces
function Card({ card, className }: { card: string | null; className?: string }) {
/** Width of an element, kept up to date (a callback ref, so it follows the element when it is re-created). */
function useWidth<T extends HTMLElement>(): [(node: T | null) => void, number, { current: T | null }] {
const [w, setW] = useState(0);
const el = useRef<T | null>(null);
const ro = useRef<ResizeObserver | null>(null);
const ref = useCallback((node: T | null) => {
ro.current?.disconnect();
ro.current = null;
el.current = node;
if (!node) return;
setW(node.clientWidth);
if (typeof ResizeObserver === 'function') {
ro.current = new ResizeObserver(() => setW(node.clientWidth));
ro.current.observe(node);
}
}, []);
return [ref, w, el];
}
const rowStyle = (l: FanLayout): CSSProperties => ({ '--cw': `${l.cw}px`, '--sw': `${l.step}px` }) as CSSProperties;
/** Tilt / drop of card `i` of `n` in a fan row (+ extra CSS variables). */
function stripStyle(i: number, n: number, l: FanLayout, extra: Record<string, string | number> = {}): CSSProperties {
const { r, y } = fanCard(i, n, l);
return { '--r': `${r}deg`, '--y': `${y}px`, ...extra } as CSSProperties;
}
function Card({ card, className, style }: { card: string | null; className?: string; style?: CSSProperties }) {
return (
<span className={`om-card${className ? ` ${className}` : ''}`} data-card={card ?? undefined} aria-hidden>
<span className={`om-card${className ? ` ${className}` : ''}`} data-card={card ?? undefined} style={style} aria-hidden>
<span className="om-face">
<PlayingCard card={card} size="lg" style={{ width: '100%', height: '100%', filter: 'none' }} />
</span>
@@ -160,11 +276,21 @@ function Card({ card, className }: { card: string | null; className?: string })
);
}
function MiniBacks({ n }: { n: number }) {
/** A seat's hand: a small fanned stack of card backs, wider and more spread with more cards. */
function MiniFan({ n }: { n: number }) {
if (n <= 0) {
return (
<span className="om-mini empty" aria-hidden>
<i style={{ left: 0, '--r': '0deg' } as CSSProperties} />
</span>
);
}
const k = Math.min(n, 10);
const half = Math.min(12, (k - 1) * 1.6);
return (
<span className="om-mini" aria-hidden>
{Array.from({ length: Math.min(n, 8) }, (_, i) => (
<i key={i} />
<span className="om-mini" style={{ width: 13 + (k - 1) * 4 + 8 }} aria-hidden>
{Array.from({ length: k }, (_, i) => (
<i key={i} style={{ left: 4 + i * 4, '--r': `${k > 1 ? Math.round(((2 * i) / (k - 1) - 1) * half) : 0}deg` } as CSSProperties} />
))}
</span>
);
@@ -177,8 +303,8 @@ function seatLabel(v: OldMaidView, id: string, me: string | null, players: Recor
else if (st === 'left') parts.push('나갔어요');
else parts.push(`카드 ${v.handCounts[id]}장`);
parts.push(`버린 짝 ${v.pairCounts[id]}쌍`);
if (v.turn === id) parts.push('뽑는 차례');
if (v.target === id) parts.push('카드를 뽑히는 중');
if (v.turn === id) parts.push(v.target ? `${whose(players, v.target, me)} 카드를 뽑는 차례` : '뽑는 차례');
if (v.target === id && v.turn) parts.push(`${who(players, v.turn, me)}에게 카드를 뽑히는 중`);
if (v.final?.thief === id) parts.push('도둑');
if (v.away[id]) parts.push('자리 비움');
return parts.join(', ');
@@ -202,8 +328,8 @@ function Seat({ id, v, me, players, deadline, bubble }: { id: string; v: OldMaid
{v.turn === id && <TurnTimer deadline={deadline} totalMs={v.turnMs} mine={false} size={30} />}
</div>
<div className="om-badges" aria-hidden>
{v.turn === id && <span className="om-badge turn">뽑는 중</span>}
{v.target === id && <span className="om-badge target">{v.turn === me ? '여기서 뽑아요' : '뽑히는 중'}</span>}
{v.turn === id && <span className="om-badge turn">{v.target === me ? '내 카드 뽑는 중' : '뽑는 중'}</span>}
{v.target === id && <span className="om-badge target">{v.turn === me ? '내가 여기서 뽑아요' : '뽑히는 중'}</span>}
{st === 'out' && <span className="om-badge win">🎉 {v.places[id]}등</span>}
{st === 'left' && <span className="om-badge">나감</span>}
{thief && <span className="om-badge lose">🃏 도둑</span>}
@@ -212,8 +338,10 @@ function Seat({ id, v, me, players, deadline, bubble }: { id: string; v: OldMaid
<div className="om-meta" aria-hidden>
{st === 'playing' || thief ? (
<>
<MiniBacks n={v.handCounts[id] ?? 0} />
<span>{v.handCounts[id]}장</span>
<MiniFan n={v.handCounts[id] ?? 0} />
<span>
<strong>{v.handCounts[id]}</strong>장
</span>
</>
) : (
<span>{st === 'out' ? '다 털었어요' : '나갔어요'}</span>
@@ -224,17 +352,78 @@ function Seat({ id, v, me, players, deadline, bubble }: { id: string; v: OldMaid
);
}
/** The face-down hand of the player being drawn from. Interactive only for the drawer. */
function Fan({ v, me, players, act, pending, tapConfirm, shake }: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; shake: boolean }) {
/** "[🙂 친구님] → [🙂 내 카드 3장]": the arrow always points from whoever draws to the hand being drawn from. */
function DrawTitle({ v, me, players }: { v: OldMaidView; me: string | null; players: Record<string, PublicUser> }) {
const drawer = v.turn!;
const target = v.target;
const count = target ? (v.handCounts[target] ?? 0) : 0;
const sentence = target ? `${drawerSubj(players, drawer, me)} ${whose(players, target, me)} 카드 ${count}장 중에서 한 장을 뽑아요` : `${drawerSubj(players, drawer, me)} 뽑을 차례예요`;
return (
<div className="om-title">
<span className="sr-only">{sentence}</span>
<span className={`om-who${drawer === me ? ' me' : ''}`} aria-hidden>
<Avatar user={userOf(players, drawer)} size={24} />
{drawer === me ? (
<span>내가</span>
) : (
<span className="lbl">
<span className="nm">{nick(players, drawer)}</span>님
</span>
)}
</span>
{target && (
<>
<span className="om-arrow" aria-hidden>
<svg width="28" height="16" viewBox="0 0 28 16">
<path d="M2 8h21M17 2l6 6-6 6" fill="none" stroke="currentColor" strokeWidth="3.2" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
<span className={`om-who${target === me ? ' me' : ''}`} aria-hidden>
<Avatar user={userOf(players, target)} size={24} />
{target === me ? (
<span>내 카드</span>
) : (
<span className="lbl">
<span className="nm">{nick(players, target)}</span>님의 카드
</span>
)}
<b>{count}장</b>
</span>
</>
)}
</div>
);
}
const FAN_PC = { cw: 70, prefer: 54 };
const FAN_PHONE = { cw: 50, prefer: 39, wrapCw: 44 };
/** The face-down hand of the player being drawn from, held as a fan. Interactive only for the drawer. */
function Fan({ v, me, players, act, pending, tapConfirm, riffle }: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; riffle: boolean }) {
const target = v.target!;
const mine = !!v.my?.canDraw && v.my.from === target;
const count = mine ? v.my!.count : (v.handCounts[target] ?? 0);
const [sel, setSel] = useState<number | null>(null);
const [ref, width, box] = useWidth<HTMLDivElement>();
// A new turn, or the owner shuffled / the fan changed: start over.
useEffect(() => setSel(null), [v.turnNo, target, count, v.shuffles[target]]);
// Where every card sits now (relative to the table), so a draw by someone else lifts that very card (useOldMaidFx).
useEffect(() => {
const table = fxEl('om-table');
if (!table || !box.current) return;
const t = table.getBoundingClientRect();
fanSnap = {
target,
rects: Array.from(box.current.querySelectorAll('.om-back > .om-face'), (el) => {
const r = el.getBoundingClientRect();
return [r.left - t.left, r.top - t.top, r.width, r.height] as const;
}),
};
});
const l = fanLayout(count, width, width > 0 && width < 520 ? FAN_PHONE : { ...FAN_PC, wrapCw: count > 12 ? 50 : 60 });
const draw = (index: number) => {
if (pending) return;
myDrawRect = document.querySelectorAll('.om-fan button.om-back')[index]?.getBoundingClientRect() ?? null;
myDrawRect = box.current?.querySelectorAll('button.om-back')[index]?.querySelector('.om-face')?.getBoundingClientRect() ?? null;
act({ type: 'draw', from: target, index });
setSel(null);
};
@@ -261,17 +450,25 @@ function Fan({ v, me, players, act, pending, tapConfirm, shake }: { v: OldMaidVi
const owner = who(players, target, me);
return (
<div
className={`om-fan${count > 12 ? ' many' : ''}${shake ? ' shake' : ''}`}
ref={ref}
className={`om-fan${l.wrap ? ' wrap' : ''}${riffle ? ' riffle' : ''}`}
style={rowStyle(l)}
role="group"
aria-label={mine ? `${owner}의 뒤집힌 카드 ${count}장. 좌우 방향키로 고르고 Enter로 뽑아요` : `${owner}의 뒤집힌 카드 ${count}장`}
onKeyDown={onKey}
>
{Array.from({ length: count }, (_, i) =>
mine ? (
{Array.from({ length: count }, (_, i) => {
const { t } = fanCard(i, count, l);
// Shuffling: the halves slide towards the middle and back, every other card a bit off, one after another.
const sx = (l.wrap ? 0 : Math.round(-t * Math.min(60, l.step * 1.5))) + (i % 2 ? 7 : -7);
const style = stripStyle(i, count, l, { '--i': i, '--sx': `${sx}px` });
const cls = `om-back om-strip${i === count - 1 ? ' last' : ''}`;
return mine ? (
<button
key={i}
type="button"
className="om-back"
className={cls}
style={style}
aria-pressed={sel === i}
disabled={pending}
aria-label={`${i + 1}번째 카드${sel === i ? '. 한 번 더 누르면 뽑아요' : ''}`}
@@ -285,13 +482,13 @@ function Fan({ v, me, players, act, pending, tapConfirm, shake }: { v: OldMaidVi
</span>
</button>
) : (
<span key={i} className="om-back" aria-hidden>
<span key={i} className={cls} style={style} aria-hidden>
<span className="om-face">
<PlayingCard card={null} size="lg" style={{ width: '100%', height: '100%', filter: 'none' }} />
</span>
</span>
),
)}
);
})}
</div>
);
}
@@ -300,7 +497,7 @@ function LastDraw({ v, me, players }: { v: OldMaidView; me: string | null; playe
const d = v.lastDraw;
if (!d) return null;
const mineDraw = d.drawer === me;
const text = `${who(players, d.drawer, me)}${mineDraw ? '는' : '이'} ${who(players, d.from, me)}의 ${d.index + 1}번째 카드를 뽑았어요${d.auto ? '(시간 초과)' : ''}`;
const text = `${drawerSubj(players, d.drawer, me)} ${whose(players, d.from, me)} ${d.index + 1}번째 카드를 뽑았어요${d.auto ? '(시간 초과)' : ''}`;
let tail: string;
if (d.pair) tail = `${cardName(d.pair[0])}·${cardName(d.pair[1])} 짝을 버렸어요`;
else if (mineDraw && d.card) tail = d.card === JOKER ? '앗, 조커를 뽑았어요!' : `뽑은 카드 ${cardName(d.card)} · 짝이 없어서 손에 넣었어요`;
@@ -312,7 +509,7 @@ function LastDraw({ v, me, players }: { v: OldMaidView; me: string | null; playe
{d.pair ? d.pair.map((c) => <Card key={c} card={c} />) : <Card card={d.card} />}
</span>
)}
<span className="small" style={{ lineHeight: 1.45 }} aria-hidden>
<span className="small txt" aria-hidden>
{text}
<br />
<strong>{tail}</strong>
@@ -326,18 +523,22 @@ function Pile({ v }: { v: OldMaidView }) {
const total = Object.values(v.pairCounts).reduce((a, b) => a + b, 0);
return (
<div className="om-pile" data-fx="om-pile" aria-label={`버린 짝 모두 ${total}쌍${pairs.length ? `, 최근: ${pairs.map((p) => `${cardName(p[0])}·${cardName(p[1])}`).join(', ')}` : ''}`} role="group">
<span>버린 짝 {total}쌍 / 26쌍</span>
{pairs.map((p, i) => (
<span key={i} className="pair" data-pair={pairKey(p)} aria-hidden>
<Card card={p[0]} />
<Card card={p[1]} />
<span className="lbl">버린 짝 {total}쌍 / 26쌍</span>
{pairs.length > 0 && (
<span className="pairs">
{pairs.map((p, i) => (
<span key={i} className="pair" data-pair={pairKey(p)} aria-hidden>
<Card card={p[0]} />
<Card card={p[1]} />
</span>
))}
</span>
))}
)}
</div>
);
}
function Table(props: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; shake: boolean }) {
function Table(props: { v: OldMaidView; me: string | null; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; tapConfirm: boolean; riffle: boolean }) {
const { v, me, players } = props;
if (v.phase === 'finished') {
const f = v.final!;
@@ -346,7 +547,7 @@ function Table(props: { v: OldMaidView; me: string | null; players: Record<strin
<strong className="om-title">게임이 끝났어요</strong>
{f.thief ? (
<>
<Card card={JOKER} className="om-thief-joker" />
<Card card={JOKER} className="om-thief-joker" style={{ '--cw': '64px' } as CSSProperties} />
<span style={{ textAlign: 'center', fontWeight: 800 }}>🃏 도둑: {who(players, f.thief, me)}</span>
</>
) : (
@@ -363,13 +564,7 @@ function Table(props: { v: OldMaidView; me: string | null; players: Record<strin
const target = v.target;
return (
<div className="om-table" role="group" aria-label="테이블" data-fx="om-table">
<div className="om-title">
<span>{who(players, drawer, me)}</span>
<span className="arrow" aria-hidden>
←
</span>
<span>{target ? `${who(players, target, me)}의 카드 ${v.handCounts[target]}장` : ''}</span>
</div>
<DrawTitle v={v} me={me} players={players} />
{target && <Fan {...props} />}
{v.my?.canDraw ? (
<span className="small" style={{ textAlign: 'center' }}>
@@ -377,7 +572,9 @@ function Table(props: { v: OldMaidView; me: string | null; players: Record<strin
</span>
) : (
<span className="small" style={{ textAlign: 'center' }}>
{target === me ? `${who(players, drawer, me)}이 내 카드를 고르는 중이에요. 아래 [🔀 섞기]로 순서를 바꿀 수 있어요.` : `${who(players, drawer, me)}이 고르는 중이에요.`}
{target === me
? `${drawerSubj(players, drawer, me)} 내 카드를 고르는 중이에요. 아래 [🔀 섞기]로 순서를 바꿀 수 있어요.`
: `${drawerSubj(players, drawer, me)} ${target ? `${whose(players, target, me)} 카드를 ` : ''}고르는 중이에요.`}
</span>
)}
<LastDraw v={v} me={me} players={players} />
@@ -386,10 +583,47 @@ function Table(props: { v: OldMaidView; me: string | null; players: Record<strin
);
}
const HAND_PC = { cw: 72, prefer: 46 };
const HAND_PHONE = { cw: 50, prefer: 34 };
function MyArea({ v, me, players, act, pending, deadline, fresh, bubble }: { v: OldMaidView; me: string; players: Record<string, PublicUser>; act: (a: unknown) => void; pending: boolean; deadline: number | null; fresh: string | null; bubble: string | null }) {
const hand = v.myHand ?? [];
const st = v.status[me];
const cls = ['om-me', v.turn === me ? 'turn anim-glow' : '', v.target === me ? 'target' : ''].filter(Boolean).join(' ');
const [ref, width, box] = useWidth<HTMLDivElement>();
const narrow = width > 0 && width < 520;
const l = fanLayout(hand.length, width, { ...(narrow ? HAND_PHONE : HAND_PC), wrapCw: narrow ? (hand.length > 12 ? 44 : 50) : hand.length > 12 ? 52 : 64 });
// Shuffled (same cards, new order): every card slides with a little hop from its old place to its new one.
const order = hand.join(',');
const pos = useRef<{ order: string; at: Map<string, [number, number]> }>({ order: '', at: new Map() });
useLayoutEffect(() => {
const el = box.current;
const prev = pos.current;
const at = new Map<string, [number, number]>();
const cards = el ? Array.from(el.querySelectorAll<HTMLElement>('.om-card')) : [];
if (el) {
const b = el.getBoundingClientRect();
for (const c of cards) {
const r = c.getBoundingClientRect();
at.set(c.dataset.card ?? '', [r.left - b.left, r.top - b.top]);
}
}
pos.current = { order, at };
if (prev.order === order || prev.at.size !== at.size || at.size < 2 || reducedMotion() || ![...at.keys()].every((k) => prev.at.has(k))) return;
let n = 0;
for (const c of cards) {
const a = prev.at.get(c.dataset.card ?? '');
const b = at.get(c.dataset.card ?? '');
if (!a || !b) continue;
const dx = a[0] - b[0];
const dy = a[1] - b[1];
if (Math.abs(dx) + Math.abs(dy) < 2 || typeof c.animate !== 'function') continue;
c.animate(
[{ transform: `translate(${dx}px, ${dy}px)` }, { transform: `translate(${dx / 2}px, ${dy / 2 - 18}px)`, offset: 0.45 }, { transform: 'translate(0px, 0px)' }],
{ duration: 480, delay: n++ * 14, easing: 'cubic-bezier(.3,.7,.3,1)', fill: 'backwards', composite: 'add' },
);
}
}, [order, width, l.wrap]);
return (
<section className={cls} data-fx-seat={me} aria-label="내 자리">
{bubble && (
@@ -400,6 +634,16 @@ function MyArea({ v, me, players, act, pending, deadline, fresh, bubble }: { v:
<div className="om-head">
<Avatar user={userOf(players, me)} size={26} />
<span className="om-name">{nick(players, me)} (나)</span>
{v.turn === me && v.phase === 'playing' && (
<span className="om-badge turn" aria-hidden>
뽑을 차례
</span>
)}
{v.target === me && (
<span className="om-badge target" aria-hidden>
뽑히는 중
</span>
)}
{v.away[me] && <span className="om-badge">자리 비움</span>}
{st === 'out' && <span className="om-badge win">🎉 {v.places[me]}등</span>}
{v.final?.thief === me && <span className="om-badge lose">🃏 도둑</span>}
@@ -416,10 +660,14 @@ function MyArea({ v, me, players, act, pending, deadline, fresh, bubble }: { v:
)}
</div>
{hand.length > 0 ? (
<div className={`om-hand${hand.length > 12 ? ' many' : ''}`} data-fx="om-hand" role="list" aria-label={`내 손패, 왼쪽부터: ${hand.map(cardAria).join(', ')}`}>
{hand.map((c) => (
<div ref={ref} className={`om-hand${l.wrap ? ' wrap' : ''}`} style={rowStyle(l)} data-fx="om-hand" role="list" aria-label={`내 손패, 왼쪽부터: ${hand.map(cardAria).join(', ')}`}>
{hand.map((c, i) => (
<span key={c} role="listitem" aria-label={cardAria(c)} style={{ display: 'contents' }}>
<Card card={c} className={[c === JOKER ? 'joker' : '', c === fresh ? 'fresh' : ''].filter(Boolean).join(' ')} />
<Card
card={c}
className={['om-strip', i === hand.length - 1 ? 'last' : '', c === JOKER ? 'joker' : '', c === fresh ? 'fresh' : ''].filter(Boolean).join(' ')}
style={stripStyle(i, hand.length, l)}
/>
</span>
))}
</div>
@@ -439,7 +687,7 @@ function OldMaidBoard({ view: v, me, players, act, pending, deadline, tapConfirm
const amPlayer = !!me && v.order.includes(me);
const [announce, setAnnounce] = useState('');
const [bubbles, setBubbles] = useState<Record<string, string>>({});
const [shake, setShake] = useState(false);
const [riffle, setRiffle] = useState(false);
const [fresh, setFresh] = useState<string | null>(null);
const prev = useRef({ logCount: v.logCount, hand: v.myHand ?? [], turn: v.turn });
const [banner, showBanner] = useBanner();
@@ -452,12 +700,12 @@ function OldMaidBoard({ view: v, me, players, act, pending, deadline, tapConfirm
const added = n ? v.log.slice(-n) : [];
const msgs: string[] = [];
const bub: Record<string, string> = {};
let shook = false;
let shuffled = false;
for (const e of added) {
msgs.push(logText(e, players, me));
if (e.t === 'shuffle') {
bub[e.player] = '🔀 섞었어요';
if (e.player === v.target) shook = true;
if (e.player === v.target) shuffled = true;
} else if (e.t === 'draw' && e.pair) bub[e.drawer] = '짝!';
else if (e.t === 'out') bub[e.player] = '🎉 다 털었어요';
}
@@ -484,9 +732,9 @@ function OldMaidBoard({ view: v, me, players, act, pending, deadline, tapConfirm
setTimeout(() => setBubbles((b) => Object.fromEntries(Object.entries(b).filter(([k]) => !(k in bub)))), 2500);
}
prev.current = { logCount: v.logCount, hand, turn: v.turn };
if (shook) {
setShake(true);
const t = setTimeout(() => setShake(false), 550);
if (shuffled) {
setRiffle(true);
const t = setTimeout(() => setRiffle(false), 1000);
return () => clearTimeout(t);
}
return undefined;
@@ -501,7 +749,7 @@ function OldMaidBoard({ view: v, me, players, act, pending, deadline, tapConfirm
<Seat key={p} id={p} v={v} me={me} players={players} deadline={deadline} bubble={bubbles[p] ?? null} />
))}
</div>
<Table v={v} me={me} players={players} act={act} pending={pending} tapConfirm={tapConfirm} shake={shake} />
<Table v={v} me={me} players={players} act={act} pending={pending} tapConfirm={tapConfirm} riffle={riffle} />
{amPlayer && <MyArea v={v} me={me!} players={players} act={act} pending={pending} deadline={deadline} fresh={fresh} bubble={bubbles[me!] ?? null} />}
<p className="sr-only" aria-live="polite">
{announce}
@@ -534,18 +782,24 @@ function useOldMaidFx(v: OldMaidView, me: string | null, players: Record<string,
switch (e.t) {
case 'draw': {
const newMine = e.drawer === me && !e.pair && ld?.no === e.no && ld.drawer === me && ld.card ? handCardEl(ld.card) : null;
if (newMine) flyFrom(newMine, myDrawRect ?? seatEl(e.from), { ms: 420, rotate: 12, delay: at });
else flyGhost(e.drawer === me && myDrawRect ? myDrawRect : spot(e.from), spot(e.drawer), { delay: at, ms: 420 });
// The drawn card itself rises out of the fan and flies to whoever drew it (my new card shows up when it lands).
const from = e.drawer === me && myDrawRect ? myDrawRect : fanCardRect(e.from, e.index);
const lifted = !!from && liftFly(from, newMine?.querySelector('.om-face') ?? spot(e.drawer), at);
if (lifted && newMine) reveal(newMine, at + LIFT_MS - 120);
else if (!lifted && newMine) flyFrom(newMine, myDrawRect ?? seatEl(e.from), { ms: 420, rotate: 12, delay: at });
else if (!lifted) flyGhost(spot(e.from), spot(e.drawer), { delay: at, ms: 420 });
if (e.drawer === me) myDrawRect = null;
fanSnap = null;
const land = lifted ? LIFT_MS - 140 : 300;
later(at, () => {
if (e.auto) sfx.tick();
sfx.draw();
});
if (e.pair) {
pile([e.pair], spot(e.drawer), at + 300);
later(at + 330, omSfx.pair);
later(at + 330, () => bump(document.querySelector('.om-last .cards'), 'pop'));
t += 420;
pile([e.pair], spot(e.drawer), at + land);
later(at + land + 30, omSfx.pair);
later(at + land + 30, () => bump(document.querySelector('.om-last .cards'), 'pop'));
t += land + 120;
} else t += 160;
break;
}
@@ -560,7 +814,8 @@ function useOldMaidFx(v: OldMaidView, me: string | null, players: Record<string,
case 'shuffle':
later(at, () => {
sfx.shuffle();
bump(e.player === me ? fxEl('om-hand') : seatEl(e.player), 'shake');
// My own hand slides card by card (MyArea), the fan being drawn from riffles (Fan); other seats wiggle.
if (e.player !== me) bump(seatEl(e.player), 'shake');
});
t += 120;
break;
@@ -611,11 +866,14 @@ function useOldMaidFx(v: OldMaidView, me: string | null, players: Record<string,
started.current = true;
// Mounted right at the start (nobody has drawn or shuffled yet): show the deal once.
if (v.phase !== 'playing' || v.logCount !== 0 || v.turnNo !== 1) return;
const table = fxEl('om-table');
sfx.shuffle();
setTimeout(() => sfx.deal(8, 60), 300);
document.querySelectorAll('.om-hand .om-card').forEach((el, i) => flyFrom(el, table, { delay: 280 + i * 40, rotate: 10 }));
for (const p of v.order) if (p !== me) flyGhost(table, seatEl(p), { count: 3, gap: 90, delay: 280 });
// Next frame: the card rows lay themselves out once their width is known (useWidth), so measure after that.
requestAnimationFrame(() => {
const table = fxEl('om-table');
document.querySelectorAll('.om-hand .om-card').forEach((el, i) => flyFrom(el, table, { delay: 280 + i * 40, rotate: 10 }));
for (const p of v.order) if (p !== me) flyGhost(table, seatEl(p), { count: 3, gap: 90, delay: 280 });
});
}, []); // eslint-disable-line react-hooks/exhaustive-deps
}

View File

@@ -89,13 +89,13 @@ interface OldMaidState {
## 9. UI/UX
- 소리·움직임(2026-10-13): 뽑기 = 뽑힌 자리에서 뽑는 자리로 카드가 날아가며 소리, 짝 버리기 = 버린 짝 더미로, 손패 다 털기 = 등수 배너, 섞기 = 섞는 소리, 게임 끝 = "🃏 도둑!" 배너, 시작 = 나눠 주기. 내 행동과 남(컴퓨터 포함)의 행동 모두 view 변화에 반응하고, 처음 들어올 때·새로고침·다시 보기 건너뛰기에는 나지 않는다. 움직임은 0.2~0.6초, 날아가는 카드는 클릭을 막지 않는다. 소리는 사이트 음량을 따르고 합성음만 쓴다(파일 없음). 차례인 자리는 테두리가 은은하게 빛난다.
- 위: 다른 사람 자리 카드(내 다음 자리부터, 즉 내가 뽑을 사람이 맨 앞). 장수(작은 뒷면 묶음), 버린 짝 수, "뽑는 중"/"뽑히는 중"/"🎉 N등"/"🃏 도둑" 배지, 섞으면 "🔀 섞었어요" 말풍선.
- 가운데 초록 테이블: "A ← B의 카드 N장"과 뽑힐 사람의 뒷면 카드를 펼쳐 보여 준다(자리 번호 표시, 많으면 작게 여러 줄). 내 차례면 카드가 버튼이 된다. 터치 기기에서 "두 번 눌러 확인"(설정 `tapConfirm`)이 켜져 있으면 첫 탭은 고르기(카드가 위로), 두 번째 탭에 뽑는다. PC 마우스는 한 번에 뽑는다. 키보드는 좌우 방향키로 고르고 Enter. 뽑힐 사람이 섞으면 펼친 카드가 흔들리고 고른 것이 풀린다.
- 지난 뽑기: 누가 누구의 몇 번째를 뽑았는지, 짝이 나면 두 장을 앞면으로. 내가 뽑은 카드는 나에게만 앞면으로("뽑은 카드 ♠9 · 짝이 없어서 손에 넣었어요", "앗, 조커를 뽑았어요!"). 최근 버린 짝 6쌍.
- 아래 내 자리: 내 손패(앞면, 실제 순서), 조커는 빨간 테두리, 방금 들어온 카드는 반짝. [🔀 섞기 (남은 횟수/3)] 버튼. "다른 사람에게는 이 순서 그대로 뒷면으로 보여요" 안내. 조커를 넘기면 "조커를 넘겼어요! 😆" 알림.
- 소리·움직임(2026-10-13): 뽑기 = 뽑힌 카드가 펼친 부채에서 위로 들렸다가 뽑는 사람 자리로 날아가며 소리(내가 뽑은 카드는 내 손패 자리에 내려앉으며 앞면으로 나타남), 짝 버리기 = 버린 짝 더미로, 손패 다 털기 = 등수 배너, 섞기 = 섞는 소리와 함께 뽑힐 사람의 펼친 카드가 가운데로 모였다 다시 펼쳐지고(리플), 섞은 사람 본인 화면에서는 내 손패 카드가 한 장씩 새 자리로 미끄러져 간다(다른 자리는 자리 카드가 흔들림), 게임 끝 = "🃏 도둑!" 배너, 시작 = 나눠 주기. 내 행동과 남(컴퓨터 포함)의 행동 모두 view 변화에 반응하고, 처음 들어올 때·새로고침·다시 보기 건너뛰기에는 나지 않는다. 움직임은 0.2~0.65초, 날아가는 카드는 클릭을 막지 않는다. 소리는 사이트 음량을 따르고 합성음만 쓴다(파일 없음). 차례인 자리는 테두리가 은은하게 빛나고 "뽑는 중" 배지가 살짝 숨 쉬듯 커졌다 작아진다. `prefers-reduced-motion`이면 날아가기·리플·화살표·배지 움직임을 모두 끈다.
- 위: 다른 사람 자리 카드(내 다음 자리부터, 즉 내가 뽑을 사람이 맨 앞). 장수(장수만큼 넓게 펼쳐지는 작은 뒷면 부채, 최대 10장), 버린 짝 수, "뽑는 중"(내 카드를 뽑는 중이면 "내 카드 뽑는 중")/"뽑히는 중"(내가 뽑을 차례면 "내가 여기서 뽑아요")/"🎉 N등"/"🃏 도둑" 배지, 섞으면 "🔀 섞었어요" 말풍선.
- 가운데 초록 테이블(나무 테두리, 가운데가 밝은 펠트): 맨 위 제목은 "[아바타] A님 → [아바타] B님의 카드 N장". 화살표는 언제나 **뽑는 사람에서 뽑히는 손패 쪽으로** 향하고 살짝 앞뒤로 움직인다. 내가 뽑으면 "내가 →", 내 카드가 뽑히면 "→ 내 카드 N장"("나의"는 쓰지 않는다; 기록·지난 뽑기 문장도 "내가 …", "… 내 2번째 카드"). 그 아래 뽑힐 사람의 뒷면 카드를 손에 쥔 부채처럼 겹쳐 호 모양으로 펼친다(바깥 카드일수록 기울고 조금 낮게, 자리 번호는 각 카드의 보이는 띠에). 겹침은 장수와 폭으로 정하고, 모든 카드가 28px 이상(계산은 30px) 눌리는 띠를 갖지 못하면 예전처럼 여러 줄로 감싼다(`fan.ts`, 휴대폰 카드 폭 50px, 감쌀 때 44px; PC 70px). 각 버튼은 보이는 띠만큼의 폭이고 카드 그림이 오른쪽으로 넘쳐서 다음 카드 밑에 깔리므로, 겹쳐도 누르는 곳과 보이는 곳이 같다. 마우스를 올리면 카드가 부채에서 들리며 빛나고, 고른 카드는 더 높이 들리고 노란 테두리로 빛난다. 내 차례면 카드가 버튼이 된다. 터치 기기에서 "두 번 눌러 확인"(설정 `tapConfirm`)이 켜져 있으면 첫 탭은 고르기(카드가 위로), 두 번째 탭에 뽑는다. PC 마우스는 한 번에 뽑는다. 키보드는 좌우 방향키로 고르고 Enter. 뽑힐 사람이 섞으면 펼친 카드가 리플하고 고른 것이 풀린다.
- 지난 뽑기(테이블 안 어두운 띠): 누가 누구의 몇 번째를 뽑았는지, 짝이 나면 두 장을 살짝 부채꼴로 겹친 앞면으로. 내가 뽑은 카드는 나에게만 앞면으로("뽑은 카드 ♠9 · 짝이 없어서 손에 넣었어요", "앗, 조커를 뽑았어요!"). 최근 버린 짝 6쌍("버린 짝 N쌍 / 26쌍" 칩 옆에, 한 쌍씩 두 장을 기울여 겹친 작은 카드).
- 아래 내 자리: 내 손패(앞면, 실제 순서)도 들어가면 완만한 호의 부채로 겹쳐 펼친다(모서리 숫자가 보이는 띠 30px 이상, 안 되면 여러 줄), 마우스를 올리면 카드가 들린다. 조커는 빨간 테두리, 방금 들어온 카드는 주황빛으로 반짝. 내 카드가 뽑히는 중이면 "뽑히는 중", 내 차례면 "뽑을 차례" 배지. [🔀 섞기 (남은 횟수/3)] 버튼. "다른 사람에게는 이 순서 그대로 뒷면으로 보여요" 안내. 조커를 넘기면 "조커를 넘겼어요! 😆" 알림.
- 오른쪽(휴대폰은 아래): 차례·타이머, 참가자(장수/등수), 최근 기록, 결과(등수와 도둑), 도움말.
- 휴대폰 320px~: 자리 카드 2열, 카드 폭 44~50px(터치 44px 이상). 다크 모드는 공통 색 변수, 화면 읽기 프로그램용 aria-label과 aria-live 안내.
- 휴대폰 320px~: 자리 카드 2열, 카드 폭 44~50px(겹친 부채에서도 눌리는 띠 28px 이상, 높이 70px). 다크 모드는 공통 색 변수, 화면 읽기 프로그램용 aria-label과 aria-live 안내.
- 컴퓨터 상대: 단계와 관계없이 무작위로 한 장 뽑고, 가끔(15%, 차례마다 한 번까지) 자기 손패를 먼저 섞는다. 생각 시간은 방의 공통 "사람 같은 지연".
## 10. 테스트 체크리스트