카드 게임 시간 무제한(우노·뱅!·달무티·고스톱·도둑잡기·포커·바퀴벌레 포커·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

@@ -1,10 +1,11 @@
/** 달무티 화면 (docs/games/dalmuti.md §9). */
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
import type { Choice, DCard, DalmutiOptions, DalmutiView, LogEntry, PlayView, SeatView, Title } from '@bg/games/dalmuti';
import type { PublicUser } from '@bg/shared/lite';
import { Avatar } from '../../components/ui';
import { TurnTimer } from '../../components/TurnTimer';
import { haptic, sounds } from '../../lib/feedback';
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
import { bump, cssEsc, flyFrom, flyGhost, fxEl, reducedMotion, seatEl, useBanner, useNewEntries } from '../card-fx';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { helpNow } from './help';
import { quickStart } from './quick';
@@ -51,6 +52,52 @@ const rankText = (rank: number) => (rank === JESTER ? '광대(13)' : String(rank
const setText = (p: { rank: number; count: number }) => `${rankText(p.rank)} × ${p.count}장`;
const facesText = (cards: number[]) => cards.map((n) => (n === JESTER ? '광대' : String(n))).join(', ');
/** 달무티 sounds on top of the shared palette (synthesized, no files). */
const dmSfx = {
/** A set lands on the pile: one slap per card. */
set: (n: number) => {
for (let i = 0; i < Math.min(n, 6); i++) noise(60, 0.15, i * 55, 'bandpass', 1500 + i * 120, 0.9);
tone(220, 70, 'sine', 0.09, Math.min(n - 1, 5) * 55);
},
/** Soft double knock on the table (pass). */
knock: () => {
tone(190, 70, 'sine', 0.14);
noise(35, 0.06, 0, 'lowpass', 700);
tone(165, 70, 'sine', 0.12, 120);
noise(35, 0.05, 120, 'lowpass', 700);
},
/** 혁명 / 대혁명: drum roll, falling growl, then a big chord (higher and longer for 대혁명). */
revolution: (great: boolean) => {
for (let i = 0; i < 7; i++) noise(90, 0.1 + i * 0.012, i * 55, 'lowpass', 320);
tone(130, 520, 'sawtooth', 0.06, 0, { slideTo: great ? 55 : 80 });
[392, 494, 587, 784].forEach((f, i) => tone(f, 420, 'square', 0.045, 420 + i * 35));
if (great) [523, 659, 784, 1046].forEach((f, i) => tone(f, 520, 'square', 0.045, 820 + i * 35));
},
/** Tax card slides over (with a little coin ring). */
tax: () => {
noise(140, 0.1, 0, 'bandpass', 1200, 0.6);
tone(660, 80, 'triangle', 0.07, 120);
tone(990, 130, 'triangle', 0.06, 190);
},
/** Card given back: slide + a lower note. */
give: () => {
noise(140, 0.1, 0, 'bandpass', 1000, 0.6);
tone(520, 110, 'triangle', 0.06, 120);
},
};
/** Where my last played set was (its button may be gone once the view arrives), so the pile cards fly from there. */
let myPlayRect: DOMRect | null = null;
const rememberPlay = (rank: number) => {
myPlayRect = document.querySelector(`.dm-group[data-n="${cssEsc(String(rank))}"]`)?.getBoundingClientRect() ?? null;
};
/** Brief dim of a seat (pass). */
function dim(el: Element | null): void {
if (!el || reducedMotion() || typeof (el as HTMLElement).animate !== 'function') return;
(el as HTMLElement).animate([{ opacity: 1 }, { opacity: 0.4, offset: 0.35 }, { opacity: 1 }], { duration: 650, easing: 'ease-out' });
}
const CSS = `
.dm { width: 100%; max-width: 1080px; display: flex; flex-direction: column; gap: 10px; align-self: center; }
.dm-tip { display: flex; align-items: center; gap: 8px; background: var(--primary-soft); color: var(--text); border-radius: 12px; padding: 6px 6px 6px 12px; font-weight: 700; font-size: .95rem; }
@@ -60,6 +107,7 @@ const CSS = `
.dm-seat { position: relative; flex: 0 1 124px; min-width: 104px; background: var(--surface); color: var(--text); border-radius: 12px; padding: 6px 8px;
border: 3px solid transparent; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; font-size: .88rem; animation: dm-in .35s ease both; }
.dm-seat.turn { border-color: var(--focus); }
.dm-seat.anim-glow { animation: anim-glow 1.4s ease-in-out infinite; }
.dm-seat.me { background: var(--primary-soft); }
.dm-seat.out { opacity: .7; }
.dm-seat .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
@@ -80,7 +128,6 @@ const CSS = `
.dm-prev .dm-card .nm { display: none; }
.dm-set { display: flex; }
.dm-set > .dm-card + .dm-card { margin-left: calc(var(--w) * -0.55); }
.dm-set.top { animation: dm-fly .3s ease-out; }
.dm-card { --w: 60px; position: relative; flex: none; width: var(--w); height: calc(var(--w) * 1.4); border-radius: calc(var(--w) * .13); background: #fffdf7; color: #1f2937;
border: 2px solid var(--c, #444); box-shadow: 0 2px 4px rgba(0,0,0,.28); display: flex; flex-direction: column; align-items: center; overflow: hidden; font-family: inherit; }
.dm-card .band { width: 100%; background: var(--c, #444); color: #fff; font-weight: 900; font-size: calc(var(--w) * .2); line-height: 1.35; text-align: left; padding-left: 4px; }
@@ -129,10 +176,9 @@ const CSS = `
.dm-flip { animation: dm-flip .7s ease both; }
@keyframes dm-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes dm-pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes dm-fly { from { transform: translateY(40px) scale(.85); opacity: .2; } to { transform: none; opacity: 1; } }
@keyframes dm-flip { from { transform: rotateY(180deg); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) {
.dm *, .dm-seat, .dm-set.top, .dm-rev, .dm-bubble, .dm-draw, .dm-flip { animation: none !important; transition: none !important; }
.dm *, .dm-seat, .dm-rev, .dm-bubble, .dm-draw, .dm-flip { animation: none !important; transition: none !important; }
}
@media (max-width: 719px) {
.dm { gap: 8px; }
@@ -195,7 +241,8 @@ function Seats({ v, players, me, deadline }: { v: DalmutiView; players: Record<s
return (
<li
key={s.id}
className={`dm-seat${s.isTurn && v.phase === 'playing' ? ' turn' : ''}${s.id === me ? ' me' : ''}${s.place ? ' out' : ''}`}
className={`dm-seat${s.isTurn && v.phase === 'playing' ? ' turn anim-glow' : ''}${s.id === me ? ' me' : ''}${s.place ? ' out' : ''}`}
data-fx-seat={s.id}
style={{ animationDelay: `${i * 40}ms` }}
aria-label={seatLabel(s, v, players, me)}
>
@@ -251,7 +298,7 @@ function TableArea({ v, players, me }: { v: DalmutiView; players: Record<string,
const leaderName = t.leader === me ? '내가' : `${nick(players, t.leader)}님이`;
const curName = v.current === me ? '내' : `${nick(players, v.current ?? '')}님`;
return (
<div className="dm-table" role="region" aria-label="바닥">
<div className="dm-table" data-fx="dm-center" role="region" aria-label="바닥">
{top ? (
<>
<div className="dm-now" aria-live="polite">
@@ -339,6 +386,7 @@ function PlayHand({ v, act, pending }: { v: DalmutiView; act: (a: unknown) => vo
setSel(null);
return;
}
sfx.select();
if (top) setSel({ rank: g.n, count: top.count, mix: ch.needsJester });
else setSel({ rank: g.n, count: ch.have, mix: false });
};
@@ -360,6 +408,7 @@ function PlayHand({ v, act, pending }: { v: DalmutiView; act: (a: unknown) => vo
};
const send = () => {
if (!ids || !legal) return;
rememberPlay(sel!.rank);
act({ type: 'play', cardIds: ids });
setSel(null);
};
@@ -374,7 +423,7 @@ function PlayHand({ v, act, pending }: { v: DalmutiView; act: (a: unknown) => vo
</strong>
{mine && <span className="small muted">{top ? `${setText(top)}보다 낮은 숫자를 골라요` : '낼 숫자를 골라요'}</span>}
</div>
<div className="dm-hand" role="group" aria-label="내 카드(숫자별). 좌우 방향키로 고르고 Enter로 선택해요" onKeyDown={(e) => onArrowKeys(e, 'button.dm-group')}>
<div className="dm-hand" data-fx="dm-hand" role="group" aria-label="내 카드(숫자별). 좌우 방향키로 고르고 Enter로 선택해요" onKeyDown={(e) => onArrowKeys(e, 'button.dm-group')}>
{groups.map((g) => {
const c = choice(g.n);
const picked = sel?.rank === g.n;
@@ -508,7 +557,7 @@ function RevolutionPanel({ v, players, me, act, pending }: { v: DalmutiView; pla
const my = v.my;
const done = v.seats.filter((s) => s.confirmed).length;
return (
<div className="dm-panel">
<div className="dm-panel" data-fx="dm-center">
<h3>
{v.round}라운드 준비 · 손패 확인 ({done}/{v.seats.length})
</h3>
@@ -553,11 +602,12 @@ function TaxPanel({ v, players, me, act, pending }: { v: DalmutiView; players: R
const subject = (id: string) => (id === me ? '내가' : `${nick(players, id)}님이`);
const toggle = (id: string) => {
if (!owe) return;
sfx.select();
if (picked.includes(id)) setPicked(picked.filter((x) => x !== id));
else setPicked(picked.length >= owe.count ? [...picked.slice(1), id] : [...picked, id]);
};
return (
<div className={`dm-panel${owe ? ' hot' : ''}`}>
<div className={`dm-panel${owe ? ' hot' : ''}`} data-fx="dm-center">
<h3>세금 카드 교환</h3>
<RoundRecap v={v} players={players} me={me} />
<ul style={{ margin: 0, paddingLeft: 20 }} aria-label="세금 내역">
@@ -685,6 +735,8 @@ function DalmutiBoard({ view: v, me, players, act, pending, deadline }: BoardPro
const mine = isMyTurn(v, me);
const prevMine = useRef(false);
const lastLog = v.log[v.log.length - 1];
const [banner, showBanner] = useBanner();
useDalmutiFx(v, me, players, showBanner);
useEffect(() => {
if (mine && !prevMine.current) {
haptic(40);
@@ -715,10 +767,101 @@ function DalmutiBoard({ view: v, me, players, act, pending, deadline }: BoardPro
<p className="sr-only" aria-live="polite">
{announce}
</p>
{banner}
</div>
);
}
const logKey = (e: LogEntry) => `${e.seq}-${e.t}-${'p' in e ? e.p : 'from' in e ? e.from : ''}`;
/** Sounds + motion for every change of the table, mine or anyone else's (log entries since the last view). */
function useDalmutiFx(v: DalmutiView, me: string | null, players: Record<string, PublicUser>, showBanner: ReturnType<typeof useBanner>[1]) {
const later = (ms: number, f: () => void) => (ms ? setTimeout(f, ms) : f());
const who = (id: string) => (id === me ? '나' : `${nick(players, id)}님`);
// A new round (or the very first deal): cards go from the middle to everyone.
const deal = (delay = 0) => {
const c = fxEl('dm-center');
later(delay, sfx.shuffle);
later(delay + 300, () => sfx.deal(6, 60));
document.querySelectorAll('.dm-hand .dm-group, .dm-hand .dm-one').forEach((el, i) => flyFrom(el, c, { delay: delay + 280 + i * 45, rotate: 10 }));
for (const s of v.seats) if (s.id !== me) flyGhost(c, seatEl(s.id), { count: 3, gap: 90, delay: delay + 280 });
};
useNewEntries(v.log, logKey, (fresh) => {
const lastPlay = [...fresh].reverse().find((e) => e.t === 'play');
let t = 0;
for (const e of fresh) {
const at = t;
switch (e.t) {
case 'play': {
if (e === lastPlay) {
const from = e.p === me ? (myPlayRect ?? fxEl('dm-hand')) : seatEl(e.p);
document.querySelectorAll('.dm-set.top .dm-card').forEach((el, i) => flyFrom(el, from, { delay: at + i * 60, ms: 340, rotate: -12 }));
}
if (e.p === me) myPlayRect = null;
later(at, () => dmSfx.set(e.count));
t += 150;
break;
}
case 'pass':
later(at, dmSfx.knock);
dim(seatEl(e.p));
t += 120;
break;
case 'trick':
// Everyone passed: the pile is swept to whoever leads next.
flyGhost(fxEl('dm-center'), seatEl(e.p), { count: 3, gap: 60, delay: at, ms: 420 });
later(at, sfx.whoosh);
later(at + 380, () => bump(seatEl(e.p)));
t += 200;
break;
case 'out':
showBanner(`${e.place}등!`, e.place === 1 ? 'gold' : 'green', e.p === me ? '손패를 다 냈어요' : `${nick(players, e.p)}님`);
later(at + 80, e.place === 1 ? sfx.fanfare : sfx.good);
bump(seatEl(e.p));
t += 250;
break;
case 'revolution': {
const great = e.kind === 'great';
showBanner(great ? '대혁명!' : '혁명!', great ? 'dark' : 'red', great ? `${who(e.p)} · 신분이 뒤집혀요` : `${who(e.p)} · 세금 없음`);
later(at, () => dmSfx.revolution(great));
t += 300;
break;
}
case 'tax':
case 'return':
flyGhost(seatEl(e.from), seatEl(e.to), { count: e.n, gap: 90, delay: at, ms: 520 });
later(at, e.t === 'tax' ? dmSfx.tax : dmSfx.give);
t += 350;
break;
case 'round':
// The next round's cards are dealt (not after the last round).
if (v.phase !== 'finished') {
deal(at + 500);
t += 1300;
}
break;
case 'timeout':
later(at, sfx.tick);
break;
default:
break;
}
}
});
const started = useRef(false);
useLayoutEffect(() => {
if (started.current) return;
started.current = true;
// Mounted right at the start of the game (nobody has done anything yet): show the deal once.
const fresh =
v.round === 1 &&
(v.phase === 'revolutionCheck'
? v.log.length === 0 && !v.seats.some((s) => s.confirmed)
: v.phase === 'taxReturn' && !v.options.revolution && v.log.every((e) => e.t === 'tax') && v.taxPending.every((p) => !p.done));
if (fresh) deal();
}, []); // eslint-disable-line react-hooks/exhaustive-deps
}
// ---------------------------------------------------------------- side
function rulesLine(o: DalmutiOptions): string {
@@ -729,7 +872,7 @@ function rulesLine(o: DalmutiOptions): string {
o.jesterTaxable ? '세금에 광대 포함' : '세금에 광대 빼기',
o.passLocksOut ? '패스하면 트릭에서 빠짐' : '패스해도 다시 낼 수 있음',
o.removeHighCards ? '9~12 빼기' : '',
`${o.turnSeconds}초`,
o.turnSeconds === null ? '시간 무제한' : `${o.turnSeconds}초`,
]
.filter(Boolean)
.join(' · ');
@@ -853,7 +996,7 @@ function statusText(v: DalmutiView, me: string | null, players: Record<string, P
// ---------------------------------------------------------------- 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]) => (
@@ -895,7 +1038,7 @@ function Options({ value: o, onChange }: OptionsProps<DalmutiOptions>) {
<Seg label="혁명 규칙" value={o.revolution} options={onOff} onChange={(revolution) => set({ revolution })} />
</Field>
<Field label="한 턴 제한 시간">
<Seg label="한 턴 제한 시간" value={o.turnSeconds} options={[[15, '15초'], [20, '20초'], [30, '30초'], [45, '45초']]} onChange={(turnSeconds) => set({ turnSeconds })} />
<Seg label="한 턴 제한 시간" value={o.turnSeconds} options={[[15, '15초'], [20, '20초'], [30, '30초'], [45, '45초'], [null, '무제한']]} onChange={(turnSeconds) => set({ turnSeconds })} />
</Field>
<button type="button" className="btn btn-ghost" onClick={() => setMore(!more)} aria-expanded={more}>
{more ? '▲ 자세한 설정 닫기' : '▼ 자세한 설정'}
@@ -926,7 +1069,7 @@ function optionsSummary(o: DalmutiOptions): string {
if (o.jesterTaxable) parts.push('세금에 광대');
if (o.passLocksOut) parts.push('패스하면 빠짐');
if (o.removeHighCards) parts.push('9~12 빼기');
parts.push(`${o.turnSeconds}초`);
parts.push(o.turnSeconds === null ? '시간 무제한' : `${o.turnSeconds}초`);
return parts.join(' · ');
}
@@ -990,7 +1133,10 @@ function Rules({ options }: { options?: DalmutiOptions }) {
라운드에서 1등은 (사람 수 − 1)점, 마지막 순위는 0점을 받아요. {o?.scoring === 'last-round' ? '이 방은 마지막 라운드 순위가 최종 순위예요.' : '총점이 높은 사람이 이기고, 같으면 마지막 라운드 순위로 정해요.'}{' '}
점수는 이 방 안에서만 쓰는 표시용이에요.
</p>
<p>시간 안에 고르지 않으면 새로 시작할 때는 가장 큰 숫자 카드를 모두 내고, 따라 낼 때는 패스해요.</p>
<p>
{o?.turnSeconds === null ? '이 방은 시간 제한이 없어요. 다만 연결이 끊긴 채 오래 돌아오지 않으면' : '시간 안에 고르지 않으면'} 새로 시작할 때는 가장 큰 숫자 카드를 모두 내고, 따라 낼 때는
패스해요.
</p>
<CardTable removeHigh={o?.removeHighCards} />
</div>
);