뱅!·고스톱·스플렌더·바퀴벌레 포커·구십구 소리·애니메이션, 게임 문서에 소리·움직임, E2E에서 무제한 확인

- 모두 view 변화(기록·이전 view 비교)에 반응해서 컴퓨터·다른 사람 행동에도 소리와 움직임이 나옴, 처음 렌더·다시 보기는 건너뜀
- 뱅!: 총소리·개틀링·인디언·결투·판정 카드·다이너마이트·감옥·맥주·쓰러짐 배너
- 고스톱: 패 내기 "탁", 뒤집기, 먹기, 피 뺏기, 뻑·따닥·쪽·싹쓸이·폭탄·흔들기 배너, N고, 판 끝(마지막 판 승패 소리는 결과 창 하나만)
- 스플렌더: 보석·카드·귀족이 날아가고 보석 소리, 마지막 라운드 배너
- 바퀴벌레 포커: 건네기·판정 배너·앞마당으로 날아감·위험 경고음
- 구십구: 카드가 합계 다이얼로, 90 이상 두근, 바로 99 배너, 방향 바뀜, 목숨·탈락
- E2E: 구십구·바퀴벌레 포커를 무제한으로 진행하고 타이머가 안 보이는지 확인

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:31:14 +09:00
parent ac37a6a6d8
commit 4fa4c69725
14 changed files with 1268 additions and 125 deletions

View File

