카드 게임 시간 무제한(우노·뱅!·달무티·고스톱·도둑잡기·포커·바퀴벌레 포커·99), 공통 카드 움직임(card-fx), 우노·달무티·도둑잡기·포커 소리·애니메이션

- 무제한(null): 차례 시계·타임아웃 없음, 자리 비움만 짧은 시계, 연결 끊김은 방 유예 뒤 자동 행동 그대로
- 포커는 리바이 고르는 시간도 무제한 가능, 고스톱은 고·스톱 선택 시간도 무제한 가능, 뱅!은 반응 시간·캐릭터 고르기도
- card-fx: 날아가는 카드·칩(ghost), 제자리 날아오기, 배너, view 변화 감지 훅(처음 렌더·다시 보기는 건너뜀)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:04:11 +09:00
parent f12cf12b84
commit ac37a6a6d8
44 changed files with 1438 additions and 198 deletions

View File

@@ -4,7 +4,8 @@ import type { CardFace, Color, LogEntry, SeatView, UnoCard, UnoOptions, UnoView
import type { PublicUser } from '@bg/shared/lite';
import { Avatar, Sheet } from '../../components/ui';
import { TurnTimer } from '../../components/TurnTimer';
import { haptic, sounds } from '../../lib/feedback';
import { haptic, sfx, sounds, tone } from '../../lib/feedback';
import { bump, cssEsc, flyFrom, flyGhost, fxEl, seatEl, useBanner, useChange, useNewEntries } from '../card-fx';
import { useSeatRows } from '../../lib/seat-rows';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { COLOR_HEX, COLOR_INK, COLOR_KO, ColorCardArt, patternName } from '../one-card/ColorCard';
@@ -36,6 +37,30 @@ function cardName(c: CardFace): string {
const isWild = (c: CardFace) => c.kind === 'wild' || c.kind === 'wild4';
/** 우노 sounds on top of the shared palette (synthesized, no files). */
const unoSfx = {
skip: () => {
tone(520, 80, 'square', 0.05);
tone(330, 140, 'square', 0.05, 80);
},
reverse: () => {
tone(420, 220, 'triangle', 0.1, 0, { slideTo: 900 });
tone(900, 220, 'triangle', 0.08, 160, { slideTo: 420 });
},
wild: () => [523, 659, 784, 1046].forEach((f, i) => tone(f, 90, 'triangle', 0.08, i * 55)),
/** Heavy "+2 / +4" thump. */
plus: () => {
tone(170, 180, 'sawtooth', 0.07, 0, { slideTo: 80 });
tone(110, 220, 'sine', 0.16);
},
};
/** Where my last played card was (its button is gone once the view arrives), so the pile card flies from there. */
let myPlayRect: DOMRect | null = null;
const rememberPlay = (id: string) => {
myPlayRect = document.querySelector(`.un-card[data-id="${cssEsc(id)}"]`)?.getBoundingClientRect() ?? null;
};
function sortHand(hand: UnoCard[], by: 'color' | 'number'): UnoCard[] {
const col = (c: UnoCard) => ('color' in c ? COLORS.indexOf(c.color) : 9);
const num = (c: UnoCard) => (c.kind === 'num' ? c.value : c.kind === 'skip' ? 10 : c.kind === 'reverse' ? 11 : c.kind === 'draw2' ? 12 : c.kind === 'wild' ? 20 : 21);
@@ -77,7 +102,6 @@ const CSS = `
.un-discard { position: relative; width: calc(var(--pw) * 1.12); height: calc(var(--pw) * 1.12 * 1.4); border-radius: 12px; }
.un-discard::before { content: ''; position: absolute; inset: -9px; border-radius: 18px; border: 5px solid var(--cc, transparent); box-shadow: 0 0 18px var(--cc, transparent); transition: border-color .3s, box-shadow .3s; }
.un-discard > .un-face { position: absolute; inset: 0; }
.un-discard > .un-face.top { animation: un-fly .28s ease-out; }
.un-discard[data-drop='true'] { outline: 3px dashed #fde047; outline-offset: 12px; }
.un-info { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.un-info .row { gap: 6px; }
@@ -123,7 +147,6 @@ const CSS = `
.un-log { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 3px; max-height: 240px; overflow: auto; }
.un-rules td, .un-rules th { padding: 4px 6px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.un-rules .un-face { width: 34px; height: 48px; }
@keyframes un-fly { from { transform: translate(-40px, 30px) scale(.8); opacity: .3; } to { transform: none; opacity: 1; } }
@keyframes un-pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes un-shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@media (min-width: 720px) {
@@ -163,7 +186,7 @@ function seatLabel(s: SeatView, players: Record<string, PublicUser>, me: string
function SeatChip({ s, v, players, me, deadline, next }: { s: SeatView; v: UnoView; players: Record<string, PublicUser>; me: string | null; deadline: number | null; next: boolean }) {
const u = userOf(players, s.id);
return (
<li className={`un-seat${s.isTurn ? ' turn' : next ? ' next' : ''}${s.left ? ' gone' : ''}`} aria-label={seatLabel(s, players, me, v)}>
<li className={`un-seat${s.isTurn ? ' turn anim-glow' : next ? ' next' : ''}${s.left ? ' gone' : ''}`} data-fx-seat={s.id} aria-label={seatLabel(s, players, me, v)}>
<div className="row" style={{ gap: 6, flexWrap: 'nowrap' }}>
<Avatar user={u} size={24} />
<span className="nm">{u.nickname}</span>
@@ -199,7 +222,7 @@ function TableArea({ v, players, canDraw, onDraw, onDropCard }: { v: UnoView; pl
const next = nextOf(v, v.current);
return (
<div className="un-table" role="region" aria-label="카드 판" style={{ '--pw': pw } as CSSProperties}>
<button type="button" className="un-pile" data-can={canDraw} disabled={!canDraw} onClick={onDraw} aria-label={`카드 더미 ${v.drawPileCount}장${canDraw ? `. 눌러서 ${drawText}` : ''}`}>
<button type="button" className="un-pile" data-fx="uno-deck" data-can={canDraw} disabled={!canDraw} onClick={onDraw} aria-label={`카드 더미 ${v.drawPileCount}장${canDraw ? `. 눌러서 ${drawText}` : ''}`}>
<Face card={null} />
<span className="cnt" aria-hidden>
{v.drawPileCount}
@@ -235,7 +258,7 @@ function TableArea({ v, players, canDraw, onDraw, onDropCard }: { v: UnoView; pl
</div>
<div className="un-info">
{v.color ? (
<span key={v.color} className="un-color" style={{ background: COLOR_HEX[v.color], color: COLOR_INK[v.color] }} aria-live="polite">
<span key={v.color} className="un-color anim-pop" style={{ background: COLOR_HEX[v.color], color: COLOR_INK[v.color] }} aria-live="polite">
<span className="sw" aria-hidden />
지금 색: {COLOR_KO[v.color]}
</span>
@@ -316,7 +339,12 @@ function MyHand({ v, act, pending, players }: { v: UnoView; act: (a: unknown) =>
const myTurn = v.current === v.me && (v.phase === 'turn' || v.phase === 'afterDraw' || (v.phase === 'wild4' && my.playable.length > 0));
const byId = (id: string) => my.hand.find((c) => c.id === id);
useNewEntries(my.hand, (c) => c.id, (fresh) => {
const deck = fxEl('uno-deck');
fresh.forEach((c, i) => flyFrom(document.querySelector(`.un-card[data-id="${cssEsc(c.id)}"]`), deck, { delay: i * 70, rotate: 8 }));
}, 30);
const send = (id: string, extra: Record<string, unknown> = {}) => {
rememberPlay(id);
act({ type: 'play', cardId: id, ...extra, ...(armed && my.hand.length === 2 ? { uno: true } : {}) });
setSel(null);
setPick(null);
@@ -336,6 +364,7 @@ function MyHand({ v, act, pending, players }: { v: UnoView; act: (a: unknown) =>
}
setNote('');
setSel(c.id);
sfx.select();
};
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
@@ -382,6 +411,7 @@ function MyHand({ v, act, pending, players }: { v: UnoView; act: (a: unknown) =>
</div>
<div
ref={ref}
data-fx="uno-hand"
className={`un-hand${phone ? ' wrap' : ''}`}
role="group"
aria-label="내 카드. 좌우 방향키로 고르고 Enter로 들어 올리거나 내요"
@@ -625,6 +655,9 @@ function UnoBoard({ view: v, me, players, act, pending, deadline }: BoardProps<U
if (lastLog && !mine) setAnnounce(logText(lastLog, players));
}, [lastLog?.seq, lastLog?.t]); // eslint-disable-line react-hooks/exhaustive-deps
const [banner, showBanner] = useBanner();
useUnoFx(v, me, players, showBanner);
const myIdx = v.seats.findIndex((s) => s.id === me);
const others = myIdx < 0 ? v.seats : [...v.seats.slice(myIdx + 1), ...v.seats.slice(0, myIdx)];
const opps = useSeatRows<HTMLUListElement>(others.length);
@@ -646,7 +679,10 @@ function UnoBoard({ view: v, me, players, act, pending, deadline }: BoardProps<U
onDraw={() => act({ type: 'draw' })}
onDropCard={(id) => {
const c = v.my?.hand.find((x) => x.id === id);
if (c && v.my!.playable.includes(id) && !isWild(c)) act({ type: 'play', cardId: id });
if (c && v.my!.playable.includes(id) && !isWild(c)) {
rememberPlay(id);
act({ type: 'play', cardId: id });
}
}}
/>
<StartColorPanel v={v} act={act} pending={pending} />
@@ -662,10 +698,105 @@ function UnoBoard({ view: v, me, players, act, pending, deadline }: BoardProps<U
<p className="sr-only" aria-live="polite">
{announce}
</p>
{banner}
</div>
);
}
/** Sounds + motion for every change of the table, mine or anyone else's (log entries since the last view). */
function useUnoFx(v: UnoView, me: string | null, players: Record<string, PublicUser>, showBanner: ReturnType<typeof useBanner>[1]) {
const later = (ms: number, f: () => void) => (ms ? setTimeout(f, ms) : f());
useNewEntries(v.log, logKey, (fresh) => {
let t = 0;
for (const e of fresh) {
const at = t;
switch (e.t) {
case 'play': {
const top = document.querySelector('.un-discard .un-face.top');
flyFrom(top, e.p === me ? (myPlayRect ?? fxEl('uno-hand')) : seatEl(e.p), { ms: 340, rotate: -14 });
if (e.p === me) myPlayRect = null;
later(at, () => {
sfx.cardPlay();
if (e.card.kind === 'wild') unoSfx.wild();
if (e.card.kind === 'draw2' || e.card.kind === 'wild4') unoSfx.plus();
});
if (e.card.kind === 'wild4') showBanner('+4', 'dark', e.color ? `${COLOR_KO[e.color]}으로` : undefined);
else if (e.card.kind === 'draw2') showBanner('+2', 'red');
t += 120;
break;
}
case 'draw': {
const n = Math.min(e.n, 8);
if (e.p !== me) flyGhost(fxEl('uno-deck'), seatEl(e.p), { count: n, gap: 80 });
later(at, () => sfx.draw(Math.min(n, 4)));
if (e.why === 'penalty' || e.why === 'challenge' || e.why === 'stack' || e.n >= 4) later(at, () => bump(seatEl(e.p), 'shake'));
t += 120;
break;
}
case 'uno':
showBanner('우노!', 'red', e.p === me ? undefined : `${nick(players, e.p)}님`);
later(at, sfx.fanfare);
bump(seatEl(e.p));
break;
case 'caught':
showBanner('잡았다!', 'gold', `${nick(players, e.p)}님 +${e.n}장`);
later(at, sfx.alarm);
break;
case 'challenge':
showBanner(e.illegal ? '도전 성공!' : '도전 실패', e.illegal ? 'green' : 'dark');
later(at + 150, e.illegal ? sfx.good : sfx.bad);
break;
case 'skip':
later(at + 80, unoSfx.skip);
bump(seatEl(e.p), 'shake');
break;
case 'reverse':
later(at + 80, unoSfx.reverse);
bump(document.querySelector('.un-dir b'));
break;
case 'reshuffle':
later(at, sfx.shuffle);
bump(fxEl('uno-deck'), 'shake');
break;
case 'startColor':
later(at, unoSfx.wild);
break;
case 'round':
if (e.winner) {
const to = seatEl(e.winner) ?? fxEl('uno-hand');
for (const s of v.seats) if (s.id !== e.winner && !s.left) flyGhost(seatEl(s.id), to, { count: 3, gap: 60 });
later(at + 200, sfx.collect);
}
break;
case 'timeout':
later(at, sfx.tick);
break;
default:
break;
}
}
});
// A new round (or the very first deal): cards are dealt from the deck to everyone.
// `myHand`: only on mount — on a later round MyHand's own new-card motion already flies my cards in.
const deal = (myHand: boolean) => {
const deck = fxEl('uno-deck');
sfx.shuffle();
setTimeout(() => sfx.deal(7, 60), 300);
if (myHand) document.querySelectorAll('.un-hand .un-card').forEach((el, i) => flyFrom(el, deck, { delay: 280 + i * 60, rotate: 10 }));
for (const s of v.seats) if (s.id !== me && !s.left) flyGhost(deck, seatEl(s.id), { count: 3, gap: 90, delay: 280 });
};
useChange(v.round, () => deal(false));
const started = useRef(false);
useLayoutEffect(() => {
if (started.current) return;
started.current = true;
// Mounted right at the start of the game (nothing played yet): show the deal once.
if (v.round === 1 && v.discardCount <= 1 && !v.log.some((e) => e.t === 'play')) deal(true);
}, []); // eslint-disable-line react-hooks/exhaustive-deps
}
const logKey = (e: LogEntry) => `${e.seq}-${e.t}-${'p' in e ? e.p : ''}`;
// ---------------------------------------------------------------- side
function rulesLine(o: UnoOptions): string {
@@ -733,7 +864,7 @@ function UnoSide({ view: v, me, players, deadline }: BoardProps<UnoView>) {
<summary style={{ cursor: 'pointer', fontWeight: 700 }}>기록</summary>
<ol className="un-log">
{[...v.log].reverse().map((e) => (
<li key={`${e.seq}-${e.t}-${'p' in e ? e.p : ''}`} className="small">
<li key={logKey(e)} className="small">
{logText(e, players)}
</li>
))}
@@ -777,7 +908,7 @@ function statusText(v: UnoView, me: string | null, players: Record<string, Publi
// ---------------------------------------------------------------- options
function Seg<T extends string | number | boolean>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
function Seg<T extends string | number | boolean | null>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
return (
<div className="segmented" role="group" aria-label={label}>
{options.map(([k, l]) => (
@@ -824,7 +955,7 @@ function Options({ value: o, onChange }: OptionsProps<UnoOptions>) {
<Seg label="낼 수 있을 때까지 뽑기" value={o.drawUntilPlayable} options={onOff} onChange={(drawUntilPlayable) => set({ drawUntilPlayable })} />
</Field>
<Field label="한 턴 제한 시간">
<Seg label="한 턴 제한 시간" value={o.turnSeconds} options={[[10, '10초'], [15, '15초'], [20, '20초'], [30, '30초'], [60, '60초']]} onChange={(turnSeconds) => set({ turnSeconds })} />
<Seg label="한 턴 제한 시간" value={o.turnSeconds} options={[[10, '10초'], [15, '15초'], [20, '20초'], [30, '30초'], [60, '60초'], [null, '무제한']]} onChange={(turnSeconds) => set({ turnSeconds })} />
</Field>
</div>
);
@@ -834,7 +965,7 @@ function optionsSummary(o: UnoOptions): string {
const parts = [o.scoring === 'to500' ? '500점 먼저' : '한 판', o.wild4Rule === 'challenge' ? '+4 도전' : '+4 제한'];
if (o.stacking) parts.push('쌓기');
if (o.drawUntilPlayable) parts.push('나올 때까지 뽑기');
parts.push(`${o.turnSeconds}초`);
parts.push(o.turnSeconds === null ? '시간 무제한' : `${o.turnSeconds}초`);
return parts.join(' · ');
}
@@ -897,7 +1028,10 @@ function Rules({ options }: { options?: UnoOptions }) {
<strong>점수</strong>: 이긴 사람은 다른 사람 손에 남은 카드 점수(숫자 그대로, 스킵·리버스·드로우2 20점, 와일드 50점)를 얻어요.
{o.scoring === 'to500' ? ' 여러 판을 해서 500점에 먼저 닿으면 이겨요.' : ' 이 방은 한 판으로 끝나요.'}
</p>
<p>시간 안에 고르지 않으면 낼 수 있는 카드 하나를 자동으로 내요(와일드는 가장 많이 가진 색). 낼 카드가 없으면 1장 뽑아요.</p>
<p>
{o.turnSeconds === null ? '이 방은 시간 제한이 없어요. 다만 연결이 끊긴 채 오래 돌아오지 않으면' : '시간 안에 고르지 않으면'} 낼 수 있는 카드 하나를 자동으로 내요(와일드는 가장 많이
가진 색). 낼 카드가 없으면 1장 뽑아요.
</p>
</div>
);
}