뱅!·고스톱·스플렌더·바퀴벌레 포커·구십구 소리·애니메이션, 게임 문서에 소리·움직임, E2E에서 무제한 확인
- 모두 view 변화(기록·이전 view 비교)에 반응해서 컴퓨터·다른 사람 행동에도 소리와 움직임이 나옴, 처음 렌더·다시 보기는 건너뜀 - 뱅!: 총소리·개틀링·인디언·결투·판정 카드·다이너마이트·감옥·맥주·쓰러짐 배너 - 고스톱: 패 내기 "탁", 뒤집기, 먹기, 피 뺏기, 뻑·따닥·쪽·싹쓸이·폭탄·흔들기 배너, N고, 판 끝(마지막 판 승패 소리는 결과 창 하나만) - 스플렌더: 보석·카드·귀족이 날아가고 보석 소리, 마지막 라운드 배너 - 바퀴벌레 포커: 건네기·판정 배너·앞마당으로 날아감·위험 경고음 - 구십구: 카드가 합계 다이얼로, 90 이상 두근, 바로 99 배너, 방향 바뀜, 목숨·탈락 - E2E: 구십구·바퀴벌레 포커를 무제한으로 진행하고 타이머가 안 보이는지 확인 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/** 뱅! 화면 (docs/games/bang.md §9). */
|
||||
import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import type { BangOptions, BangView, Card, CardFace, CardKind, CharacterId, LogEntry, PlayOption, PlayerView, Prompt, Role, Team } from '@bg/games/bang';
|
||||
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, type BannerTone } from '../card-fx';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -176,14 +177,91 @@ button.bg-card:focus-visible { outline: 3px solid var(--focus); outline-offset:
|
||||
.bg-me { padding: 8px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) { button.bg-card { transition: none; } }
|
||||
.fx-ghost.bg-ghost { background: #fffaf0; border: 2px solid #92400e; box-shadow: 0 3px 8px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center;
|
||||
font: 900 20px/1 system-ui, sans-serif; color: #1f2937; }
|
||||
.fx-ghost.bg-ghost.blue { border-color: #1d4ed8; }
|
||||
.fx-ghost.bg-ghost.chk { font-size: 14px; }
|
||||
.fx-ghost.bg-ghost.chk.r { color: #dc2626; }
|
||||
.fx-ghost.bg-ghost-back { background: repeating-linear-gradient(45deg, #7c2d12 0 5px, #9a3412 5px 10px); border: 2px solid #fdba74; box-shadow: 0 3px 8px rgba(0,0,0,.35); }
|
||||
.fx-ghost.bg-bullet { background: none; border: 0; box-shadow: none; font-size: 22px; }
|
||||
`;
|
||||
|
||||
// ---------------------------------------------------------------- sounds + motion helpers
|
||||
|
||||
/** 뱅! sounds on top of the shared palette (synthesized; `d` = delay in ms). */
|
||||
const shot = (d = 0) => {
|
||||
noise(110, 0.32, d, 'bandpass', 1700, 0.6);
|
||||
noise(40, 0.18, d, 'highpass', 4500);
|
||||
tone(95, 170, 'sine', 0.26, d, { slideTo: 45 });
|
||||
};
|
||||
const bangSfx = {
|
||||
shot,
|
||||
gatling: (d = 0) => {
|
||||
for (let i = 0; i < 7; i++) {
|
||||
noise(60, 0.22, d + i * 85, 'bandpass', 1600 + (i % 3) * 250, 0.7);
|
||||
tone(90, 80, 'sine', 0.15, d + i * 85, { slideTo: 50 });
|
||||
}
|
||||
},
|
||||
/** 빗나감! / 술통: a ricochet whistle. */
|
||||
ricochet: (d = 0) => {
|
||||
noise(30, 0.08, d, 'highpass', 5000);
|
||||
tone(2200, 300, 'sine', 0.07, d + 10, { slideTo: 700 });
|
||||
},
|
||||
hit: (d = 0) => {
|
||||
noise(90, 0.2, d, 'lowpass', 500, 0.8);
|
||||
tone(160, 200, 'sawtooth', 0.07, d, { slideTo: 70 });
|
||||
},
|
||||
/** Glug glug + clink. */
|
||||
beer: (d = 0) => {
|
||||
[0, 110, 220].forEach((x, i) => tone(240 - i * 25, 80, 'sine', 0.14, d + x, { slideTo: 150 }));
|
||||
tone(2600, 140, 'triangle', 0.05, d + 340);
|
||||
tone(3300, 120, 'triangle', 0.04, d + 360);
|
||||
},
|
||||
boom: (d = 0) => {
|
||||
noise(900, 0.42, d, 'lowpass', 380, 0.7);
|
||||
noise(120, 0.22, d, 'bandpass', 1200, 0.5);
|
||||
tone(70, 800, 'sine', 0.3, d, { slideTo: 28 });
|
||||
},
|
||||
/** Jail bars. */
|
||||
clank: (d = 0) => {
|
||||
tone(330, 180, 'square', 0.05, d);
|
||||
tone(495, 220, 'square', 0.04, d + 30);
|
||||
noise(70, 0.14, d, 'bandpass', 4200, 3);
|
||||
},
|
||||
drums: (d = 0) =>
|
||||
[0, 170, 340, 430, 520].forEach((x) => {
|
||||
tone(120, 130, 'sine', 0.26, d + x, { slideTo: 65 });
|
||||
noise(50, 0.08, d + x, 'lowpass', 320);
|
||||
}),
|
||||
duel: (d = 0) => {
|
||||
shot(d);
|
||||
shot(d + 340);
|
||||
},
|
||||
death: (d = 0) => tone(440, 750, 'triangle', 0.12, d, { slideTo: 100 }),
|
||||
};
|
||||
|
||||
/** 판정 card / role badge turning face up (Web Animations, no layout change). */
|
||||
function flip(el: Element | null | undefined, delay = 0): void {
|
||||
if (!el || reducedMotion() || typeof (el as HTMLElement).animate !== 'function') return;
|
||||
(el as HTMLElement).animate([{ transform: 'perspective(500px) rotateX(90deg)', opacity: 0.3 }, { transform: 'perspective(500px) rotateX(0deg)', opacity: 1 }], {
|
||||
duration: 380,
|
||||
delay,
|
||||
easing: 'ease-out',
|
||||
fill: 'backwards',
|
||||
composite: 'add',
|
||||
});
|
||||
}
|
||||
|
||||
const sameFace = (a: CardFace, b: CardFace) => a.kind === b.kind && a.suit === b.suit && a.rank === b.rank;
|
||||
const faceGhost = (f: CardFace) => ({ label: CARD_INFO[f.kind].icon, className: `bg-ghost${BLUE.includes(f.kind) ? ' blue' : ''}` });
|
||||
const BACK_GHOST = { className: 'bg-ghost-back' };
|
||||
|
||||
// ---------------------------------------------------------------- small parts
|
||||
|
||||
function CardArt({ card, small, label }: { card: CardFace; small?: boolean; label?: boolean }) {
|
||||
function CardArt({ card, small, label, fx }: { card: CardFace; small?: boolean; label?: boolean; fx?: string }) {
|
||||
const info = CARD_INFO[card.kind];
|
||||
return (
|
||||
<span className={`bg-card${small ? ' sm' : ''}`} data-blue={BLUE.includes(card.kind)} aria-hidden={!label} {...(label ? { role: 'img', 'aria-label': faceAria(card) } : {})}>
|
||||
<span className={`bg-card${small ? ' sm' : ''}`} data-fx={fx} data-blue={BLUE.includes(card.kind)} aria-hidden={!label} {...(label ? { role: 'img', 'aria-label': faceAria(card) } : {})}>
|
||||
<CardFaceInner card={card} info={info} />
|
||||
</span>
|
||||
);
|
||||
@@ -300,7 +378,7 @@ function Seat({
|
||||
) : p.isTurn && !v.reactions.length && !v.winner ? (
|
||||
<TurnTimer deadline={v.turnDeadline} totalMs={v.deadlineTotalMs} mine={p.id === me} size={26} />
|
||||
) : null;
|
||||
const cls = `bg-seat${p.isTurn ? ' turn' : ''}${r ? ' react' : ''}${p.id === me ? ' me' : ''}${!p.alive ? ' dead' : ''}`;
|
||||
const cls = `bg-seat${p.isTurn ? ` turn${v.winner ? '' : ' anim-glow'}` : ''}${r ? ' react' : ''}${p.id === me ? ' me' : ''}${!p.alive ? ' dead' : ''}`;
|
||||
const body = (
|
||||
<>
|
||||
<span className="bg-row nw">
|
||||
@@ -347,6 +425,7 @@ function Seat({
|
||||
style={style}
|
||||
data-target="ok"
|
||||
data-player={p.id}
|
||||
data-fx-seat={p.id}
|
||||
aria-pressed={mark.selected}
|
||||
aria-label={`${seatLabel(p, players, me, shownRole(p, v, me))}. 대상으로 고르기`}
|
||||
onClick={() => onPick(p.id)}
|
||||
@@ -356,7 +435,7 @@ function Seat({
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={cls} style={style} data-target={mark ? 'no' : undefined} data-player={p.id} role="group" aria-label={seatLabel(p, players, me, shownRole(p, v, me)) + (mark?.reason ? `. ${mark.reason}` : '')}>
|
||||
<div className={cls} style={style} data-target={mark ? 'no' : undefined} data-player={p.id} data-fx-seat={p.id} role="group" aria-label={seatLabel(p, players, me, shownRole(p, v, me)) + (mark?.reason ? `. ${mark.reason}` : '')}>
|
||||
{body}
|
||||
</div>
|
||||
);
|
||||
@@ -379,15 +458,15 @@ function Center({ v, players }: { v: BangView; players: Record<string, PublicUse
|
||||
const last = v.log[v.log.length - 1];
|
||||
return (
|
||||
<div className="bg-center">
|
||||
<div className="bg-piles">
|
||||
<span className="bg-back" role="img" aria-label={`카드 더미 ${v.deckCount}장`}>
|
||||
<div className="bg-piles" data-fx="bang-piles">
|
||||
<span className="bg-back" data-fx="bang-deck" role="img" aria-label={`카드 더미 ${v.deckCount}장`}>
|
||||
{v.deckCount}
|
||||
</span>
|
||||
{top ? <CardArt card={top} small label /> : <span className="bg-chip">버린 카드 없음</span>}
|
||||
{top ? <CardArt card={top} small label fx="bang-discard" /> : <span className="bg-chip" data-fx="bang-discard">버린 카드 없음</span>}
|
||||
</div>
|
||||
{v.phase !== 'draft' && <span className="bg-chip">{v.round}라운드</span>}
|
||||
{chk && (
|
||||
<span className={`bg-chip ${chk.success ? 'ok' : 'bad'}`} aria-live="polite">
|
||||
<span className={`bg-chip ${chk.success ? 'ok' : 'bad'}`} data-fx="bang-check" aria-live="polite">
|
||||
{nick(players, chk.player)}님 {PURPOSE[chk.purpose]} 판정: {chk.cards.map((c) => `${SUIT_SYMBOL[c.suit]}${c.rank}`).join(' · ')} → {chk.success ? '성공' : '실패'}
|
||||
</span>
|
||||
)}
|
||||
@@ -474,12 +553,14 @@ function HandCards({
|
||||
picked,
|
||||
onTap,
|
||||
label,
|
||||
fx,
|
||||
}: {
|
||||
hand: Card[];
|
||||
okOf?: (c: Card) => boolean | undefined;
|
||||
picked: (c: Card) => boolean;
|
||||
onTap: (c: Card) => void;
|
||||
label: string;
|
||||
fx?: string;
|
||||
}) {
|
||||
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
||||
@@ -490,7 +571,7 @@ function HandCards({
|
||||
btns[(i + (e.key === 'ArrowRight' ? 1 : btns.length - 1)) % btns.length]?.focus();
|
||||
};
|
||||
return (
|
||||
<div className="bg-hand" role="group" aria-label={label} onKeyDown={onKey}>
|
||||
<div className="bg-hand" data-fx={fx} role="group" aria-label={label} onKeyDown={onKey}>
|
||||
{hand.map((c) => {
|
||||
const ok = okOf?.(c);
|
||||
return (
|
||||
@@ -595,7 +676,7 @@ function MyArea({
|
||||
|
||||
return (
|
||||
<section className="bg-me" aria-label="내 자리">
|
||||
<div className="bg-mehead">
|
||||
<div className="bg-mehead" data-fx="bang-me">
|
||||
<RoleCard role={my.role} hints={hints} always={!!v.winner || !meP?.alive} />
|
||||
<span className="stack" style={{ gap: 2, flex: '1 1 220px', minWidth: 0 }}>
|
||||
<strong>
|
||||
@@ -619,6 +700,7 @@ function MyArea({
|
||||
{prompt?.kind === 'draw' && <DrawPanel prompt={prompt} act={act} pending={pending} players={players} />}
|
||||
{meP?.alive && (
|
||||
<HandCards
|
||||
fx="bang-hand"
|
||||
hand={my.hand}
|
||||
label={`내 카드 ${my.hand.length}장. 좌우 방향키로 고르고 Enter로 눌러요`}
|
||||
okOf={(c) => (discarding || sidMode ? undefined : playing ? !!optOf(c.id)?.ok : undefined)}
|
||||
@@ -974,6 +1056,8 @@ function BangBoard({ view: v, me, players, act, pending }: BoardProps<BangView>)
|
||||
useEffect(() => {
|
||||
if (last && !mine) setAnnounce(logText(last, players));
|
||||
}, [last?.seq, last?.t]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const [banner, showBanner] = useBanner();
|
||||
useBangFx(v, me, players, showBanner);
|
||||
|
||||
const n = v.players.length;
|
||||
const myIdx = v.players.findIndex((p) => p.id === me);
|
||||
@@ -1018,10 +1102,313 @@ function BangBoard({ view: v, me, players, act, pending }: BoardProps<BangView>)
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
{banner}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const TEAM_TONE: Record<Team, BannerTone> = { law: 'blue', outlaws: 'red', renegade: 'gold' };
|
||||
|
||||
/**
|
||||
* Sounds + motion for every change of the table, mine or anyone else's: the log entries that are new since the last
|
||||
* view (never on the first render, so joining / reloading / a replay jump stays quiet).
|
||||
*/
|
||||
function useBangFx(v: BangView, me: string | null, players: Record<string, PublicUser>, showBanner: (text: string, tone?: BannerTone, sub?: string) => void) {
|
||||
// Entries of one action share `seq`; count repeats (two 판정 cards, Black Jack's two draws) so every key is unique.
|
||||
const keyed = useMemo(() => {
|
||||
const seen = new Map<string, number>();
|
||||
return v.log.map((e) => {
|
||||
const base = `${e.seq}-${e.t}-${'p' in e ? e.p : ''}`;
|
||||
const i = seen.get(base) ?? 0;
|
||||
seen.set(base, i + 1);
|
||||
return { e, k: `${base}-${i}` };
|
||||
});
|
||||
}, [v.log]);
|
||||
/** Last known place of my hand cards: a card I played is gone from the DOM once the view arrives. */
|
||||
const handRects = useRef(new Map<string, { r: DOMRect; f: CardFace }>());
|
||||
/** Where my next new hand cards come from (deck by default) and when. */
|
||||
const handSrc = useRef<{ from: Element | DOMRect | null; at: number } | null>(null);
|
||||
|
||||
const visible = (el: Element | null) => (el && el.getBoundingClientRect().width > 0 ? el : null);
|
||||
/** A player's seat; my own seat is hidden on phones, so my area stands in for it. */
|
||||
const place = (id: string): Element | null => visible(seatEl(id)) ?? (id === me ? fxEl('bang-me') : null);
|
||||
/** Where a card I (or someone) just used came from. */
|
||||
const srcOf = (id: string, f?: CardFace): Element | DOMRect | null => {
|
||||
if (id === me && f) {
|
||||
const hand = new Set(v.my?.hand.map((c) => c.id) ?? []);
|
||||
for (const [cid, x] of handRects.current) {
|
||||
if (hand.has(cid) || !sameFace(x.f, f)) continue;
|
||||
handRects.current.delete(cid);
|
||||
return x.r;
|
||||
}
|
||||
}
|
||||
return place(id);
|
||||
};
|
||||
const name = (id: string) => `${nick(players, id)}님`;
|
||||
|
||||
useNewEntries(
|
||||
keyed,
|
||||
(x) => x.k,
|
||||
(fresh) => {
|
||||
const deck = fxEl('bang-deck');
|
||||
const pile = fxEl('bang-discard') ?? deck;
|
||||
const piles = fxEl('bang-piles');
|
||||
const later = (ms: number, f: () => void) => (ms > 0 ? setTimeout(f, ms) : f());
|
||||
const toPile = (from: Element | DOMRect | null, f: CardFace | null, delay: number) => flyGhost(from, pile, { delay, ms: 420, ...(f ? faceGhost(f) : BACK_GHOST) });
|
||||
const toMe = (from: Element | null, at: number) => (handSrc.current = { from, at });
|
||||
const others = (p: string) => v.players.filter((x) => x.alive && x.id !== p).map((x) => x.id);
|
||||
let healed = false;
|
||||
let t = 0;
|
||||
for (const { e } of fresh) {
|
||||
const at = Math.min(t, 3000);
|
||||
switch (e.t) {
|
||||
case 'play': {
|
||||
const k = e.as ?? e.card.kind;
|
||||
toPile(srcOf(e.p, e.card), e.card, at);
|
||||
later(at, sfx.cardPlay);
|
||||
if (k === 'bang' && e.target) {
|
||||
const tg = e.target;
|
||||
flyGhost(place(e.p), place(tg), { kind: 'coin', label: '💥', className: 'bg-bullet', ms: 260, delay: at + 100 });
|
||||
bangSfx.shot(at + 100);
|
||||
later(at + 340, () => bump(place(tg), 'shake'));
|
||||
if (tg === me) later(at, () => showBanner('뱅!', 'red', `${name(e.p)}이 쐈어요`));
|
||||
t += 450;
|
||||
} else if (k === 'gatling') {
|
||||
bangSfx.gatling(at + 80);
|
||||
later(at, () => showBanner('개틀링!', 'red', name(e.p)));
|
||||
others(e.p).forEach((id, i) => later(at + 200 + i * 85, () => bump(place(id), 'shake')));
|
||||
t += 750;
|
||||
} else if (k === 'indians') {
|
||||
bangSfx.drums(at + 60);
|
||||
later(at, () => showBanner('인디언!', 'gold', name(e.p)));
|
||||
others(e.p).forEach((id, i) => later(at + 150 + i * 90, () => bump(place(id))));
|
||||
t += 650;
|
||||
} else if (k === 'duel') {
|
||||
bangSfx.duel(at + 80);
|
||||
if (e.target && (e.p === me || e.target === me)) later(at, () => showBanner('결투!', 'dark', `${name(e.p)} vs ${name(e.target!)}`));
|
||||
if (e.target) later(at + 120, () => bump(place(e.target!)));
|
||||
t += 650;
|
||||
} else if (k === 'generalStore') {
|
||||
later(at + 100, sfx.shuffle);
|
||||
t += 300;
|
||||
} else if (k === 'panic' || k === 'catBalou') {
|
||||
later(at + 100, sfx.whoosh);
|
||||
t += 250;
|
||||
} else t += 200;
|
||||
break;
|
||||
}
|
||||
case 'equip': {
|
||||
const to = e.target ?? e.p;
|
||||
flyGhost(srcOf(e.p, e.card), place(to), { delay: at, ms: 420, ...faceGhost(e.card) });
|
||||
later(at, sfx.cardPlay);
|
||||
if (e.card.kind === 'jail') {
|
||||
bangSfx.clank(at + 400);
|
||||
later(at + 400, () => bump(place(to), 'shake'));
|
||||
} else later(at + 400, () => bump(place(to)));
|
||||
if (e.replaced) toPile(place(to), e.replaced, at + 300);
|
||||
t += 400;
|
||||
break;
|
||||
}
|
||||
case 'check': {
|
||||
e.cards.forEach((c, i) => {
|
||||
flyGhost(deck, pile, { delay: at + i * 220, ms: 380, label: `${SUIT_SYMBOL[c.suit]}${c.rank}`, className: `bg-ghost chk${sr(c) === 'r' ? ' r' : ''}` });
|
||||
later(at + i * 220, sfx.cardFlip);
|
||||
});
|
||||
const end = at + 300 + (e.cards.length - 1) * 220;
|
||||
flip(fxEl('bang-check'), end);
|
||||
later(end + 80, e.success ? sfx.good : sfx.bad);
|
||||
t += 450 + (e.cards.length - 1) * 220;
|
||||
break;
|
||||
}
|
||||
case 'dynamite':
|
||||
if (e.exploded) {
|
||||
bangSfx.boom(at);
|
||||
later(at, () => {
|
||||
showBanner('펑!', 'dark', `${name(e.p)} 앞에서 다이너마이트가 터졌어요`);
|
||||
bump(place(e.p), 'shake');
|
||||
});
|
||||
t += 700;
|
||||
} else if (e.to) {
|
||||
flyGhost(place(e.p), place(e.to), { delay: at, ms: 420, label: '🧨', className: 'bg-ghost blue' });
|
||||
later(at, sfx.whoosh);
|
||||
t += 400;
|
||||
}
|
||||
break;
|
||||
case 'jail':
|
||||
flyGhost(place(e.p), pile, { delay: at + 200, ms: 400, label: '🔒', className: 'bg-ghost blue' });
|
||||
if (e.escaped) {
|
||||
later(at, () => {
|
||||
sfx.good();
|
||||
bump(place(e.p));
|
||||
});
|
||||
} else {
|
||||
bangSfx.clank(at);
|
||||
later(at, () => bump(place(e.p), 'shake'));
|
||||
if (e.p === me) later(at, () => showBanner('감옥!', 'dark', '이번 턴을 쉬어요'));
|
||||
}
|
||||
t += 450;
|
||||
break;
|
||||
case 'missed':
|
||||
e.cards.forEach((c, i) => toPile(srcOf(e.p, c), c, at + i * 80));
|
||||
bangSfx.ricochet(at);
|
||||
later(at, () => bump(place(e.p)));
|
||||
t += 350;
|
||||
break;
|
||||
case 'barrelSave':
|
||||
bangSfx.ricochet(at);
|
||||
later(at, () => bump(place(e.p)));
|
||||
t += 300;
|
||||
break;
|
||||
case 'respond':
|
||||
e.cards.forEach((c) => toPile(srcOf(e.p, c), c, at));
|
||||
if (e.why === 'duel') bangSfx.shot(at + 80);
|
||||
else later(at, sfx.cardPlay);
|
||||
t += 350;
|
||||
break;
|
||||
case 'hit':
|
||||
bangSfx.hit(at);
|
||||
later(at, () => {
|
||||
bump(place(e.p), 'shake');
|
||||
if (e.p === me) haptic([40, 40, 40]);
|
||||
});
|
||||
t += 350;
|
||||
break;
|
||||
case 'heal':
|
||||
e.cards?.forEach((c) => toPile(srcOf(e.p, c), c, at));
|
||||
if (!healed) bangSfx.beer(at);
|
||||
healed = healed || e.why === 'saloon';
|
||||
later(at + 200, () => bump(place(e.p)));
|
||||
t += e.why === 'saloon' ? 60 : 400;
|
||||
break;
|
||||
case 'draw': {
|
||||
const n = Math.min(e.n, 6);
|
||||
if (e.p === me) toMe(deck, at);
|
||||
else flyGhost(deck, place(e.p), { count: n, gap: 80, delay: at, ...BACK_GHOST });
|
||||
later(at, () => sfx.draw(Math.min(n, 4)));
|
||||
t += 120 + 80 * Math.min(n, 4);
|
||||
break;
|
||||
}
|
||||
case 'blackJack':
|
||||
later(at, sfx.cardFlip);
|
||||
if (e.extra) later(at + 150, () => {
|
||||
sfx.good();
|
||||
bump(place(e.p));
|
||||
});
|
||||
t += 250;
|
||||
break;
|
||||
case 'pedro':
|
||||
if (e.p === me) toMe(pile, at);
|
||||
else flyGhost(pile, place(e.p), { delay: at, ms: 420, ...faceGhost(e.card) });
|
||||
later(at, () => sfx.cardDeal());
|
||||
t += 250;
|
||||
break;
|
||||
case 'take':
|
||||
if (e.p === me) toMe(place(e.from), at);
|
||||
else flyGhost(place(e.from), place(e.p), { delay: at, ms: 420, ...(e.equip ? faceGhost(e.equip) : e.card ? faceGhost(e.card) : BACK_GHOST) });
|
||||
later(at, sfx.whoosh);
|
||||
t += 300;
|
||||
break;
|
||||
case 'discarded':
|
||||
toPile(place(e.p), e.card, at);
|
||||
later(at, () => {
|
||||
sfx.whoosh();
|
||||
bump(place(e.p), 'shake');
|
||||
});
|
||||
t += 300;
|
||||
break;
|
||||
case 'limit':
|
||||
e.cards.forEach((c, i) => toPile(srcOf(e.p, c), c, at + i * 70));
|
||||
later(at, () => sfx.deal(Math.min(e.cards.length, 4)));
|
||||
t += 250;
|
||||
break;
|
||||
case 'store':
|
||||
if (e.p === me) toMe(piles, at);
|
||||
else flyGhost(piles, place(e.p), { delay: at, ms: 420, ...faceGhost(e.card) });
|
||||
later(at, () => sfx.cardDeal());
|
||||
t += 250;
|
||||
break;
|
||||
case 'storeOpen':
|
||||
later(at, () => sfx.deal(Math.min(e.cards.length, 7)));
|
||||
later(at, () => bump(piles));
|
||||
t += 300;
|
||||
break;
|
||||
case 'dead': {
|
||||
const role = ROLE_INFO[e.role];
|
||||
bangSfx.death(at);
|
||||
later(at, () => {
|
||||
showBanner(e.left ? `${name(e.p)} 탈락` : `${name(e.p)} 쓰러짐`, 'dark', `${role.icon} ${role.name}였어요`);
|
||||
bump(place(e.p), 'shake');
|
||||
});
|
||||
flip(place(e.p)?.querySelector('.bg-role'), at + 200);
|
||||
t += 900;
|
||||
break;
|
||||
}
|
||||
case 'reward':
|
||||
later(at, sfx.collect);
|
||||
t += 150;
|
||||
break;
|
||||
case 'penalty':
|
||||
toPile(place(e.p), null, at);
|
||||
later(at, sfx.bad);
|
||||
t += 250;
|
||||
break;
|
||||
case 'vulture':
|
||||
if (e.p === me) toMe(place(e.from), at);
|
||||
else flyGhost(place(e.from), place(e.p), { count: Math.min(e.n, 6), gap: 70, delay: at, ...BACK_GHOST });
|
||||
later(at, sfx.collect);
|
||||
t += 350;
|
||||
break;
|
||||
case 'character':
|
||||
later(at, sfx.select);
|
||||
break;
|
||||
case 'turn':
|
||||
later(at, () => bump(place(e.p)));
|
||||
t += 100;
|
||||
break;
|
||||
case 'timeout':
|
||||
later(at, sfx.tick);
|
||||
break;
|
||||
case 'reshuffle':
|
||||
later(at, () => {
|
||||
sfx.shuffle();
|
||||
bump(deck, 'shake');
|
||||
});
|
||||
t += 300;
|
||||
break;
|
||||
case 'end':
|
||||
// The room already plays the win / lose sound.
|
||||
later(at + 300, () => showBanner(`${TEAM_KO[e.winner]} 승리!`, TEAM_TONE[e.winner]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
30,
|
||||
);
|
||||
|
||||
// New cards in my hand fly in from wherever they came from (deck, discard pile, another seat, the store).
|
||||
useNewEntries(
|
||||
v.my?.hand,
|
||||
(c) => c.id,
|
||||
(fresh) => {
|
||||
const src = handSrc.current ?? { from: fxEl('bang-deck'), at: 0 };
|
||||
fresh.forEach((c, i) =>
|
||||
flyFrom(document.querySelector(`[data-fx="bang-hand"] [data-id="${cssEsc(c.id)}"]`), src.from, { delay: Math.min(src.at, 3000) + i * 70, rotate: 8 }),
|
||||
);
|
||||
},
|
||||
20,
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
handSrc.current = null;
|
||||
const m = new Map<string, { r: DOMRect; f: CardFace }>();
|
||||
for (const c of v.my?.hand ?? []) {
|
||||
const el = document.querySelector(`[data-fx="bang-hand"] [data-id="${cssEsc(c.id)}"]`);
|
||||
if (el) m.set(c.id, { r: el.getBoundingClientRect(), f: c });
|
||||
}
|
||||
handRects.current = m;
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- side
|
||||
|
||||
function BangSide({ view: v, me, players }: BoardProps<BangView>) {
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { ClaimEntry, CockroachOptions, CockroachView, FrontView, Kind, Last
|
||||
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, flyGhost, seatEl, useBanner } from '../card-fx';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -213,6 +214,7 @@ const CSS = `
|
||||
.cp-seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
|
||||
.cp-seat { position: relative; background: var(--surface); border-radius: var(--radius-lg); padding: 9px 11px; box-shadow: var(--shadow); border: 3px solid transparent; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
||||
.cp-seat.turn { border-color: var(--focus); }
|
||||
.fx-ghost.cp-ghost { background: linear-gradient(135deg, #7c2d12, #431407); border: 2px solid #fdba74; border-radius: 7px; box-shadow: 0 3px 8px rgba(0,0,0,.35); }
|
||||
.cp-seat.loser { border-color: var(--danger); }
|
||||
.cp-head { display: flex; align-items: center; gap: 7px; min-height: 30px; min-width: 0; }
|
||||
.cp-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
|
||||
@@ -354,7 +356,7 @@ function Seat({ id, v, me, players, deadline, bubble }: { id: string; v: Cockroa
|
||||
const role = v.phase === 'finished' ? null : r.holder === id ? (r.peeked ? '넘기는 중' : '받는 중') : r.holder === null && r.starter === id ? '건네는 중' : null;
|
||||
const label = `${u.nickname}님${id === me ? '(나)' : ''}: 손패 ${v.handCounts[id]}장, ${frontText(front, v.loseCount)}${role ? `, ${role}` : ''}${r.seen.includes(id) && r.holder !== null ? ', 이 카드를 봤어요' : ''}${v.away[id] ? ', 자리 비움' : ''}`;
|
||||
return (
|
||||
<section className={`cp-seat${active ? ' turn' : ''}${loser ? ' loser' : ''}`} aria-label={label}>
|
||||
<section className={`cp-seat${active ? ' turn anim-glow' : ''}${loser ? ' loser' : ''}`} data-fx-seat={id} aria-label={label}>
|
||||
{bubble && (
|
||||
<span className="cp-bubble" aria-hidden>
|
||||
{bubble}
|
||||
@@ -705,7 +707,7 @@ function MyArea({
|
||||
const active = waitingOn(v) === me;
|
||||
const total = v.handCounts[me] ?? 0;
|
||||
return (
|
||||
<section className={`cp-me${active ? ' turn' : ''}`} aria-label="내 자리">
|
||||
<section className={`cp-me${active ? ' turn anim-glow' : ''}`} data-fx-seat={me} aria-label="내 자리">
|
||||
{bubble && (
|
||||
<span className="cp-bubble" aria-hidden>
|
||||
{bubble}
|
||||
@@ -752,7 +754,15 @@ function CockroachBoard({ view: v, me, players, act, pending, deadline }: BoardP
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const [bubbles, setBubbles] = useState<Record<string, string>>({});
|
||||
const [fresh, setFresh] = useState({ slide: false, flip: false });
|
||||
const prev = useRef({ claims: v.round.claims.length + v.round.no * 100, reveal: v.lastReveal?.round ?? 0, said: v.said[v.said.length - 1]?.seq ?? 0, waiting: waitingOn(v) });
|
||||
const [banner, showBanner] = useBanner();
|
||||
const prev = useRef({
|
||||
claims: v.round.claims.length + v.round.no * 100,
|
||||
reveal: v.lastReveal?.round ?? 0,
|
||||
said: v.said[v.said.length - 1]?.seq ?? 0,
|
||||
waiting: waitingOn(v),
|
||||
peek: `${v.round.no}:${v.round.seen.length}`,
|
||||
over: v.phase === 'finished',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const p = prev.current;
|
||||
@@ -763,6 +773,37 @@ function CockroachBoard({ view: v, me, players, act, pending, deadline }: BoardP
|
||||
let msg = '';
|
||||
const slide = claimsKey !== p.claims && v.round.holder !== null;
|
||||
const flip = revealKey !== p.reveal && !!v.lastReveal;
|
||||
const peekKey = `${v.round.no}:${v.round.seen.length}`;
|
||||
const over = v.phase === 'finished';
|
||||
// Sounds + motion (2026-10-13): the same diff drives everyone's moves, so other players' and computers' moves show too.
|
||||
if (slide && v.round.lastPasser && v.round.holder) {
|
||||
flyGhost(seatEl(v.round.lastPasser), seatEl(v.round.holder), { ms: 460, className: 'cp-ghost' });
|
||||
sfx.cardDeal();
|
||||
cpSfx.sneak(80);
|
||||
} else if (!flip && peekKey !== p.peek && v.round.peeked) {
|
||||
sfx.cardFlip(); // someone takes a secret look before passing on
|
||||
}
|
||||
if (flip) {
|
||||
const rv = v.lastReveal!;
|
||||
sfx.cardFlip();
|
||||
setTimeout(() => (rv.correct ? sfx.good() : cpSfx.wrong()), 260);
|
||||
showBanner(rv.call === 'true' ? '진짜!' : '거짓말!', rv.correct ? 'green' : 'red', `${rv.caller === me ? '내가' : `${nick(players, rv.caller)}님이`} ${rv.correct ? '맞혔어요' : '틀렸어요'}`);
|
||||
flyGhost(document.querySelector('.cp-table'), seatEl(rv.takenBy), { delay: 380, ms: 480, className: 'cp-ghost' });
|
||||
setTimeout(() => {
|
||||
bump(seatEl(rv.takenBy), 'shake');
|
||||
const n = v.fronts[rv.takenBy]?.counts[rv.kind] ?? 0;
|
||||
if (!over && n >= v.loseCount - 1) cpSfx.danger();
|
||||
else cpSfx.splat();
|
||||
}, 820);
|
||||
}
|
||||
if (over && !p.over && v.final) {
|
||||
const f = v.final;
|
||||
setTimeout(() => {
|
||||
showBanner(`${f.loser === me ? '내가' : `${nick(players, f.loser)}님`} 패배!`, 'dark', f.losingKind ? `${KIND_KO[f.losingKind]}${hasBatchim(KIND_KO[f.losingKind]) ? '이' : '가'} 너무 많아요` : undefined);
|
||||
cpSfx.danger();
|
||||
bump(seatEl(f.loser), 'shake');
|
||||
}, flip ? 1300 : 0);
|
||||
}
|
||||
if (flip) {
|
||||
const rv = v.lastReveal!;
|
||||
msg = `${nick(players, rv.caller)}님이 ${rv.call === 'true' ? '진짜라고' : '거짓말이라고'} 했고 ${rv.correct ? '맞혔어요' : '틀렸어요'}. ${kj(rv.kind, '은', '는')} ${nick(players, rv.takenBy)}님 앞마당으로 갔어요.`;
|
||||
@@ -779,10 +820,11 @@ function CockroachBoard({ view: v, me, players, act, pending, deadline }: BoardP
|
||||
if (lastSaid > p.said) {
|
||||
const add: Record<string, string> = {};
|
||||
for (const s of v.said) if (s.seq > p.said) add[s.player] = PHRASE_KO[s.phrase];
|
||||
sfx.pop();
|
||||
setBubbles((b) => ({ ...b, ...add }));
|
||||
setTimeout(() => setBubbles((b) => Object.fromEntries(Object.entries(b).filter(([k]) => !(k in add)))), 3500);
|
||||
}
|
||||
prev.current = { claims: claimsKey, reveal: revealKey, said: lastSaid, waiting: w };
|
||||
prev.current = { claims: claimsKey, reveal: revealKey, said: lastSaid, waiting: w, peek: peekKey, over };
|
||||
if (slide || flip) {
|
||||
setFresh({ slide, flip });
|
||||
const t = setTimeout(() => setFresh({ slide: false, flip: false }), 700);
|
||||
@@ -818,10 +860,34 @@ function CockroachBoard({ view: v, me, players, act, pending, deadline }: BoardP
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
{banner}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 바퀴벌레 포커 sounds on top of the shared palette (synthesized, no files). */
|
||||
const cpSfx = {
|
||||
/** The card slides over with a little scuttle. */
|
||||
sneak: (delay = 0) => {
|
||||
for (let i = 0; i < 4; i++) noise(25, 0.05, delay + i * 45, 'bandpass', 3200 + i * 300, 2);
|
||||
},
|
||||
/** Wrong guess: a sour "bwomp". */
|
||||
wrong: () => {
|
||||
tone(260, 160, 'sawtooth', 0.05, 0, { slideTo: 180 });
|
||||
tone(180, 260, 'sawtooth', 0.05, 150, { slideTo: 110 });
|
||||
},
|
||||
/** The card lands face up in front of someone: a soft "splat". */
|
||||
splat: () => {
|
||||
noise(90, 0.12, 0, 'lowpass', 600);
|
||||
tone(140, 90, 'sine', 0.12, 0, { slideTo: 90 });
|
||||
},
|
||||
/** One more of that critter and you lose (or you just lost). */
|
||||
danger: () => {
|
||||
[880, 660, 880].forEach((f, i) => tone(f, 110, 'square', 0.05, i * 130));
|
||||
tone(110, 400, 'sawtooth', 0.04, 0, { slideTo: 70 });
|
||||
},
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------- side
|
||||
|
||||
function CockroachSide({ view: v, me, players, act, pending, deadline }: BoardProps<CockroachView>) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/** 고스톱 / 맞고 화면 (docs/games/gostop.md §9). Points are room-only play points. */
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
||||
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react';
|
||||
import type { BakKind, CardView, GostopOptions, GostopView, HandCardView, OutcomeView, SeatView, TurnTag } from '@bg/games/gostop';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar, Sheet } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { HwatuCard, type HwatuInfo } from '../../components/cards/HwatuCard';
|
||||
import { ChipIcon } from '../../components/cards/Chips';
|
||||
import { haptic, sounds } from '../../lib/feedback';
|
||||
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import { bump, cssEsc, flyFrom, flyGhost, fxEl, reducedMotion, seatEl, useBanner, type BannerTone } from '../card-fx';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -152,10 +153,6 @@ const CSS = `
|
||||
background: #dc2626; color: #fff; pointer-events: none; }
|
||||
.gs-hcard .tag.shake { background: #7c3aed; }
|
||||
.gs-hint { margin: 0; text-align: center; font-size: .9rem; color: var(--text-sub); }
|
||||
.gs-flash { position: fixed; left: 50%; top: 36%; transform: translate(-50%, -50%); z-index: 30; pointer-events: none; text-align: center;
|
||||
font-size: 3rem; font-weight: 900; color: #fde047; text-shadow: 0 3px 10px rgba(0,0,0,.7); animation: gs-pop .35s ease-out; white-space: nowrap; }
|
||||
.gs-flash small { display: block; font-size: 1.1rem; color: #fff; }
|
||||
@keyframes gs-pop { from { transform: translate(-50%, -50%) scale(.5); opacity: 0 } to { transform: translate(-50%, -50%) scale(1); opacity: 1 } }
|
||||
.gs-big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.gs-big .btn { min-height: 76px; font-size: 1.3rem; flex-direction: column; gap: 2px; line-height: 1.2; }
|
||||
.gs-big .btn small { font-size: .85rem; font-weight: 600; opacity: .95; }
|
||||
@@ -177,7 +174,6 @@ const CSS = `
|
||||
.gs-me { padding: 6px 4px; }
|
||||
.gs-hand { gap: 4px; }
|
||||
.gs-hcard { border-width: 2px; }
|
||||
.gs-flash { font-size: 2.4rem; }
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -197,9 +193,14 @@ function Card({ c, size = 'sm', className, style }: { c: CardView | null; size?:
|
||||
function CapturedRow({ seat, label }: { seat: SeatView; label: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const groups = (['gwang', 'yeol', 'tti', 'pi'] as const).filter((k) => seat.captured[k].length > 0);
|
||||
if (groups.length === 0) return <span className="small muted">먹은 패 없음</span>;
|
||||
if (groups.length === 0)
|
||||
return (
|
||||
<span className="small muted" data-fx-cap={seat.id}>
|
||||
먹은 패 없음
|
||||
</span>
|
||||
);
|
||||
return (
|
||||
<button type="button" className="gs-cap" aria-expanded={open} onClick={() => setOpen(!open)} aria-label={`${label} 먹은 패: ${groups.map((k) => `${KIND_LABEL[k]} ${seat.captured[k].length}장`).join(', ')}. 눌러서 ${open ? '접기' : '펼치기'}`}>
|
||||
<button type="button" className="gs-cap" data-fx-cap={seat.id} aria-expanded={open} onClick={() => setOpen(!open)} aria-label={`${label} 먹은 패: ${groups.map((k) => `${KIND_LABEL[k]} ${seat.captured[k].length}장`).join(', ')}. 눌러서 ${open ? '접기' : '펼치기'}`}>
|
||||
{groups.map((k) => (
|
||||
<span key={k} className="gs-pile">
|
||||
<b>
|
||||
@@ -207,7 +208,9 @@ function CapturedRow({ seat, label }: { seat: SeatView; label: string }) {
|
||||
</b>
|
||||
<span className="gs-pile-cards">
|
||||
{seat.captured[k].map((c) => (
|
||||
<HwatuCard key={c.key} card={c as HwatuInfo} size="sm" />
|
||||
<span key={c.key} data-gs-cap={c.key} style={{ display: 'inline-flex' }}>
|
||||
<HwatuCard card={c as HwatuInfo} size="sm" />
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
</span>
|
||||
@@ -260,7 +263,7 @@ function SeatBox({ seat, v, players, me, deadline }: { seat: SeatView; v: Gostop
|
||||
const u = userOf(players, seat.id);
|
||||
const active = actorOf(v) === seat.id;
|
||||
return (
|
||||
<li className={`gs-seat${active ? ' turn' : ''}${!seat.participant && v.step !== 'sell' ? ' out' : ''}`} aria-label={`${u.nickname}, 방 점수 ${signed(seat.total)}${seat.isDealer ? ', 선' : ''}${seat.participant ? `, 지금 ${seat.score.total}점, 손패 ${seat.handCount}장` : ''}`}>
|
||||
<li className={`gs-seat${active ? ' turn anim-glow' : ''}${!seat.participant && v.step !== 'sell' ? ' out' : ''}`} data-fx-seat={seat.id} aria-label={`${u.nickname}, 방 점수 ${signed(seat.total)}${seat.isDealer ? ', 선' : ''}${seat.participant ? `, 지금 ${seat.score.total}점, 손패 ${seat.handCount}장` : ''}`}>
|
||||
<div className="gs-head">
|
||||
<Avatar user={u} size={26} />
|
||||
<span className="nm">
|
||||
@@ -308,7 +311,7 @@ function Floor({ v, glow, narrow, players }: { v: GostopView; glow: Set<number>;
|
||||
const pf = v.pendingFlip;
|
||||
return (
|
||||
<div className="gs-table" role="region" aria-label="바닥">
|
||||
<ul className="gs-floor" aria-label="바닥 패(월별)">
|
||||
<ul className="gs-floor" data-fx="gs-floor" aria-label="바닥 패(월별)">
|
||||
{months.map((m) => {
|
||||
const g = v.floor.find((x) => x.month === m);
|
||||
const cls = `gs-slot${g ? ' has' : ''}${g && g.cards.length === 3 ? (g.natural ? ' ppeok natural' : ' ppeok') : ''}`;
|
||||
@@ -316,14 +319,16 @@ function Floor({ v, glow, narrow, players }: { v: GostopView; glow: Set<number>;
|
||||
? `${m}월 ${g.cards.length}장${g.cards.length === 3 ? (g.natural ? ', 처음 깔린 3장' : `, ${nick(players, g.ppeokBy)}님이 싼 뻑`) : ''}: ${g.cards.map((c) => c.name).join(', ')}`
|
||||
: `${m}월 없음`;
|
||||
return (
|
||||
<li key={m} className={cls} aria-label={label}>
|
||||
<li key={m} className={cls} data-gs-month={m} aria-label={label}>
|
||||
<span className="m" aria-hidden>
|
||||
{m}월
|
||||
</span>
|
||||
{g && (
|
||||
<span className="gs-slot-cards">
|
||||
{g.cards.map((c) => (
|
||||
<Card key={c.key} c={c} size={narrow ? 'sm' : 'md'} className={glow.has(c.id) ? 'gs-glow' : undefined} />
|
||||
<span key={c.key} className={glow.has(c.id) ? 'gs-glow' : undefined} data-gs-floor={c.key} style={{ display: 'inline-flex' }}>
|
||||
<HwatuCard card={c as HwatuInfo} size={narrow ? 'sm' : 'md'} />
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
@@ -333,7 +338,7 @@ function Floor({ v, glow, narrow, players }: { v: GostopView; glow: Set<number>;
|
||||
</ul>
|
||||
<div className="gs-side">
|
||||
<div className="gs-deck">
|
||||
<div aria-label={`더미 ${v.deckCount}장`} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2 }}>
|
||||
<div data-fx="gs-deck" aria-label={`더미 ${v.deckCount}장`} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2 }}>
|
||||
<HwatuCard card={null} size={narrow ? 'sm' : 'md'} />
|
||||
<strong>{v.deckCount}장</strong>
|
||||
</div>
|
||||
@@ -351,7 +356,9 @@ function Floor({ v, glow, narrow, players }: { v: GostopView; glow: Set<number>;
|
||||
{pf && (
|
||||
<div aria-label={`뒤집은 패 ${pf.flipped.name}`} style={{ textAlign: 'center' }}>
|
||||
<div className="small">뒤집은 패</div>
|
||||
<Card c={pf.flipped} size="sm" className="gs-glow" />
|
||||
<span className="gs-glow" data-fx="gs-pflip" style={{ display: 'inline-flex' }}>
|
||||
<HwatuCard card={pf.flipped as HwatuInfo} size="sm" />
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -423,8 +430,8 @@ function MyHand({ v, act, pending, tapConfirm, onFocusCard }: { v: GostopView; a
|
||||
setAsk(null);
|
||||
}, [v.turn, v.step, v.roundNo, v.lastTurn?.seq]);
|
||||
const hand = v.myHand ?? [];
|
||||
const send = (a: object) => {
|
||||
sounds.stone();
|
||||
const send = (a: { card: number | 'dummy'; target?: number; shake?: boolean; bomb?: boolean }) => {
|
||||
rememberPlay(a.card);
|
||||
act({ type: 'play', ...a });
|
||||
setLifted(null);
|
||||
setAsk(null);
|
||||
@@ -446,7 +453,7 @@ function MyHand({ v, act, pending, tapConfirm, onFocusCard }: { v: GostopView; a
|
||||
const floorCards = (ids: number[]) => v.floor.flatMap((g) => g.cards).filter((c) => ids.includes(c.id));
|
||||
return (
|
||||
<>
|
||||
<div className="gs-hand" role="group" aria-label="내 손패">
|
||||
<div className="gs-hand" data-fx="gs-hand" role="group" aria-label="내 손패">
|
||||
{hand.map((h) => {
|
||||
const match = hints && h.matches.length > 0;
|
||||
const tag = h.canBomb ? '폭탄' : h.canShake ? '흔들기' : null;
|
||||
@@ -456,6 +463,7 @@ function MyHand({ v, act, pending, tapConfirm, onFocusCard }: { v: GostopView; a
|
||||
key={h.card.key}
|
||||
type="button"
|
||||
className="gs-hcard"
|
||||
data-gs-hand={h.card.key}
|
||||
data-match={match || undefined}
|
||||
data-lifted={lifted === h.card.id || undefined}
|
||||
disabled={!canPlay}
|
||||
@@ -540,7 +548,7 @@ function MyArea(props: BoardProps<GostopView> & { onFocusCard: (h: HandCardView
|
||||
const active = actorOf(v) === me;
|
||||
if (v.phase !== 'playing') return null;
|
||||
return (
|
||||
<div className={`gs-me${active ? ' turn' : ''}`} aria-label="내 자리">
|
||||
<div className={`gs-me${active ? ' turn anim-glow' : ''}`} data-fx-seat={me} aria-label="내 자리">
|
||||
<div className="gs-head">
|
||||
<Avatar user={userOf(players, me)} size={26} />
|
||||
<span className="nm">나 · 합계 {signed(seat.total)}</span>
|
||||
@@ -703,7 +711,7 @@ function RoundResult({ view: v, me, players, act, pending }: BoardProps<GostopVi
|
||||
const seat = v.seats.find((s) => s.id === me);
|
||||
const nextMult = v.rules.nagariMultiplier === 'x2' ? Math.min(2 ** v.nagariStreak, v.rules.nagariMaxMultiplier) : 1;
|
||||
return (
|
||||
<section className="gs-panel gs-res" aria-label={`${v.roundNo}판 결과`} aria-live="polite">
|
||||
<section className="gs-panel gs-res" data-fx="gs-result" aria-label={`${v.roundNo}판 결과`} aria-live="polite">
|
||||
<h2 style={{ margin: 0 }}>
|
||||
{v.roundNo}판 결과 · {outcomeTitle(o, players, me)}
|
||||
</h2>
|
||||
@@ -777,13 +785,336 @@ function RoundResult({ view: v, me, players, act, pending }: BoardProps<GostopVi
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- motion + sound
|
||||
|
||||
/** 고스톱 sounds on top of the shared palette (synthesized, no files). */
|
||||
const gsSfx = {
|
||||
/** "탁!" — a hwatu card slapped on the floor. */
|
||||
slap: (gain = 1, delay = 0) => {
|
||||
noise(70, 0.3 * gain, delay, 'lowpass', 900);
|
||||
noise(22, 0.12 * gain, delay, 'highpass', 3200);
|
||||
tone(120, 90, 'sine', 0.22 * gain, delay, { slideTo: 60 });
|
||||
},
|
||||
/** Cards taken into the pile ("착착"). */
|
||||
gather: (n: number) => {
|
||||
for (let i = 0; i < Math.min(n, 4); i++) noise(45, 0.12, i * 60, 'bandpass', 1700 + i * 200, 1);
|
||||
},
|
||||
/** 쪽 */
|
||||
kiss: () => {
|
||||
tone(1100, 70, 'sine', 0.14, 0, { slideTo: 2300 });
|
||||
noise(25, 0.08, 55, 'highpass', 5000);
|
||||
},
|
||||
/** 뻑 — a dull, deflating thud. */
|
||||
ppeok: () => {
|
||||
noise(140, 0.22, 0, 'lowpass', 500);
|
||||
tone(320, 280, 'sawtooth', 0.06, 0, { slideTo: 90 });
|
||||
},
|
||||
/** 따닥 — two quick slaps. */
|
||||
ttadak: () => {
|
||||
gsSfx.slap(0.9);
|
||||
gsSfx.slap(1, 110);
|
||||
tone(988, 90, 'triangle', 0.08, 200);
|
||||
},
|
||||
/** 싹쓸이 — a broom sweep, then the pile. */
|
||||
sweep: () => {
|
||||
noise(260, 0.12, 0, 'bandpass', 1200, 0.5);
|
||||
sfx.collect();
|
||||
},
|
||||
/** 폭탄 */
|
||||
boom: () => {
|
||||
noise(450, 0.35, 0, 'lowpass', 280);
|
||||
tone(85, 420, 'sine', 0.3, 0, { slideTo: 38 });
|
||||
},
|
||||
/** 흔들기 — cards rattled in the hand. */
|
||||
rattle: () => {
|
||||
for (let i = 0; i < 6; i++) noise(35, 0.12, i * 60, 'bandpass', 2300 + (i % 2) * 700, 3);
|
||||
},
|
||||
/** 고 — rising, one step higher per 고. */
|
||||
go: (n: number) => {
|
||||
const up = Math.min(n, 5) * 60;
|
||||
[523, 659, 784].forEach((f, i) => tone(f + up, 110, 'square', 0.06, i * 70));
|
||||
},
|
||||
nagari: () => [440, 370, 311].forEach((f, i) => tone(f, 200, 'triangle', 0.12, i * 160)),
|
||||
};
|
||||
|
||||
/** Where my last played card was (its button is gone once the view arrives), so the floor card flies from there. */
|
||||
let myPlayRect: DOMRect | null = null;
|
||||
function rememberPlay(card: number | 'dummy'): void {
|
||||
myPlayRect = card === 'dummy' ? null : (document.querySelector(`.gs-hcard[data-gs-hand$="c${card}"]`)?.getBoundingClientRect() ?? null);
|
||||
}
|
||||
|
||||
const later = (ms: number, f: () => void) => (ms > 0 ? setTimeout(f, ms) : f());
|
||||
const byAttr = (attr: string, key: string | number): Element | null => document.querySelector(`[${attr}="${cssEsc(String(key))}"]`);
|
||||
const slotEl = (month: number) => (month > 0 ? byAttr('data-gs-month', month) : null);
|
||||
const capEl = (id: string) => byAttr('data-fx-cap', id) ?? seatEl(id);
|
||||
const CAP_KINDS = ['gwang', 'yeol', 'tti', 'pi'] as const;
|
||||
|
||||
/** A card turned face up (Web Animations, composite add, so it can run together with a fly-in). */
|
||||
function flipIn(el: Element | null | undefined, delay = 0): void {
|
||||
if (!el || reducedMotion() || typeof (el as HTMLElement).animate !== 'function') return;
|
||||
(el as HTMLElement).animate(
|
||||
[{ transform: 'perspective(600px) rotateY(90deg)' }, { transform: 'perspective(600px) rotateY(-12deg)', offset: 0.6 }, { transform: 'perspective(600px) rotateY(0deg)' }],
|
||||
{ duration: 380, delay, easing: 'ease', fill: 'backwards', composite: 'add' },
|
||||
);
|
||||
}
|
||||
|
||||
function capOwners(v: GostopView): Map<string, string> {
|
||||
const m = new Map<string, string>();
|
||||
for (const s of v.seats) for (const k of CAP_KINDS) for (const c of s.captured[k]) m.set(c.key, s.id);
|
||||
return m;
|
||||
}
|
||||
|
||||
const TAG_ORDER: TurnTag[] = ['samPpeok', 'yeonPpeok', 'firstPpeok', 'bomb', 'ttadak', 'jaPpeok', 'ppeokEat', 'ppeok', 'jjok', 'sseul', 'shake', 'bonus', 'bonusFlip'];
|
||||
const TAG_TONE: Partial<Record<TurnTag, BannerTone>> = {
|
||||
samPpeok: 'red', yeonPpeok: 'red', firstPpeok: 'red', ppeok: 'red', bomb: 'red',
|
||||
ttadak: 'gold', jaPpeok: 'gold', ppeokEat: 'gold', jjok: 'gold', sseul: 'green', shake: 'blue', bonus: 'blue', bonusFlip: 'blue',
|
||||
};
|
||||
|
||||
/** Sound (and a shake) for the most important tag of a turn. */
|
||||
function tagFx(tag: TurnTag | undefined, actor: string | null): void {
|
||||
switch (tag) {
|
||||
case 'samPpeok':
|
||||
gsSfx.ppeok();
|
||||
later(250, sfx.fanfare);
|
||||
break;
|
||||
case 'yeonPpeok':
|
||||
case 'firstPpeok':
|
||||
gsSfx.ppeok();
|
||||
later(280, sfx.good);
|
||||
break;
|
||||
case 'ppeok':
|
||||
gsSfx.ppeok();
|
||||
bump(fxEl('gs-floor'), 'shake');
|
||||
break;
|
||||
case 'bomb':
|
||||
gsSfx.boom();
|
||||
bump(fxEl('gs-floor'), 'shake');
|
||||
break;
|
||||
case 'ttadak':
|
||||
gsSfx.ttadak();
|
||||
break;
|
||||
case 'jaPpeok':
|
||||
case 'ppeokEat':
|
||||
sfx.good();
|
||||
break;
|
||||
case 'jjok':
|
||||
gsSfx.kiss();
|
||||
break;
|
||||
case 'sseul':
|
||||
gsSfx.sweep();
|
||||
break;
|
||||
case 'shake':
|
||||
gsSfx.rattle();
|
||||
if (actor) bump(seatEl(actor), 'shake');
|
||||
break;
|
||||
case 'bonus':
|
||||
case 'bonusFlip':
|
||||
sfx.pop();
|
||||
break;
|
||||
default:
|
||||
sfx.capture();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sounds + motion for every change of the table — mine, the other players' and the bots' — by diffing the previous
|
||||
* view: deal, card played (탁), deck card flipped, cards taken into a pile, 피 taken from another pile, 뻑·쪽·따닥·
|
||||
* 싹쓸이·폭탄·흔들기 banners, 고, 광 팔기 and the round result. Nothing on the first render (join / reload / replay),
|
||||
* except the first deal when mounted right at the start of the game.
|
||||
*/
|
||||
function useGostopFx(v: GostopView, me: string | null, players: Record<string, PublicUser>, showBanner: ReturnType<typeof useBanner>[1]) {
|
||||
const prev = useRef<GostopView | null>(null);
|
||||
const origin = (id: string | null): Element | DOMRect | null =>
|
||||
!id ? null : id === me ? (myPlayRect ?? fxEl('gs-hand') ?? seatEl(id)) : seatEl(id);
|
||||
|
||||
const deal = () => {
|
||||
const deck = fxEl('gs-deck');
|
||||
sfx.shuffle();
|
||||
later(300, () => sfx.deal(8, 55));
|
||||
document.querySelectorAll('[data-gs-floor]').forEach((el, i) => flyFrom(el, deck, { delay: 300 + i * 45, rotate: 8 }));
|
||||
const mine = document.querySelectorAll('[data-gs-hand]');
|
||||
mine.forEach((el, i) => flyFrom(el, deck, { delay: 300 + i * 40, rotate: 10 }));
|
||||
for (const s of v.seats) {
|
||||
if (s.handCount === 0 || (s.id === me && mine.length > 0)) continue;
|
||||
flyGhost(deck, seatEl(s.id), { kind: 'hwatu', count: 3, gap: 90, delay: 300 });
|
||||
}
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const p = prev.current;
|
||||
prev.current = v;
|
||||
if (!p) {
|
||||
// Mounted right at the start of the game (nothing played yet): show the deal once.
|
||||
if (v.roundNo === 1 && v.phase === 'playing' && !v.lastTurn && !v.sell?.decisions.length) deal();
|
||||
return;
|
||||
}
|
||||
if (p === v) return;
|
||||
// A new round, or the same round dealt again (총통 다시 돌리기).
|
||||
if (v.roundNo !== p.roundNo || (v.phase === 'playing' && p.phase === 'playing' && v.deckCount > p.deckCount)) {
|
||||
myPlayRect = null;
|
||||
if (v.phase === 'playing') deal();
|
||||
return;
|
||||
}
|
||||
const deck = fxEl('gs-deck');
|
||||
const lt = v.lastTurn;
|
||||
const newTurn = !!lt && lt.seq !== (p.lastTurn?.seq ?? 0);
|
||||
const pendingNew = !!v.pendingFlip && !p.pendingFlip;
|
||||
// The flip that needed a choice: the played card and the flip were already shown with the choice.
|
||||
const resumed = newTurn && !!p.pendingFlip;
|
||||
const actor = newTurn ? lt!.player : (v.pendingFlip?.player ?? p.turn);
|
||||
let bannerShown = false;
|
||||
|
||||
if (newTurn || pendingNew) {
|
||||
const fresh = newTurn && !resumed;
|
||||
const flippedKeys = new Set(fresh ? lt!.flipped.map((c) => c.key) : []);
|
||||
const before = new Set(p.floor.flatMap((g) => g.cards.map((c) => c.key)));
|
||||
const onFloor = new Set<string>();
|
||||
let played = false;
|
||||
let flipped = false;
|
||||
for (const g of v.floor)
|
||||
for (const c of g.cards) {
|
||||
onFloor.add(c.key);
|
||||
if (before.has(c.key)) continue;
|
||||
const el = byAttr('data-gs-floor', c.key);
|
||||
if (flippedKeys.has(c.key)) {
|
||||
flyFrom(el, deck, { delay: 380, ms: 300, rotate: 0, scale: 0.8 });
|
||||
flipIn(el, 380);
|
||||
flipped = true;
|
||||
} else {
|
||||
flyFrom(el, origin(actor), { ms: 340, rotate: -14 });
|
||||
played = true;
|
||||
}
|
||||
}
|
||||
if (fresh) {
|
||||
// Cards that were taken right away never stay on the floor: a copy flies to their month.
|
||||
for (const c of lt!.played) {
|
||||
played = true;
|
||||
if (!onFloor.has(c.key) && c.month > 0) flyGhost(origin(actor), slotEl(c.month), { kind: 'hwatu', ms: 340 });
|
||||
}
|
||||
for (const c of lt!.flipped) {
|
||||
flipped = true;
|
||||
if (!onFloor.has(c.key) && c.month > 0) flyGhost(deck, slotEl(c.month), { kind: 'hwatu', delay: 380, ms: 300 });
|
||||
}
|
||||
// 보너스패: the player takes one more card from the deck.
|
||||
if (lt!.tags.includes('bonus') && actor !== me) flyGhost(deck, seatEl(actor!), { kind: 'hwatu', delay: 300 });
|
||||
}
|
||||
if (pendingNew) {
|
||||
const el = fxEl('gs-pflip');
|
||||
flyFrom(el, deck, { delay: 380, ms: 300, rotate: 0, scale: 0.8 });
|
||||
flipIn(el, 380);
|
||||
flipped = true;
|
||||
played = true;
|
||||
}
|
||||
const bomb = fresh && lt!.tags.includes('bomb');
|
||||
if (played) later(260, () => gsSfx.slap(bomb ? 1.4 : 1));
|
||||
if (flipped) {
|
||||
later(380, sfx.cardFlip);
|
||||
later(640, () => gsSfx.slap(0.6));
|
||||
}
|
||||
|
||||
// Cards that reached a pile: from the floor (their month), the deck or hand (bonus cards), or another pile (피 뺏기).
|
||||
const capAt = resumed ? 120 : 720;
|
||||
const owners = capOwners(p);
|
||||
const robbed = new Set<string>();
|
||||
let got = 0;
|
||||
for (const s of v.seats)
|
||||
for (const k of CAP_KINDS)
|
||||
for (const c of s.captured[k]) {
|
||||
const was = owners.get(c.key);
|
||||
if (was === s.id) continue;
|
||||
const el = byAttr('data-gs-cap', c.key);
|
||||
if (was) {
|
||||
flyFrom(el, capEl(was), { delay: capAt + 250, ms: 420, scale: 0.8, rotate: 0 });
|
||||
robbed.add(was);
|
||||
} else {
|
||||
flyFrom(el, slotEl(c.month) ?? (flippedKeys.has(c.key) ? deck : origin(actor)), { delay: capAt, ms: 400, scale: 0.9, rotate: 0 });
|
||||
got++;
|
||||
}
|
||||
}
|
||||
if (got) later(capAt + 40, () => gsSfx.gather(got));
|
||||
if (robbed.size) {
|
||||
later(capAt + 250, sfx.whoosh);
|
||||
for (const id of robbed) later(capAt + 250, () => bump(seatEl(id), 'shake'));
|
||||
}
|
||||
|
||||
if (newTurn) {
|
||||
const f = flashText(v, players);
|
||||
if (f) {
|
||||
const top = TAG_ORDER.find((x) => lt!.tags.includes(x));
|
||||
later(resumed ? 150 : 600, () => {
|
||||
showBanner(f.big, (top && TAG_TONE[top]) ?? 'blue', f.small);
|
||||
tagFx(top, actor);
|
||||
});
|
||||
bannerShown = true;
|
||||
}
|
||||
}
|
||||
if (actor === me) myPlayRect = null;
|
||||
}
|
||||
|
||||
// My new hand cards during a round (보너스패 draw).
|
||||
if (v.myHand && p.myHand) {
|
||||
const had = new Set(p.myHand.map((h) => h.card.key));
|
||||
v.myHand.filter((h) => !had.has(h.card.key)).forEach((h, i) => flyFrom(byAttr('data-gs-hand', h.card.key), deck, { delay: 300 + i * 60, rotate: 10 }));
|
||||
}
|
||||
|
||||
// 고
|
||||
for (const s of v.seats) {
|
||||
const b = p.seats.find((x) => x.id === s.id);
|
||||
if (!b || s.goCount <= b.goCount) continue;
|
||||
showBanner(`${s.goCount}고!`, 'red', s.id === me ? undefined : `${nick(players, s.id)}님`);
|
||||
gsSfx.go(s.goCount);
|
||||
bump(seatEl(s.id));
|
||||
bannerShown = true;
|
||||
}
|
||||
|
||||
// 광팔기: a player sits out (and shows the cards they sell).
|
||||
for (const d of v.sell?.decisions.slice(p.sell?.decisions.length ?? 0) ?? []) {
|
||||
if (!d.sell) {
|
||||
sfx.select();
|
||||
continue;
|
||||
}
|
||||
const n = v.seats.find((s) => s.id === d.player)?.seller?.shown.length ?? 0;
|
||||
showBanner(n ? '광 팔기!' : '죽기', 'blue', `${nick(players, d.player)}님${n ? ` · 광 ${n}장` : ''}`);
|
||||
if (n) sfx.chips(Math.min(n, 4));
|
||||
else sfx.whoosh();
|
||||
bump(seatEl(d.player));
|
||||
bannerShown = true;
|
||||
}
|
||||
|
||||
// Round result: 스톱 / 총통 / 삼뻑 / 나가리.
|
||||
const o = v.outcome;
|
||||
if (o && !p.outcome) {
|
||||
const at = bannerShown ? 1000 : 0;
|
||||
const who = o.winner === me ? '내가 이겼어요' : `${nick(players, o.winner)}님이 이겼어요`;
|
||||
const nextMult = v.rules.nagariMultiplier === 'x2' ? Math.min(2 ** v.nagariStreak, v.rules.nagariMaxMultiplier) : 1;
|
||||
const mySeat = v.seats.find((s) => s.id === me);
|
||||
later(at, () => {
|
||||
if (o.type === 'nagari') showBanner('나가리', 'dark', nextMult > 1 ? `다음 판 x${nextMult}` : undefined);
|
||||
else showBanner(o.type === 'chongtong' ? '총통!' : o.type === 'samppeok' ? '삼뻑!' : '스톱!', o.type === 'samppeok' ? 'red' : 'gold', who);
|
||||
// The last round: the result dialog already plays the win/lose sound.
|
||||
if (o.type === 'nagari') gsSfx.nagari();
|
||||
else if (v.phase === 'finished' && mySeat) return;
|
||||
else if (o.winner === me) sounds.win();
|
||||
else if (mySeat?.participant) sounds.lose();
|
||||
else sfx.fanfare();
|
||||
});
|
||||
if (o.winner) {
|
||||
const to = seatEl(o.winner) ?? fxEl('gs-result');
|
||||
o.payments.forEach((pay, i) => {
|
||||
if (pay.amount > 0) flyGhost(seatEl(pay.from) ?? fxEl('gs-result'), to, { kind: 'chip', count: 3, gap: 70, delay: at + 250 + i * 120 });
|
||||
});
|
||||
if (o.payments.some((pay) => pay.amount > 0)) later(at + 500, () => sfx.chips(4));
|
||||
}
|
||||
}
|
||||
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- board
|
||||
|
||||
function GostopBoard(props: BoardProps<GostopView>) {
|
||||
const { view: v, me, players } = props;
|
||||
const narrow = useNarrow();
|
||||
const [focus, setFocus] = useState<HandCardView | null>(null);
|
||||
const [flash, setFlash] = useState<{ big: string; small: string } | null>(null);
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const mine = isMyTurn(v, me);
|
||||
const prevMine = useRef(false);
|
||||
@@ -796,10 +1127,6 @@ function GostopBoard(props: BoardProps<GostopView>) {
|
||||
`${nick(players, t.player)}님: ${t.played.map((c) => c.name).join(', ')}${t.played.length ? ' 냄, ' : ''}${t.flipped.map((c) => c.name).join(', ')} 뒤집음, ${t.captured.length}장 먹음${f ? `. ${f.big}` : ''}`,
|
||||
);
|
||||
}
|
||||
setFlash(f);
|
||||
if (!f) return undefined;
|
||||
const tm = setTimeout(() => setFlash(null), 1300);
|
||||
return () => clearTimeout(tm);
|
||||
}, [seq]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useEffect(() => {
|
||||
if (mine && !prevMine.current && v.phase === 'playing') {
|
||||
@@ -811,10 +1138,11 @@ function GostopBoard(props: BoardProps<GostopView>) {
|
||||
}, [mine]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useEffect(() => {
|
||||
if (v.outcome && v.phase !== 'playing') {
|
||||
if (v.outcome.winner === me) sounds.win();
|
||||
setAnnounce(`${v.roundNo}판 결과: ${outcomeTitle(v.outcome, players, me)}`);
|
||||
}
|
||||
}, [v.roundNo, v.phase]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const [banner, showBanner] = useBanner();
|
||||
useGostopFx(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 glow = new Set<number>(v.rules.hints && focus ? focus.matches : []);
|
||||
@@ -831,12 +1159,7 @@ function GostopBoard(props: BoardProps<GostopView>) {
|
||||
<RoundResult {...props} />
|
||||
<MyArea {...props} onFocusCard={setFocus} />
|
||||
<Decisions {...props} />
|
||||
{flash && v.phase === 'playing' && (
|
||||
<div className="gs-flash" aria-hidden>
|
||||
{flash.big}
|
||||
<small>{flash.small}</small>
|
||||
</div>
|
||||
)}
|
||||
{banner}
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** 스플렌더 화면 (docs/games/splendor.md §9). Everything is drawn from the view; art is own CSS/SVG. */
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import type {
|
||||
BuyOption,
|
||||
Color,
|
||||
@@ -17,7 +17,8 @@ import type {
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar, ConfirmSheet } 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, useBanner, useChange, useNewEntries } from '../card-fx';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -50,7 +51,6 @@ const iGa = (w: string) => {
|
||||
};
|
||||
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 reducedMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
const emptyTokens = (): Tokens => ({ W: 0, U: 0, G: 0, R: 0, K: 0, gold: 0 });
|
||||
const sum = (t: Partial<Record<TokenColor, number>>) => TOKEN_COLORS.reduce((a, c) => a + (t[c] ?? 0), 0);
|
||||
const costText = (cost: Partial<Record<TokenColor, number>>) =>
|
||||
@@ -93,8 +93,6 @@ const CSS = `
|
||||
.sp-card.can .sp-flag { background: var(--success); color: #fff; }
|
||||
.sp-card.gold .sp-flag { background: #a16207; color: #fff; }
|
||||
.sp-card.empty { background: transparent; border: 2px dashed var(--border); box-shadow: none; cursor: default; display: flex; align-items: center; justify-content: center; color: var(--text-sub); font-size: .8rem; }
|
||||
.sp-card.fresh { animation: sp-in .45s ease-out; }
|
||||
@keyframes sp-in { from { transform: scale(.7) rotate(-4deg); opacity: 0; } to { transform: none; opacity: 1; } }
|
||||
.sp-card.mini { --cw: 62px; --ch: 84px; border-width: 2px; }
|
||||
.sp-back { background: repeating-linear-gradient(45deg, #3b3157, #3b3157 6px, #4a3f6b 6px, #4a3f6b 12px); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 800; }
|
||||
.sp-back.t1 { --bk: #2f5d46; background: repeating-linear-gradient(45deg, #2f5d46, #2f5d46 6px, #3a6d54 6px, #3a6d54 12px); }
|
||||
@@ -176,9 +174,19 @@ button.sp-noble { cursor: pointer; }
|
||||
.sp-mini-cols > span { display: flex; flex-direction: column; align-items: center; background: var(--surface-2); border-radius: 8px; padding: 2px 0; line-height: 1.25; }
|
||||
.sp-badge { display: inline-block; border-radius: 999px; padding: 0 8px; font-weight: 800; font-size: .74rem; line-height: 1.6; }
|
||||
|
||||
.sp-crown { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 30; pointer-events: none; font-size: 2.4rem; font-weight: 900;
|
||||
color: #fde047; text-shadow: 0 3px 10px rgba(0,0,0,.6); animation: sp-pop .6s ease-out both; white-space: nowrap; }
|
||||
@keyframes sp-pop { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 60% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); } }
|
||||
|
||||
/* flying copies (card-fx ghosts): gem tokens, cards, card backs, noble tiles */
|
||||
.fx-ghost.sp-fx-gem { border: 3px solid rgba(0,0,0,.35); background: var(--g); color: var(--gt); font-size: 9px; box-shadow: inset 0 0 0 3px rgba(255,255,255,.3), 0 2px 5px rgba(0,0,0,.4); }
|
||||
.fx-ghost.sp-fx-W { --g: #f4f6f9; --gt: #1c1e21; border-color: #8a94a6; } .fx-ghost.sp-fx-U { --g: #2563eb; --gt: #fff; } .fx-ghost.sp-fx-G { --g: #15803d; --gt: #fff; }
|
||||
.fx-ghost.sp-fx-R { --g: #c81e1e; --gt: #fff; } .fx-ghost.sp-fx-K { --g: #23262d; --gt: #fff; border-color: #6b7280; } .fx-ghost.sp-fx-gold { --g: #eab308; --gt: #2b1d00; border-color: #a16207; }
|
||||
.fx-ghost.sp-fx-card { border: 2px solid #cbbf9f; border-radius: 6px; background: linear-gradient(160deg, var(--g, #e8edf3) 0%, #fffaf0 70%); color: #1c1e21;
|
||||
box-shadow: 0 3px 8px rgba(0,0,0,.35); font: 900 15px/1 system-ui, sans-serif; padding: 3px 4px; }
|
||||
.fx-ghost.sp-fx-b-W { --g: #e8edf3; } .fx-ghost.sp-fx-b-U { --g: #c9dcff; } .fx-ghost.sp-fx-b-G { --g: #c8efd3; } .fx-ghost.sp-fx-b-R { --g: #ffd0cc; } .fx-ghost.sp-fx-b-K { --g: #c9ccd3; }
|
||||
.fx-ghost.sp-fx-t1 { background: repeating-linear-gradient(45deg, #2f5d46, #2f5d46 5px, #3a6d54 5px, #3a6d54 10px); border-color: rgba(0,0,0,.3); }
|
||||
.fx-ghost.sp-fx-t2 { background: repeating-linear-gradient(45deg, #7a5a14, #7a5a14 5px, #8a6a20 5px, #8a6a20 10px); border-color: rgba(0,0,0,.3); }
|
||||
.fx-ghost.sp-fx-t3 { background: repeating-linear-gradient(45deg, #34407a, #34407a 5px, #404d8c 5px, #404d8c 10px); border-color: rgba(0,0,0,.3); }
|
||||
.fx-ghost.sp-fx-noble { border: 2px solid #b08d3c; border-radius: 8px; background: linear-gradient(135deg, #fff4d1, #f2d79a); box-shadow: 0 3px 10px rgba(0,0,0,.35);
|
||||
display: flex; align-items: center; justify-content: center; font-size: 20px; }
|
||||
.sp-help { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .9rem; }
|
||||
.sp-help b { background: var(--primary-soft); border-radius: 8px; padding: 2px 8px; }
|
||||
|
||||
@@ -210,7 +218,7 @@ button.sp-noble { cursor: pointer; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.sp-card, .sp-token { transition: none; }
|
||||
.sp-card.fresh, .sp-token.shake, .sp-crown { animation: none; }
|
||||
.sp-token.shake { animation: none; }
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -321,7 +329,7 @@ function CardBack({ tier, n, label }: { tier: Tier; n?: number; label?: string }
|
||||
);
|
||||
}
|
||||
|
||||
function NobleTile({ noble, need, onClick, pick }: { noble: Noble; need?: number; onClick?: () => void; pick?: boolean }) {
|
||||
function NobleTile({ noble, need, onClick, pick, fx }: { noble: Noble; need?: number; onClick?: () => void; pick?: boolean; fx?: boolean }) {
|
||||
const name = NOBLE_NAME[noble.id] ?? `귀족 ${Number(noble.id.slice(1))}`;
|
||||
const req = COLORS.filter((c) => noble.req[c] > 0);
|
||||
const label = `${name}, ${noble.points}점, 필요한 보너스 ${req.map((c) => `${SHORT[c]} ${noble.req[c]}`).join(' ')}${need !== undefined ? `, 남은 보너스 ${need}` : ''}`;
|
||||
@@ -362,7 +370,7 @@ function NobleTile({ noble, need, onClick, pick }: { noble: Noble; need?: number
|
||||
</button>
|
||||
);
|
||||
return (
|
||||
<div className="sp-noble" role="img" aria-label={label}>
|
||||
<div className="sp-noble" role="img" aria-label={label} data-fx-noble={fx ? noble.id : undefined}>
|
||||
{body}
|
||||
</div>
|
||||
);
|
||||
@@ -384,7 +392,6 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
const [back, setBack] = useState<Tokens>(emptyTokens);
|
||||
const [msg, setMsg] = useState<{ text: string; bad: boolean } | null>(null);
|
||||
const [shake, setShake] = useState<{ c: TokenColor; n: number } | null>(null);
|
||||
const [crown, setCrown] = useState<string | null>(null);
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const [openOpp, setOpenOpp] = useState<string | null>(null);
|
||||
const [askPass, setAskPass] = useState(false);
|
||||
@@ -397,8 +404,8 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
});
|
||||
const prevTurn = useRef(v.turnSeq);
|
||||
const prevLog = useRef(v.log.at(-1)?.n ?? 0);
|
||||
const prevBoard = useRef<Record<string, string | null>>({});
|
||||
const [fresh, setFresh] = useState<Set<string>>(new Set());
|
||||
const [banner, showBanner] = useBanner();
|
||||
useSplendorFx(v, me, players, showBanner);
|
||||
|
||||
// Reset local choices whenever the turn or phase moves on.
|
||||
useEffect(() => {
|
||||
@@ -419,45 +426,16 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
}
|
||||
}, [v.turnSeq]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// New log lines → screen reader text, sounds, noble crown.
|
||||
// New log lines → screen reader text (sounds and motion: useSplendorFx).
|
||||
useEffect(() => {
|
||||
const last = prevLog.current;
|
||||
const news = v.log.filter((e) => e.n > last);
|
||||
prevLog.current = v.log.at(-1)?.n ?? last;
|
||||
if (!news.length || last === 0) return;
|
||||
setAnnounce(news.map((e) => logText(e, players, me)).join(' '));
|
||||
if (news.some((e) => e.k === 'buy' || e.k === 'take')) sounds.stone();
|
||||
const noble = news.find((e) => e.k === 'noble');
|
||||
if (noble && noble.k === 'noble') {
|
||||
setCrown(`👑 ${noble.p === me ? '나에게' : `${nick(players, noble.p)}님에게`} ${NOBLE_NAME[noble.nobleId] ?? '귀족'} 방문!`);
|
||||
haptic([60, 40, 60]);
|
||||
}
|
||||
if (news.some((e) => e.k === 'noble')) haptic([60, 40, 60]);
|
||||
}, [v.log]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
if (!crown) return;
|
||||
const t = setTimeout(() => setCrown(null), reducedMotion() ? 2200 : 1500);
|
||||
return () => clearTimeout(t);
|
||||
}, [crown]);
|
||||
|
||||
// Newly revealed board cards get a short entrance animation.
|
||||
useEffect(() => {
|
||||
const now: Record<string, string | null> = {};
|
||||
const changed = new Set<string>();
|
||||
for (const t of TIERS_DOWN)
|
||||
v.board[t].forEach((c, i) => {
|
||||
const k = `b${t}-${i}`;
|
||||
now[k] = c?.id ?? null;
|
||||
if (prevBoard.current[k] !== undefined && prevBoard.current[k] !== now[k] && c) changed.add(k);
|
||||
});
|
||||
prevBoard.current = now;
|
||||
if (changed.size) {
|
||||
setFresh(changed);
|
||||
const t = setTimeout(() => setFresh(new Set()), 600);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
}, [v.board]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!shake) return;
|
||||
const t = setTimeout(() => setShake(null), 400);
|
||||
@@ -480,18 +458,26 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
setManual(null);
|
||||
if (v.supply[c] <= 0) return refuse(c, '남아 있지 않은 색이에요.');
|
||||
setMsg(null);
|
||||
if (same) return setPicks([c]);
|
||||
if (same) {
|
||||
sfx.select();
|
||||
return setPicks([c]);
|
||||
}
|
||||
if (picks.length === 1 && picks[0] === c) {
|
||||
if (my?.takeSame.includes(c)) {
|
||||
sfx.select();
|
||||
setPicks([c, c]);
|
||||
setMsg({ text: `${NAME[c]} 2개를 가져와요.`, bad: false });
|
||||
return;
|
||||
}
|
||||
return refuse(c, '같은 색 2개는 4개 이상 남은 색에서만 가져올 수 있어요.');
|
||||
}
|
||||
if (picks.includes(c)) return setPicks(picks.filter((x) => x !== c));
|
||||
if (picks.includes(c)) {
|
||||
sfx.click();
|
||||
return setPicks(picks.filter((x) => x !== c));
|
||||
}
|
||||
if (takeCount === 0) return refuse(c, '서로 다른 색 보석은 가져올 수 없어요.');
|
||||
if (picks.length >= takeCount) return refuse(c, `서로 다른 색은 ${takeCount}개까지 골라요.`);
|
||||
sfx.select();
|
||||
setPicks([...picks, c]);
|
||||
};
|
||||
const take = () => {
|
||||
@@ -517,7 +503,10 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
setPicks([]);
|
||||
setManual(null);
|
||||
setMsg(null);
|
||||
setSel(sel && selKey(sel) === selKey(s) ? null : s);
|
||||
const off = !!sel && selKey(sel) === selKey(s);
|
||||
if (off) sfx.click();
|
||||
else sfx.select();
|
||||
setSel(off ? null : s);
|
||||
};
|
||||
const payment = manual ?? buyOpt?.payment ?? null;
|
||||
const deckSel = sel?.kind === 'deck' ? sel : null;
|
||||
@@ -558,6 +547,8 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
if (next[c] >= mine.tokens[c]) return;
|
||||
next[c]++;
|
||||
} else if (next[c] > 0) next[c]--;
|
||||
else return;
|
||||
sfx.select();
|
||||
setMsg(null);
|
||||
setBack(next);
|
||||
};
|
||||
@@ -565,7 +556,7 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
const cardClass = (key: string, extra = '') => {
|
||||
const opt = my?.buy[key];
|
||||
const hl = hints && opt && !mine?.conceded ? (opt.gold > 0 ? ' gold' : ' can') : '';
|
||||
return `sp-card${hl}${sel && selKey(sel) === key ? ' sel' : ''}${fresh.has(key) ? ' fresh' : ''}${extra}`;
|
||||
return `sp-card${hl}${sel && selKey(sel) === key ? ' sel' : ''}${extra}`;
|
||||
};
|
||||
const cardAria = (card: DevCard, key: string) => {
|
||||
const opt = my?.buy[key];
|
||||
@@ -595,7 +586,8 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
key={p}
|
||||
type="button"
|
||||
role="listitem"
|
||||
className={`sp-chip${v.current === p ? ' turn' : ''}`}
|
||||
className={`sp-chip${v.current === p ? ` turn${v.phase !== 'finished' ? ' anim-glow' : ''}` : ''}`}
|
||||
data-fx-seat={p}
|
||||
aria-expanded={openOpp === p}
|
||||
aria-label={`${nick(players, p)} ${pv.points}점, 보석 ${pv.tokenCount}개, 카드 ${pv.cards.length}장, 예약 ${pv.reservedCount}장${v.current === p ? ', 지금 차례' : ''}. 누르면 자세히 보여요`}
|
||||
onClick={() => setOpenOpp(openOpp === p ? null : p)}
|
||||
@@ -640,9 +632,9 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
</div>
|
||||
)}
|
||||
<div className="sp-table">
|
||||
<section className="sp-nobles" aria-label={`귀족 ${v.nobles.length}명`}>
|
||||
<section className="sp-nobles" aria-label={`귀족 ${v.nobles.length}명`} data-fx="sp-nobles">
|
||||
{v.nobles.map((n) => (
|
||||
<NobleTile key={n.id} noble={n} need={hints && my ? my.nobleNeed[n.id] : undefined} />
|
||||
<NobleTile key={n.id} noble={n} need={hints && my ? my.nobleNeed[n.id] : undefined} fx />
|
||||
))}
|
||||
{v.nobles.length === 0 && <span className="small muted">남은 귀족이 없어요</span>}
|
||||
</section>
|
||||
@@ -652,6 +644,7 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
<button
|
||||
type="button"
|
||||
className={`sp-deck sp-back t${t}${sel?.kind === 'deck' && sel.tier === t ? ' sel' : ''}`}
|
||||
data-fx={`sp-deck-${t}`}
|
||||
disabled={v.deckCounts[t] === 0}
|
||||
aria-label={`${t}단계 더미 ${v.deckCounts[t]}장${my?.reserveDecks.includes(t) ? '. 누르면 안 보고 예약할 수 있어요' : ''}`}
|
||||
onClick={() => choose({ kind: 'deck', tier: t })}
|
||||
@@ -662,12 +655,12 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
const key = `b${t}-${i}`;
|
||||
if (!card)
|
||||
return (
|
||||
<div key={key} className="sp-card empty" aria-label="빈 칸">
|
||||
<div key={key} className="sp-card empty" aria-label="빈 칸" data-fx={`sp-slot-${key}`}>
|
||||
빈 칸
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<button key={key} type="button" className={cardClass(key)} data-b={card.bonus} aria-label={cardAria(card, key)} aria-pressed={sel ? selKey(sel) === key : false} onClick={() => choose({ kind: 'board', tier: t, slot: i })}>
|
||||
<button key={key} type="button" className={cardClass(key)} data-b={card.bonus} data-fx={`sp-slot-${key}`} aria-label={cardAria(card, key)} aria-pressed={sel ? selKey(sel) === key : false} onClick={() => choose({ kind: 'board', tier: t, slot: i })}>
|
||||
<CardFace card={card} />
|
||||
{flag(key)}
|
||||
</button>
|
||||
@@ -687,6 +680,7 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
type="button"
|
||||
className={`sp-token${n === 0 ? ' out' : ''}${count ? ' picked' : ''}${count === 2 ? ' picked2' : ''}${shake?.c === c ? ' shake' : ''}`}
|
||||
data-c={c}
|
||||
data-fx={`sp-bank-${c}`}
|
||||
disabled={isGold || !acting}
|
||||
aria-pressed={!isGold && acting ? count > 0 : undefined}
|
||||
aria-label={`${NAME[c]} ${n}개 남음${count ? `, ${count}개 고름` : ''}${isGold ? ' (예약하면 1개 받아요)' : ''}`}
|
||||
@@ -876,16 +870,224 @@ function SplendorBoard({ view: v, me, players, act, pending, tapConfirm }: Board
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
{crown && (
|
||||
<div className="sp-crown" aria-hidden>
|
||||
{crown}
|
||||
</div>
|
||||
)}
|
||||
{banner}
|
||||
{askPass && <ConfirmSheet title="차례를 넘길까요?" body="지금은 할 수 있는 행동이 없어요." confirm="넘기기" onConfirm={() => act({ type: 'PASS' })} onClose={() => setAskPass(false)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- motion + sound
|
||||
|
||||
/** 스플렌더 sounds on top of the shared palette (synthesized; `delay` in ms). */
|
||||
const spSfx = {
|
||||
/** Glassy gem "clink" (bank → player). */
|
||||
clink: (delay = 0, i = 0) => {
|
||||
const f = 2350 + (i % 4) * 170;
|
||||
tone(f, 70, 'triangle', 0.08, delay);
|
||||
tone(f * 1.5, 130, 'sine', 0.035, delay + 6);
|
||||
},
|
||||
/** Gems put back on the bank: lower and softer. */
|
||||
clack: (delay = 0, i = 0) => {
|
||||
tone(1500 + (i % 3) * 110, 60, 'triangle', 0.06, delay);
|
||||
noise(25, 0.05, delay, 'highpass', 5000);
|
||||
},
|
||||
/** A development card bought: card slide + "ka-ching". */
|
||||
buy: (delay = 0) => {
|
||||
noise(80, 0.15, delay, 'bandpass', 1600, 0.9);
|
||||
tone(784, 90, 'triangle', 0.1, delay + 40);
|
||||
tone(1175, 170, 'triangle', 0.1, delay + 120);
|
||||
},
|
||||
/** A card put aside (reserved). */
|
||||
reserve: (delay = 0) => {
|
||||
noise(90, 0.14, delay, 'bandpass', 2200, 0.8);
|
||||
tone(660, 90, 'triangle', 0.08, delay + 50);
|
||||
tone(520, 120, 'triangle', 0.06, delay + 120);
|
||||
},
|
||||
gold: (delay = 0) => {
|
||||
tone(1318, 70, 'square', 0.05, delay);
|
||||
tone(1976, 160, 'square', 0.05, delay + 70);
|
||||
},
|
||||
/** New market card turned face up. */
|
||||
flip: (delay = 0) => {
|
||||
noise(60, 0.12, delay, 'highpass', 2500);
|
||||
tone(1400, 40, 'triangle', 0.05, delay + 10);
|
||||
},
|
||||
/** Noble visit: a little bell chime. */
|
||||
noble: (delay = 0) => [1047, 1319, 1568, 2093].forEach((f, i) => tone(f, 420, 'sine', 0.1, delay + i * 110)),
|
||||
};
|
||||
|
||||
const isShown = (el: Element | null | undefined): el is Element => {
|
||||
if (!el) return false;
|
||||
const r = el.getBoundingClientRect();
|
||||
return r.width > 0 || r.height > 0;
|
||||
};
|
||||
/** A player's place on screen: my area, else the first visible seat (side list on wide screens, chip on narrow ones). */
|
||||
function seatOf(p: string, me: string | null): Element | null {
|
||||
if (p === me) {
|
||||
const m = fxEl('sp-mine');
|
||||
if (isShown(m)) return m;
|
||||
}
|
||||
for (const el of document.querySelectorAll(`[data-fx-seat="${cssEsc(p)}"]`)) if (isShown(el)) return el;
|
||||
return null;
|
||||
}
|
||||
/** Where a player's colour `c` is shown (my column, an opponent's mini column), else their seat. */
|
||||
function gemSpot(p: string, c: TokenColor, me: string | null): Element | null {
|
||||
if (p === me) {
|
||||
const el = fxEl(`sp-tok-${c}`);
|
||||
if (isShown(el)) return el;
|
||||
}
|
||||
const seat = seatOf(p, me);
|
||||
const col = seat?.querySelector(`[data-fx-tok="${c}"]`);
|
||||
return isShown(col) ? col : seat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sounds + motion for every change of the table, mine or anyone else's (new log entries and board diffs since the
|
||||
* previous view). Nothing on the first render (join, reload, replay jump).
|
||||
*/
|
||||
function useSplendorFx(v: SplendorView, me: string | null, players: Record<string, PublicUser>, showBanner: ReturnType<typeof useBanner>[1]) {
|
||||
const later = (ms: number, f: () => void) => (ms ? setTimeout(f, ms) : f());
|
||||
// Board of the previous view (slot key → card id) to know where a bought / reserved card was.
|
||||
const prevBoard = useRef<Record<string, string | null> | null>(null);
|
||||
// Nobles and my reserved cards disappear from the DOM with the new view: remember their rects while the DOM still
|
||||
// shows the previous view (render phase, only when the log moved).
|
||||
const snap = useRef<{ n: number; rects: Map<string, DOMRect> }>({ n: -1, rects: new Map() });
|
||||
const tail = v.log.at(-1)?.n ?? 0;
|
||||
if (snap.current.n !== tail && typeof document !== 'undefined') {
|
||||
const rects = new Map<string, DOMRect>();
|
||||
document.querySelectorAll('[data-fx-noble], [data-fx="sp-reserved"] [data-fx-res]').forEach((el) => {
|
||||
const id = el.getAttribute('data-fx-noble');
|
||||
rects.set(id ? `n:${id}` : `r:${el.getAttribute('data-fx-res')}`, el.getBoundingClientRect());
|
||||
});
|
||||
snap.current = { n: tail, rects };
|
||||
}
|
||||
|
||||
const gemsFly = (tokens: Partial<Tokens>, p: string, toBank: boolean, at: number) => {
|
||||
let i = 0;
|
||||
for (const c of TOKEN_COLORS) {
|
||||
const n = Math.min(tokens[c] ?? 0, 6);
|
||||
if (!n) continue;
|
||||
const bank = fxEl(`sp-bank-${c}`);
|
||||
const spot = gemSpot(p, c, me);
|
||||
flyGhost(toBank ? spot : bank, toBank ? bank : spot, { kind: 'chip', count: n, gap: 80, delay: at + i * 80, ms: 420, label: SHORT[c], className: `sp-fx-gem sp-fx-${c}` });
|
||||
for (let k = 0; k < n; k++) (toBank ? spSfx.clack : spSfx.clink)(at + (i + k) * 80 + (toBank ? 380 : 120), i + k);
|
||||
i += n;
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
useNewEntries(
|
||||
v.log,
|
||||
(e) => e.n,
|
||||
(fresh) => {
|
||||
const board = prevBoard.current ?? {};
|
||||
const slotOf = (id: string) => Object.keys(board).find((k) => board[k] === id);
|
||||
let t = 0;
|
||||
for (const e of fresh) {
|
||||
const at = t;
|
||||
switch (e.k) {
|
||||
case 'take':
|
||||
gemsFly(e.tokens, e.p, false, at);
|
||||
t += 200;
|
||||
break;
|
||||
case 'discard':
|
||||
gemsFly(e.tokens, e.p, true, at);
|
||||
t += 200;
|
||||
break;
|
||||
case 'buy': {
|
||||
const bonus = e.cardId[1] as Color;
|
||||
const to = gemSpot(e.p, bonus, me);
|
||||
const slot = e.fromReserve ? undefined : slotOf(e.cardId);
|
||||
const from: Element | DOMRect | null = slot
|
||||
? fxEl(`sp-slot-${slot}`)
|
||||
: e.fromReserve && e.p === me
|
||||
? (snap.current.rects.get(`r:${e.cardId}`) ?? fxEl('sp-reserved'))
|
||||
: seatOf(e.p, me);
|
||||
flyGhost(from, to, { kind: 'card', delay: at, ms: 520, className: `sp-fx-card sp-fx-b-${bonus}` });
|
||||
later(at + 480, () => bump(to));
|
||||
spSfx.buy(at);
|
||||
const paid = sum(e.paid);
|
||||
if (paid) gemsFly(e.paid, e.p, true, at + 120);
|
||||
t += 300 + Math.min(paid, 6) * 40;
|
||||
break;
|
||||
}
|
||||
case 'reserve': {
|
||||
const slot = e.cardId ? slotOf(e.cardId) : undefined;
|
||||
const from = slot ? fxEl(`sp-slot-${slot}`) : fxEl(`sp-deck-${e.tier}`);
|
||||
const look = e.cardId ? `sp-fx-b-${e.cardId[1]}` : `sp-fx-t${e.tier}`;
|
||||
const mineEls = e.p === me ? document.querySelectorAll('[data-fx="sp-reserved"] [data-fx-res]') : null;
|
||||
const newCard = mineEls?.length ? mineEls[mineEls.length - 1] : null;
|
||||
if (newCard && isShown(newCard)) flyFrom(newCard, from, { delay: at, ms: 460, rotate: -8 });
|
||||
else flyGhost(from, e.p === me ? fxEl('sp-reserved') : seatOf(e.p, me), { kind: 'card', delay: at, ms: 500, className: `sp-fx-card ${look}` });
|
||||
spSfx.reserve(at);
|
||||
if (e.gold) {
|
||||
flyGhost(fxEl('sp-bank-gold'), gemSpot(e.p, 'gold', me), { kind: 'chip', delay: at + 180, ms: 420, label: SHORT.gold, className: 'sp-fx-gem sp-fx-gold' });
|
||||
spSfx.gold(at + 520);
|
||||
}
|
||||
t += 300;
|
||||
break;
|
||||
}
|
||||
case 'noble': {
|
||||
const from = snap.current.rects.get(`n:${e.nobleId}`) ?? fxEl('sp-nobles');
|
||||
const at2 = at + 150;
|
||||
flyGhost(from, seatOf(e.p, me), { kind: 'card', delay: at2, ms: 560, label: '👑', className: 'sp-fx-noble' });
|
||||
later(at2, () => showBanner('👑 귀족 방문!', 'gold', `${NOBLE_NAME[e.nobleId] ?? '귀족'} → ${e.p === me ? '나' : `${nick(players, e.p)}님`} (+3점)`));
|
||||
spSfx.noble(at2);
|
||||
later(at2 + 560, () => bump(seatOf(e.p, me)));
|
||||
t += 700;
|
||||
break;
|
||||
}
|
||||
case 'end':
|
||||
// The game may already be over (last turn of the round): the finish banner below covers it.
|
||||
if (v.phase !== 'finished')
|
||||
later(at, () => {
|
||||
showBanner('🏁 마지막 라운드!', 'blue', `${e.p === me ? '내가' : `${nick(players, e.p)}님이`} ${e.points}점에 도달했어요`);
|
||||
sfx.fanfare();
|
||||
});
|
||||
t += 900;
|
||||
break;
|
||||
case 'pass':
|
||||
later(at, sfx.whoosh);
|
||||
break;
|
||||
case 'concede':
|
||||
later(at, sfx.bad);
|
||||
bump(seatOf(e.p, me), 'shake');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Market refill: the new card deals in from its deck and turns face up.
|
||||
useLayoutEffect(() => {
|
||||
const now: Record<string, string | null> = {};
|
||||
for (const t of TIERS_DOWN) v.board[t].forEach((c, i) => (now[`b${t}-${i}`] = c?.id ?? null));
|
||||
const before = prevBoard.current;
|
||||
prevBoard.current = now;
|
||||
if (!before) return;
|
||||
let n = 0;
|
||||
for (const t of TIERS_DOWN)
|
||||
v.board[t].forEach((c, i) => {
|
||||
const k = `b${t}-${i}`;
|
||||
if (!c || before[k] === c.id || before[k] === undefined) return;
|
||||
const delay = 260 + n * 120;
|
||||
flyFrom(fxEl(`sp-slot-${k}`), fxEl(`sp-deck-${t}`), { delay, ms: 420, rotate: 8, scale: 0.7 });
|
||||
spSfx.flip(delay + 380);
|
||||
n++;
|
||||
});
|
||||
}, [v.board]);
|
||||
|
||||
// Game over (results and win/lose sounds come from the room page; this is the on-board moment).
|
||||
useChange(v.phase, (now) => {
|
||||
if (now !== 'finished' || !v.result) return;
|
||||
const w = v.result.winners;
|
||||
const sub = w.length ? (w.includes(me ?? '') && w.length === 1 ? '내가 이겼어요!' : `${w.map((p) => nick(players, p)).join(', ')}님 승리`) : undefined;
|
||||
later(700, () => showBanner('게임 끝', 'gold', sub));
|
||||
});
|
||||
}
|
||||
|
||||
function MyArea({
|
||||
v,
|
||||
pv,
|
||||
@@ -907,7 +1109,7 @@ function MyArea({
|
||||
}) {
|
||||
const turn = v.current === me;
|
||||
return (
|
||||
<section className="sp-mine" aria-label="내 자리" style={{ border: `3px solid ${turn ? 'var(--focus)' : 'transparent'}` }}>
|
||||
<section className={`sp-mine${turn && v.phase !== 'finished' ? ' anim-glow' : ''}`} aria-label="내 자리" data-fx="sp-mine" style={{ border: `3px solid ${turn ? 'var(--focus)' : 'transparent'}` }}>
|
||||
<div className="sp-mine-head">
|
||||
<strong>
|
||||
나 · <span style={{ fontSize: '1.2rem' }}>{pv.points}점</span>
|
||||
@@ -919,7 +1121,7 @@ function MyArea({
|
||||
</div>
|
||||
<div className="sp-cols" role="list" aria-label="색별 보너스와 보석">
|
||||
{TOKEN_COLORS.map((c) => (
|
||||
<div key={c} className="sp-col" role="listitem" aria-label={c === 'gold' ? `황금 ${pv.tokens.gold}개` : `${NAME[c]}: 보너스 ${pv.bonuses[c as Color]}, 보석 ${pv.tokens[c]}개`}>
|
||||
<div key={c} className="sp-col" data-fx={`sp-tok-${c}`} role="listitem" aria-label={c === 'gold' ? `황금 ${pv.tokens.gold}개` : `${NAME[c]}: 보너스 ${pv.bonuses[c as Color]}, 보석 ${pv.tokens[c]}개`}>
|
||||
<Gem c={c} size={20} />
|
||||
<span className="bn" aria-hidden>
|
||||
{c === 'gold' ? '황금' : `할인 ${pv.bonuses[c as Color]}`}
|
||||
@@ -930,14 +1132,14 @@ function MyArea({
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="sp-reserved" role="group" aria-label={`내 예약 카드 ${pv.reservedCount}장`}>
|
||||
<div className="sp-reserved" role="group" aria-label={`내 예약 카드 ${pv.reservedCount}장`} data-fx="sp-reserved">
|
||||
<span className="small muted">예약 {pv.reservedCount}/3</span>
|
||||
{pv.reserved.map((r, i) => {
|
||||
if (r.hidden) return null;
|
||||
const card = r as Extract<ReservedView, { hidden: false }>;
|
||||
const key = `r${i}`;
|
||||
return (
|
||||
<button key={key} type="button" className={cardClass(key, ' mini')} data-b={card.bonus} aria-label={`예약 카드: ${cardAria(card, key)}${card.blind ? ' (더미에서 안 보고 예약)' : ''}`} aria-pressed={sel ? selKey(sel) === key : false} onClick={() => onPick(i)}>
|
||||
<button key={key} type="button" className={cardClass(key, ' mini')} data-b={card.bonus} data-fx-res={card.id} aria-label={`예약 카드: ${cardAria(card, key)}${card.blind ? ' (더미에서 안 보고 예약)' : ''}`} aria-pressed={sel ? selKey(sel) === key : false} onClick={() => onPick(i)}>
|
||||
<CardFace card={card} />
|
||||
{flag(key)}
|
||||
</button>
|
||||
@@ -954,7 +1156,7 @@ function PlayerDetail({ pv, name }: { pv: SplendorPlayerView; name: string }) {
|
||||
<div className="stack" style={{ gap: 6 }}>
|
||||
<div className="sp-mini-cols" role="list" aria-label={`${name}의 보너스와 보석`}>
|
||||
{TOKEN_COLORS.map((c) => (
|
||||
<span key={c} role="listitem" aria-label={c === 'gold' ? `황금 ${pv.tokens.gold}개` : `${NAME[c]} 보너스 ${pv.bonuses[c as Color]}, 보석 ${pv.tokens[c]}개`}>
|
||||
<span key={c} role="listitem" data-fx-tok={c} aria-label={c === 'gold' ? `황금 ${pv.tokens.gold}개` : `${NAME[c]} 보너스 ${pv.bonuses[c as Color]}, 보석 ${pv.tokens[c]}개`}>
|
||||
<Gem c={c} size={15} />
|
||||
<span aria-hidden>{c === 'gold' ? '-' : `+${pv.bonuses[c as Color]}`}</span>
|
||||
<strong aria-hidden>{pv.tokens[c]}</strong>
|
||||
@@ -1029,7 +1231,7 @@ function SplendorSide({ view: v, me, players, act, deadline }: BoardProps<Splend
|
||||
const pv = v.players[p]!;
|
||||
const turn = v.current === p;
|
||||
return (
|
||||
<div key={p} className={`sp-player${turn ? ' turn' : ''}${pv.conceded ? ' gone' : ''}`}>
|
||||
<div key={p} className={`sp-player${turn ? ` turn${v.phase !== 'finished' ? ' anim-glow' : ''}` : ''}${pv.conceded ? ' gone' : ''}`} data-fx-seat={p}>
|
||||
<div className="row" style={{ gap: 8, flexWrap: 'nowrap' }}>
|
||||
<span className="muted small" style={{ width: 14 }} title={i === 0 ? '선 플레이어' : undefined}>
|
||||
{i === 0 ? '선' : i + 1}
|
||||
|
||||
Reference in New Issue
Block a user