@@ -1,11 +1,12 @@
/** 구십구 화면 (docs/games/ninety-nine.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 { CardFace, CardKind, ChoiceView, HandCardView, LogEntry, NNOptions, NinetyNineView, SeatView } from '@bg/games/ninety-nine';
import type { PublicUser } from '@bg/shared/lite';
import { Avatar } from '../../components/ui';
import { TurnTimer } from '../../components/TurnTimer';
import { PlayingCard } from '../../components/cards/PlayingCard';
import { haptic, sounds } from '../../lib/feedback';
import { haptic, noise, 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 { helpNow, resolvedHandSize } from './help';
@@ -148,6 +149,7 @@ const CSS = `
.nn-rules td, .nn-rules th { padding: 4px 6px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.nn-rules .nn-face { width: 34px; height: 48px; --cw: 34px; }
.nn-rules .nn-art::before { inset: 3px; }
.fx-ghost.nn-ghost { background: #fffdf7; color: #1f2937; border: 2px solid #334155; box-shadow: 0 3px 8px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; font: 900 13px/1 system-ui, sans-serif; }
@keyframes nn-pop { 0% { transform: scale(.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes nn-break { 0% { transform: scale(1); color: #e11d48; opacity: 1; } 40% { transform: scale(1.5) rotate(-15deg); } 100% { transform: scale(1); } }
/* PC/tablet: many players stack into even rows (9 → 5 + 4) instead of scrolling sideways. Phones keep one swipeable row. */
@@ -239,7 +241,7 @@ function SeatChip({ s, v, players, me, deadline }: { s: SeatView; v: NinetyNineV
const u = userOf(players, s.id);
const rank = v.result?.ranking.find((r) => r.player === s.id)?.rank;
return (
<li className={`nn-seat${s.isTurn ? ' turn' : ''}${s.alive ? '' : ' out'}`} aria-label={seatLabel(s, v, players, me)}>
<li className={`nn-seat${s.isTurn ? ' turn anim-glow' : ''}${s.alive ? '' : ' out'}`} data-fx-seat={s.id} aria-label={seatLabel(s, v, players, me)}>
<div className="row" style={{ gap: 6, flexWrap: 'nowrap' }}>
<Avatar user={u} size={24} />
<span className="nm">{u.nickname}</span>
@@ -287,12 +289,12 @@ function Table({ v, players, me, deadline }: { v: NinetyNineView; players: Recor
<TurnTimer deadline={deadline} totalMs={v.deadlineTotalMs} mine={cur === me} size={40} />
</span>
)}
<span className="nn-chip" aria-label={`뽑을 카드 ${v.drawPileCount}장`}>
<span className="nn-chip" data-fx="nn-deck" aria-label={`뽑을 카드 ${v.drawPileCount}장`}>
더미 {v.drawPileCount}장
</span>
{v.livesStart > 0 && <span className="nn-chip">{v.round}판째</span>}
</div>
<div className="nn-dial" role="img" aria-label={`지금 합계 ${v.total}`}>
<div className="nn-dial" data-fx="nn-dial" role="img" aria-label={`지금 합계 ${v.total}`}>
<svg viewBox="0 0 100 100" width="100%" height="100%" aria-hidden>
<circle cx="50" cy="50" r={r} fill="rgba(0,0,0,.28)" stroke="rgba(255,255,255,.18)" strokeWidth="8" />
<circle cx="50" cy="50" r={r} fill="none" stroke={gaugeColor(v.total)} strokeWidth="8" strokeLinecap="round" strokeDasharray={c} strokeDashoffset={c * (1 - frac)} />
@@ -396,8 +398,14 @@ function MyHand({ v, act, pending }: { v: NinetyNineView; act: (a: unknown) => v
setNote('');
}, [v.turnNo]);
const chosen = my.hand.find((c) => c.id === sel) ?? null;
// Cards that came to me (refill, a new round): fly in from the draw pile.
useNewEntries(my.hand, (c) => c.id, (fresh) => {
const deck = fxEl('nn-deck');
fresh.forEach((c, i) => flyFrom(document.querySelector(`.nn-card[data-id="${cssEsc(c.id)}"]`), deck, { delay: 120 + i * 70, rotate: 8 }));
}, 30);
const send = (c: HandCardView, extra: Record<string, unknown> = {}) => {
if (pending) return;
rememberPlay(c.id);
act({ type: 'play', cardId: c.id, ...extra });
setSel(null);
};
@@ -419,6 +427,7 @@ function MyHand({ v, act, pending }: { v: NinetyNineView; act: (a: unknown) => v
else setSel(null);
return;
}
sfx.select();
setSel(c.id);
};
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
@@ -449,7 +458,7 @@ function MyHand({ v, act, pending }: { v: NinetyNineView; act: (a: unknown) => v
</span>
)}
</div>
<div className="nn-hand" role="group" aria-label="내 카드. 좌우 방향키로 고르고 Enter로 고른 뒤 한 번 더 누르면 내요" onKeyDown={onKey} style={{ '--cw': cw } as CSSProperties}>
<div className="nn-hand" data-fx="nn-hand" role="group" aria-label="내 카드. 좌우 방향키로 고르고 Enter로 고른 뒤 한 번 더 누르면 내요" onKeyDown={onKey} style={{ '--cw': cw } as CSSProperties}>
{my.hand.map((c) => {
const p = previewOf(c);
return (
@@ -457,6 +466,7 @@ function MyHand({ v, act, pending }: { v: NinetyNineView; act: (a: unknown) => v
key={c.id}
type="button"
className="nn-card"
data-id={c.id}
data-legal={myTurn ? c.legal : undefined}
aria-pressed={sel === c.id}
aria-label={`${cardAria(c, myTurn)}${sel === c.id && myTurn && single(c) ? '. 한 번 더 누르면 내요' : ''}`}
@@ -559,6 +569,8 @@ function Board({ view: v, me, players, act, pending, deadline }: BoardProps<Nine
const others = myIdx < 0 ? v.seats : [...v.seats.slice(myIdx + 1), ...v.seats.slice(0, myIdx)];
const opps = useSeatRows<HTMLUListElement>(others.length);
const meSeat = v.seats.find((s) => s.id === me);
const [banner, showBanner] = useBanner();
useNinetyNineFx(v, me, players, showBanner);
return (
<div className="nn">
<style>{CSS}</style>
@@ -577,10 +589,145 @@ function Board({ view: v, me, players, act, pending, deadline }: BoardProps<Nine
<p className="sr-only" aria-live="polite">
{announce}
</p>
{banner}
</div>
);
}
// ---------------------------------------------------------------- sounds + motion (2026-10-13)
/** 구십구 sounds on top of the shared palette (synthesized, no files). */
const nnSfx = {
/** Direction flips: a rising then falling swoop. */
reverse: () => {
tone(420, 200, 'triangle', 0.09, 0, { slideTo: 880 });
tone(880, 200, 'triangle', 0.07, 150, { slideTo: 420 });
},
/** 홀드 / 0: a short "tock", nothing changes. */
hold: () => {
tone(600, 60, 'square', 0.04);
tone(600, 60, 'square', 0.04, 110);
},
/** Straight to 99: alarm-ish rising siren. */
to99: () => {
tone(330, 380, 'sawtooth', 0.05, 0, { slideTo: 990 });
tone(990, 160, 'square', 0.05, 380);
},
/** Total gets close to 99: a quick tense heartbeat. */
tense: () => {
tone(90, 120, 'sine', 0.2);
tone(80, 140, 'sine', 0.16, 180);
},
/** A life (heart) breaks. */
heart: () => {
noise(120, 0.1, 0, 'highpass', 2500);
tone(660, 300, 'triangle', 0.08, 40, { slideTo: 220 });
},
};
/** Where my last played card was (its button is gone once the view arrives), so the ghost starts there. */
let myPlayRect: DOMRect | null = null;
const rememberPlay = (id: string) => {
myPlayRect = document.querySelector(`.nn-card[data-id="${cssEsc(id)}"]`)?.getBoundingClientRect() ?? null;
};
const nnLogKey = (e: LogEntry) => `${e.seq}-${e.t}-${'p' in e ? e.p : ''}`;
/** Sounds + motion for every change of the table, mine or anyone else's (log entries since the last view). */
function useNinetyNineFx(v: NinetyNineView, me: string | null, players: Record<string, PublicUser>, showBanner: ReturnType<typeof useBanner>[1]) {
const later = (ms: number, f: () => void) => (ms > 0 ? setTimeout(f, ms) : f());
const who = (id: string) => (id === me ? '나' : `${nick(players, id)}님`);
const dealAll = (delay: number) => {
const deck = fxEl('nn-deck');
later(delay, sfx.shuffle);
later(delay + 300, () => sfx.deal(Math.min(8, v.seats.filter((s) => s.alive).length * 2), 60));
for (const s of v.seats) if (s.alive && s.id !== me) flyGhost(deck, seatEl(s.id), { count: 3, gap: 90, delay: delay + 280 });
};
useNewEntries(v.log, nnLogKey, (fresh) => {
let t = 0;
for (const e of fresh) {
const at = t;
switch (e.t) {
case 'play': {
const from = e.p === me ? (myPlayRect ?? fxEl('nn-hand')) : seatEl(e.p);
if (e.p === me) myPlayRect = null;
flyGhost(from, fxEl('nn-dial'), { delay: at, ms: 380, label: faceName(e.face), className: 'nn-ghost' });
later(at + 300, () => {
sfx.cardPlay();
// (a direction flip sounds from the direction change below)
if (e.kind === 'hold' || e.choice === '방향 그대로') nnSfx.hold();
if (e.kind === 'to99') nnSfx.to99();
else if (e.total >= 90 && e.total > e.from) nnSfx.tense();
});
if (e.kind === 'to99') later(at + 300, () => showBanner('99!', 'red', `${who(e.p)} 바로 99`));
// Refill: the player takes one card from the pile (mine flies in from MyHand).
if (v.options.refill && e.p !== me) flyGhost(fxEl('nn-deck'), seatEl(e.p), { delay: at + 420, ms: 380 });
t += 160;
break;
}
case 'noCard':
showBanner('낼 카드가 없어요!', 'red', who(e.p));
later(at, sfx.bad);
bump(seatEl(e.p), 'shake');
t += 200;
break;
case 'life':
later(at, nnSfx.heart);
bump(seatEl(e.p), 'shake');
t += 200;
break;
case 'out':
if (e.why === 'noCard') {
showBanner('탈락!', 'dark', who(e.p));
later(at + 120, sfx.bad);
}
t += 200;
break;
case 'round':
if (e.round > 1) {
dealAll(at + 400);
t += 900;
}
break;
case 'reshuffle':
later(at, sfx.shuffle);
bump(fxEl('nn-deck'), 'shake');
break;
case 'timeout':
later(at, sfx.tick);
break;
default:
break;
}
}
});
// The total jumps: the dial pops (shakes when it is close to 99).
useChange(v.total, (now, before) => {
if (now !== before) later(320, () => bump(fxEl('nn-dial'), now >= 90 ? 'shake' : 'pop'));
});
// Only a card flips it (a new round just resets it to clockwise, which the deal already covers).
const round = useRef(v.round);
useChange(v.direction, () => {
if (round.current !== v.round) return;
later(300, nnSfx.reverse);
bump(document.querySelector('.nn-dir b'));
});
useLayoutEffect(() => {
round.current = v.round;
});
// Mounted right at the start of the game (nothing played yet): show the deal once.
const started = useRef(false);
useLayoutEffect(() => {
if (started.current) return;
started.current = true;
if (v.phase === 'playing' && v.round === 1 && !v.log.some((e) => e.t === 'play')) {
dealAll(0);
const deck = fxEl('nn-deck');
document.querySelectorAll('.nn-hand .nn-card').forEach((el, i) => flyFrom(el, deck, { delay: 280 + i * 70, rotate: 10 }));
}
}, []); // eslint-disable-line react-hooks/exhaustive-deps
}
// ---------------------------------------------------------------- side
function rulesLine(o: NNOptions): string {