병합: 도둑잡기 화면 개선(뽑기 방향 바로잡기·부채꼴 카드·애니메이션)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
47
apps/web/src/games/old-maid/fan.test.ts
Normal file
47
apps/web/src/games/old-maid/fan.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
53
apps/web/src/games/old-maid/fan.ts
Normal file
53
apps/web/src/games/old-maid/fan.ts
Normal 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 };
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user