루미큐브·다빈치 코드·마작·라스베가스·부루마불·요트 다이스 소리·애니메이션: 상대·컴퓨터 행동도 화면 변화로 한 번만 울림(처음 들어올 때·재접속은 조용), 타일 놓기·뒤집기, 주사위 굴림, 말 한 칸씩 이동, 점수 통 튀기, 큰 순간 배너
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import type { DiscardView, HandResultView, MahjongOptions, MahjongView, MeldView
|
||||
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 type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -30,9 +30,134 @@ const eulReul = (word: string) => {
|
||||
};
|
||||
const waitText = (ws: WaitView[]) => ws.map((w) => `${tileShort(w.kind)}(${w.left}장${w.yaku ? '' : ', 역 없음'})`).join(', ');
|
||||
|
||||
// ---------------------------------------------------------------- sounds (synthesized: bone/plastic tiles on felt)
|
||||
|
||||
const mjSound = {
|
||||
/** One tile knocking another / the table. */
|
||||
clack: (delay = 0, g = 1) => {
|
||||
noise(26, 0.15 * g, delay, 'highpass', 3200);
|
||||
tone(2100, 24, 'triangle', 0.06 * g, delay);
|
||||
tone(720, 42, 'sine', 0.08 * g, delay);
|
||||
},
|
||||
/** 타패: the tile lands in the river. */
|
||||
discard: () => {
|
||||
mjSound.clack(0, 1.15);
|
||||
noise(55, 0.07, 14, 'lowpass', 900);
|
||||
},
|
||||
/** 쯔모: a tile slid off the wall into the hand. */
|
||||
draw: () => {
|
||||
noise(60, 0.06, 0, 'bandpass', 1800, 0.7);
|
||||
mjSound.clack(55, 0.55);
|
||||
},
|
||||
/** Picking a tile up in my hand. */
|
||||
lift: () => tone(1700, 22, 'triangle', 0.05),
|
||||
/** 새 국: the wall washed and built (자라자라). */
|
||||
shuffle: () => {
|
||||
for (let i = 0; i < 16; i++) mjSound.clack(i * 42 + (i % 3) * 9, 0.35 + (i % 4) * 0.08);
|
||||
noise(520, 0.05, 0, 'lowpass', 700);
|
||||
},
|
||||
pon: () => {
|
||||
mjSound.clack(0);
|
||||
mjSound.clack(70);
|
||||
tone(560, 150, 'triangle', 0.13, 110, { slideTo: 400 });
|
||||
},
|
||||
chi: () => {
|
||||
[0, 50, 100].forEach((d) => mjSound.clack(d, 0.8));
|
||||
tone(784, 80, 'triangle', 0.1, 150);
|
||||
tone(1046, 110, 'triangle', 0.09, 210);
|
||||
},
|
||||
kan: () => {
|
||||
[0, 60, 120, 180].forEach((d) => mjSound.clack(d));
|
||||
tone(196, 280, 'sawtooth', 0.035, 220);
|
||||
tone(392, 240, 'triangle', 0.09, 220);
|
||||
},
|
||||
kita: () => {
|
||||
mjSound.clack(0, 0.9);
|
||||
tone(660, 90, 'triangle', 0.09, 60);
|
||||
},
|
||||
/** 리치: the 1,000-point stick put down, then a rising chime. */
|
||||
riichi: () => {
|
||||
tone(1600, 26, 'square', 0.035);
|
||||
noise(32, 0.12, 0, 'highpass', 3600);
|
||||
tone(1046, 120, 'triangle', 0.1, 110);
|
||||
tone(1568, 220, 'triangle', 0.09, 210);
|
||||
},
|
||||
tsumo: () => {
|
||||
mjSound.clack(0, 1.3);
|
||||
[784, 988, 1175, 1568].forEach((f, i) => tone(f, 170, 'triangle', 0.12, 90 + i * 85));
|
||||
},
|
||||
ron: () => {
|
||||
mjSound.clack(0, 1.4);
|
||||
noise(140, 0.08, 0, 'lowpass', 500);
|
||||
[1046, 1318, 1568].forEach((f) => tone(f, 260, 'square', 0.035, 90));
|
||||
tone(2093, 380, 'triangle', 0.09, 220);
|
||||
},
|
||||
/** Points moving after a win. */
|
||||
payout: (delay = 0) => {
|
||||
for (let i = 0; i < 6; i++) tone(2200 + i * 130, 50, 'triangle', 0.045, delay + i * 45);
|
||||
},
|
||||
/** 유국. */
|
||||
ryuukyoku: () => [523, 440, 349].forEach((f, i) => tone(f, 200, 'sine', 0.11, i * 150)),
|
||||
/** A dora indicator turned over. */
|
||||
flip: (delay = 0) => {
|
||||
noise(60, 0.11, delay, 'highpass', 2500);
|
||||
tone(1400, 40, 'triangle', 0.05, delay + 10);
|
||||
},
|
||||
/** A call / ron window opened for me. */
|
||||
prompt: (ron: boolean) => {
|
||||
if (ron) [1318, 1760, 1318, 1760].forEach((f, i) => tone(f, 80, 'triangle', 0.1, i * 85));
|
||||
else {
|
||||
tone(988, 70, 'triangle', 0.1);
|
||||
tone(1318, 100, 'triangle', 0.09, 75);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const CALL_SOUND: Record<string, () => void> = { pon: mjSound.pon, chi: mjSound.chi, kan: mjSound.kan, kita: mjSound.kita, riichi: mjSound.riichi, tsumo: mjSound.tsumo, ron: mjSound.ron };
|
||||
|
||||
/** One id for a hand from its deal through its result screen (handsPlayed goes up when the hand ends). */
|
||||
const handId = (v: MahjongView) => (v.phase === 'playing' ? v.handsPlayed : v.handsPlayed - 1);
|
||||
|
||||
/** What was already on the table when this screen opened, so only things added later animate (not a reconnect's whole table). */
|
||||
interface Seen {
|
||||
hand: number;
|
||||
disc: number[];
|
||||
melds: number[];
|
||||
kita: number[];
|
||||
riichi: boolean[];
|
||||
dora: number;
|
||||
}
|
||||
function useSeen(v: MahjongView): Seen | null {
|
||||
const [s] = useState<Seen>(() => ({
|
||||
hand: handId(v),
|
||||
disc: v.seats.map((x) => x.discards.length),
|
||||
melds: v.seats.map((x) => x.melds.length),
|
||||
kita: v.seats.map((x) => x.kita.length),
|
||||
riichi: v.seats.map((x) => x.riichi),
|
||||
dora: v.doraIndicators.length,
|
||||
}));
|
||||
// A later hand: everything in it is new.
|
||||
return s.hand === handId(v) ? s : null;
|
||||
}
|
||||
|
||||
/** A number that pops when it changes (not on the first render). */
|
||||
function Bump({ value, children }: { value: number; children?: ReactNode }) {
|
||||
const prev = useRef(value);
|
||||
const moved = useRef(false);
|
||||
if (prev.current !== value) {
|
||||
prev.current = value;
|
||||
moved.current = true;
|
||||
}
|
||||
return (
|
||||
<span key={value} className={moved.current ? 'anim-bump' : undefined} style={{ display: 'inline-block' }}>
|
||||
{children ?? fmt(value)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const CSS = `
|
||||
.game-main:has(> .mj) { justify-content: flex-start; }
|
||||
.mj { width: 100%; max-width: 1080px; display: flex; flex-direction: column; gap: 8px; align-self: center; }
|
||||
.mj { position: relative; width: 100%; max-width: 1080px; display: flex; flex-direction: column; gap: 8px; align-self: center; }
|
||||
.mj.wide { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: 'table side' 'me me'; align-items: start; gap: 8px 12px; }
|
||||
.mj.wide .mj-opps { grid-area: side; flex-direction: column; flex-wrap: nowrap; }
|
||||
.mj.wide .mj-seat { max-width: none; flex: none; }
|
||||
@@ -80,7 +205,26 @@ const CSS = `
|
||||
.mj-edge.r { right: 3px; top: 50%; transform: translateY(-50%) rotate(180deg); writing-mode: vertical-rl; text-orientation: sideways; padding: 6px 0; }
|
||||
.mj-edge.l { left: 3px; top: 50%; transform: translateY(-50%); writing-mode: vertical-rl; text-orientation: sideways; padding: 6px 0; }
|
||||
.mj-callout { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; background: #b91c1c; color: #fff; font-weight: 900;
|
||||
font-size: 2rem; padding: 4px 18px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.35); pointer-events: none; animation: mj-pop .35s ease; white-space: nowrap; }
|
||||
font-size: 2rem; padding: 4px 18px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.35); pointer-events: none; animation: mj-call 1.3s ease both; white-space: nowrap; }
|
||||
.mj-callout.c-riichi { background: #f59e0b; color: #1c1e21; text-shadow: none; }
|
||||
.mj-callout.c-chi { background: #15803d; }
|
||||
.mj-callout.c-kan { background: #6d28d9; }
|
||||
.mj-callout.c-kita { background: #1d4ed8; }
|
||||
/* 론·쯔모·유국: over the whole board (the table is hidden on the PC result screen). */
|
||||
.mj-banner { position: absolute; left: 0; right: 0; top: 18%; z-index: 20; display: flex; justify-content: center; pointer-events: none; }
|
||||
.mj-banner > span { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 3.2rem; font-weight: 900; line-height: 1.1; color: #fff; background: #b91c1c;
|
||||
padding: 8px 34px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.4); text-shadow: 0 2px 4px rgba(0,0,0,.35); white-space: nowrap; border: 3px solid #fde047; }
|
||||
.mj-banner.tsumo > span { background: linear-gradient(160deg, #f59e0b, #b45309); }
|
||||
.mj-banner.draw > span { background: #334155; border-color: #94a3b8; font-size: 2.2rem; }
|
||||
.mj-banner.final > span { background: linear-gradient(160deg, #15803d, #14532d); font-size: 2.4rem; }
|
||||
.mj-banner small { font-size: 1rem; font-weight: 800; }
|
||||
/* 타패: the newest tile lands in the river from its owner's side (ponds are rotated, so +Y is always toward the owner). */
|
||||
.mj-toss { animation: mj-toss .34s cubic-bezier(.25,.8,.35,1.25) both; }
|
||||
@keyframes mj-toss { 0% { transform: translateY(calc(var(--tw) * 1.3)) scale(1.3); opacity: 0; } 55% { opacity: 1; } 100% { transform: none; } }
|
||||
.mj-drawn { animation: mj-draw .3s ease-out both; animation-delay: var(--anim-delay, 0ms); }
|
||||
@keyframes mj-draw { from { transform: translateY(-24px) rotate(6deg); opacity: 0; } }
|
||||
.mj-edge .stick.new { animation: mj-stick .45s cubic-bezier(.3,1.5,.5,1) both; }
|
||||
@keyframes mj-stick { from { transform: translateY(-14px) scale(1.7); opacity: 0; } }
|
||||
.mj-panel { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.mj-panel.claim { border: 3px solid var(--primary); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
|
||||
.mj-panel.win { border: 3px solid var(--success); }
|
||||
@@ -118,10 +262,11 @@ const CSS = `
|
||||
.mj-toggles input { width: 22px; height: 22px; }
|
||||
.mj-hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 220px; overflow: auto; font-size: .85rem; }
|
||||
.mj-rules td, .mj-rules th { padding: 3px 6px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
|
||||
@keyframes mj-pop { 0% { transform: translate(-50%, -50%) scale(.5); opacity: 0; } 70% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); } }
|
||||
@keyframes mj-call { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 14% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 24% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1.04); opacity: 0; } }
|
||||
@keyframes mj-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.mj-callout, .mj-win-btn { animation: none; }
|
||||
/* Banners stay readable (shown still, removed by their timer) instead of fading out at once. */
|
||||
.mj-callout, .mj-win-btn, .mj-banner .anim-banner { animation: none; }
|
||||
.mj-htile { transition: none; }
|
||||
}
|
||||
@media (max-width: 719px) {
|
||||
@@ -129,6 +274,8 @@ const CSS = `
|
||||
.mj-seat { padding: 4px 6px; font-size: .8rem; flex-basis: 30%; }
|
||||
.mj-table { border-width: 5px; padding: 4px; border-radius: 16px; }
|
||||
.mj-callout { font-size: 1.5rem; }
|
||||
.mj-banner > span { font-size: 2.3rem; padding: 6px 22px; }
|
||||
.mj-banner.draw > span, .mj-banner.final > span { font-size: 1.7rem; }
|
||||
.mj-actions .btn { min-height: 48px; }
|
||||
}
|
||||
`;
|
||||
@@ -179,9 +326,9 @@ function meldLabel(m: MeldView): string {
|
||||
return `${name} ${m.tiles.map(tileShort).join(' ')}`;
|
||||
}
|
||||
|
||||
function Meld({ m, w }: { m: MeldView; w: number }) {
|
||||
function Meld({ m, w, fresh }: { m: MeldView; w: number; fresh?: boolean }) {
|
||||
return (
|
||||
<span className="mj-meld" role="img" aria-label={meldLabel(m)}>
|
||||
<span className={`mj-meld${fresh ? ' anim-pop' : ''}`} role="img" aria-label={meldLabel(m)}>
|
||||
{m.tiles.map((t, i) => {
|
||||
const hidden = m.type === 'ankan' && (i === 0 || i === 3);
|
||||
const side = m.called !== null && t === m.called && m.type !== 'ankan';
|
||||
@@ -191,17 +338,19 @@ function Meld({ m, w }: { m: MeldView; w: number }) {
|
||||
);
|
||||
}
|
||||
|
||||
function Melds({ s, w }: { s: Pick<SeatView, 'melds' | 'kita'>; w: number }) {
|
||||
/** `seen`: how many melds / 북 were already there when the screen opened (later ones pop in). */
|
||||
function Melds({ s, w, seen }: { s: Pick<SeatView, 'melds' | 'kita'>; w: number; seen?: [number, number] }) {
|
||||
if (s.melds.length === 0 && s.kita.length === 0) return null;
|
||||
const [m0, k0] = seen ?? [Infinity, Infinity];
|
||||
return (
|
||||
<div className="mj-melds">
|
||||
{s.melds.map((m, i) => (
|
||||
<Meld key={i} m={m} w={w} />
|
||||
<Meld key={i} m={m} w={w} fresh={i >= m0} />
|
||||
))}
|
||||
{s.kita.length > 0 && (
|
||||
<span className="mj-meld" role="img" aria-label={`북 뽑기 ${s.kita.length}장`}>
|
||||
{s.kita.map((t) => (
|
||||
<Tile key={t} code={t} w={w} />
|
||||
{s.kita.map((t, i) => (
|
||||
<Tile key={t} code={t} w={w} className={i >= k0 ? 'anim-pop' : undefined} />
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
@@ -211,6 +360,8 @@ function Melds({ s, w }: { s: Pick<SeatView, 'melds' | 'kita'>; w: number }) {
|
||||
|
||||
// ---------------------------------------------------------------- seats
|
||||
|
||||
const meldSeen = (seen: Seen | null, seat: number): [number, number] => (seen ? [seen.melds[seat] ?? 0, seen.kita[seat] ?? 0] : [0, 0]);
|
||||
|
||||
function seatLabel(v: MahjongView, s: SeatView, players: Record<string, PublicUser>, me: string | null): string {
|
||||
const parts = [`${POS_KO[relPos(v, s.seat)]}`, `${nick(players, s.id)}${s.id === me ? '(나)' : ''}`, `${WIND[s.wind]}${s.isDealer ? '(친)' : ''}`, `${fmt(s.points)}점`];
|
||||
if (s.riichi) parts.push('리치');
|
||||
@@ -223,11 +374,11 @@ function seatLabel(v: MahjongView, s: SeatView, players: Record<string, PublicUs
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
function SeatChip({ v, s, players, me, deadline, w }: { v: MahjongView; s: SeatView; players: Record<string, PublicUser>; me: string | null; deadline: number | null; w: number }) {
|
||||
function SeatChip({ v, s, players, me, deadline, w, seen }: { v: MahjongView; s: SeatView; players: Record<string, PublicUser>; me: string | null; deadline: number | null; w: number; seen: Seen | null }) {
|
||||
const u = userOf(players, s.id);
|
||||
const turn = v.phase === 'playing' && v.turn === s.seat && v.stage !== 'claim';
|
||||
return (
|
||||
<li className={`mj-seat${turn ? ' turn' : ''}${s.left ? ' gone' : ''}`} aria-label={seatLabel(v, s, players, me)}>
|
||||
<li className={`mj-seat${turn ? ' turn anim-glow' : ''}${s.left ? ' gone' : ''}`} aria-label={seatLabel(v, s, players, me)}>
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'nowrap' }} aria-hidden>
|
||||
<Avatar user={u} size={22} />
|
||||
<span className="nm">{u.nickname}</span>
|
||||
@@ -239,8 +390,10 @@ function SeatChip({ v, s, players, me, deadline, w }: { v: MahjongView; s: SeatV
|
||||
{WIND[s.wind]}
|
||||
{s.isDealer ? ' 친' : ''}
|
||||
</span>
|
||||
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>{fmt(s.points)}</strong>
|
||||
{s.riichi && <span className="mj-badge mj-b-riichi">리치</span>}
|
||||
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
|
||||
<Bump value={s.points} />
|
||||
</strong>
|
||||
{s.riichi && <span className={`mj-badge mj-b-riichi${seen?.riichi[s.seat] ? '' : ' anim-pop'}`}>리치</span>}
|
||||
{(s.away || s.left) && <span className="mj-badge mj-b-away">{s.left ? '나감' : '자리 비움'}</span>}
|
||||
{v.phase === 'playing' && (
|
||||
<span className="mj-back-count" title="손패 장수">
|
||||
@@ -249,14 +402,15 @@ function SeatChip({ v, s, players, me, deadline, w }: { v: MahjongView; s: SeatV
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<Melds s={s} w={w} />
|
||||
<Melds s={s} w={w} seen={meldSeen(seen, s.seat)} />
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- table
|
||||
|
||||
function Pond({ discards, tw, lastIndex }: { discards: DiscardView[]; tw: number; lastIndex: number | null }) {
|
||||
/** `fromIndex`: tiles from here on were discarded while watching and land with a toss. */
|
||||
function Pond({ discards, tw, lastIndex, fromIndex }: { discards: DiscardView[]; tw: number; lastIndex: number | null; fromIndex: number }) {
|
||||
const rows: DiscardView[][] = [];
|
||||
for (let i = 0; i < discards.length; i += 6) rows.push(discards.slice(i, i + 6));
|
||||
return (
|
||||
@@ -272,7 +426,7 @@ function Pond({ discards, tw, lastIndex }: { discards: DiscardView[]; tw: number
|
||||
w={tw}
|
||||
sideways={d.riichi}
|
||||
dim={d.called}
|
||||
className={idx === lastIndex ? 'last' : undefined}
|
||||
className={[idx === lastIndex ? 'last' : '', idx >= fromIndex ? 'mj-toss' : ''].filter(Boolean).join(' ') || undefined}
|
||||
label={`${tileName(d.tile)}${d.tsumogiri ? ', 쯔모기리' : ''}${d.riichi ? ', 리치 선언' : ''}${d.called ? ', 울려 감' : ''}`}
|
||||
/>
|
||||
);
|
||||
@@ -285,7 +439,7 @@ function Pond({ discards, tw, lastIndex }: { discards: DiscardView[]; tw: number
|
||||
|
||||
const ROT = [0, -90, 180, 90];
|
||||
|
||||
function Table({ v, players, width, callout }: { v: MahjongView; players: Record<string, PublicUser>; width: number; callout: ReactNode }) {
|
||||
function Table({ v, players, width, callout, seen }: { v: MahjongView; players: Record<string, PublicUser>; width: number; callout: ReactNode; seen: Seen | null }) {
|
||||
// Pond: 6 tiles per row (+ room for one sideways riichi tile) × 4 rows. Table = H + W + H.
|
||||
// Total width ≈ 2H + W + padding/border = 17·tw + 37.
|
||||
const tw = Math.max(14, Math.min(30, Math.floor((width - 37) / 17)));
|
||||
@@ -303,7 +457,7 @@ function Table({ v, players, width, callout }: { v: MahjongView; players: Record
|
||||
return (
|
||||
<div className="mj-cell" style={style} role="group" aria-label={`${nick(players, s.id)}님 버림패 ${s.discards.length}장`}>
|
||||
<div className={`mj-pond${turn ? ' turn' : ''}`} style={{ width: W, height: H, transform: `translate(-50%, -50%) rotate(${ROT[pos]}deg)` }}>
|
||||
<Pond discards={s.discards} tw={tw} lastIndex={lastIndex} />
|
||||
<Pond discards={s.discards} tw={tw} lastIndex={lastIndex} fromIndex={seen ? (seen.disc[s.seat] ?? 0) : 0} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -314,8 +468,8 @@ function Table({ v, players, width, callout }: { v: MahjongView; players: Record
|
||||
const turn = v.phase === 'playing' && v.turn === s.seat && v.stage !== 'claim';
|
||||
return (
|
||||
<span key={pos} className={`mj-edge ${['b', 'r', 't', 'l'][pos]}${turn ? ' turn' : ''}`} aria-hidden>
|
||||
{WIND[s.wind]} {fmt(s.points)}
|
||||
{s.riichi && <i className="stick" />}
|
||||
{WIND[s.wind]} <Bump value={s.points} />
|
||||
{s.riichi && <i className={`stick${seen?.riichi[s.seat] ? '' : ' new'}`} />}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -334,12 +488,12 @@ function Table({ v, players, width, callout }: { v: MahjongView; players: Record
|
||||
<div className="mj-center" style={{ width: W, height: W }}>
|
||||
<span className="rl">{roundLabel(v).split(' ')[0]}</span>
|
||||
<span className="sub">
|
||||
{v.honba}본장 · 공탁 {v.riichiPool / 1000}개
|
||||
{v.honba}본장 · 공탁 <Bump value={v.riichiPool / 1000} />개
|
||||
</span>
|
||||
<span className="sub">남은 패 {v.wallCount}</span>
|
||||
<div className="mj-dora" title="도라 표시패">
|
||||
{v.doraIndicators.map((t) => (
|
||||
<Tile key={t} code={t} w={dw} />
|
||||
{v.doraIndicators.map((t, i) => (
|
||||
<Tile key={t} code={t} w={dw} className={i >= (seen?.dora ?? 0) ? 'anim-flip' : undefined} style={{ '--anim-delay': '120ms' } as CSSProperties} />
|
||||
))}
|
||||
{Array.from({ length: Math.max(0, 5 - v.doraIndicators.length) }, (_, i) => (
|
||||
<Tile key={`b${i}`} code={null} w={dw} />
|
||||
@@ -358,7 +512,28 @@ function Table({ v, players, width, callout }: { v: MahjongView; players: Record
|
||||
|
||||
// ---------------------------------------------------------------- my hand
|
||||
|
||||
function MyArea({ v, my, act, pending, players, deadline, tapConfirm }: { v: MahjongView; my: MyView; act: (a: unknown) => void; pending: boolean; players: Record<string, PublicUser>; deadline: number | null; tapConfirm: boolean }) {
|
||||
function MyArea({
|
||||
v,
|
||||
my,
|
||||
act,
|
||||
pending,
|
||||
players,
|
||||
deadline,
|
||||
tapConfirm,
|
||||
seen,
|
||||
dealing,
|
||||
}: {
|
||||
v: MahjongView;
|
||||
my: MyView;
|
||||
act: (a: unknown) => void;
|
||||
pending: boolean;
|
||||
players: Record<string, PublicUser>;
|
||||
deadline: number | null;
|
||||
tapConfirm: boolean;
|
||||
seen: Seen | null;
|
||||
/** A new hand was just dealt: the hand tiles fly in one by one. */
|
||||
dealing: boolean;
|
||||
}) {
|
||||
const [sel, setSel] = useState<string | null>(null);
|
||||
const [riichiMode, setRiichiMode] = useState(false);
|
||||
const [kanPick, setKanPick] = useState(false);
|
||||
@@ -395,12 +570,16 @@ function MyArea({ v, my, act, pending, players, deadline, tapConfirm }: { v: Mah
|
||||
const tap = (code: string) => {
|
||||
if (!myTurn || pending) return;
|
||||
if (!legal.has(code)) {
|
||||
sounds.warn();
|
||||
setNote(locked.has(code) ? `${tileShort(code)}: 방금 울은 패와 같은 패(또는 스지)라 버릴 수 없어요.` : riichiMode ? '이 패를 버리면 텐파이가 아니라 리치할 수 없어요.' : my.riichi ? '리치 후에는 쯔모한 패만 버릴 수 있어요.' : '지금은 버릴 수 없어요.');
|
||||
return;
|
||||
}
|
||||
setNote('');
|
||||
if (sel === code || !tapConfirm) send(code);
|
||||
else setSel(code);
|
||||
else {
|
||||
mjSound.lift();
|
||||
setSel(code);
|
||||
}
|
||||
};
|
||||
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
||||
@@ -415,7 +594,7 @@ function MyArea({ v, my, act, pending, players, deadline, tapConfirm }: { v: Mah
|
||||
const selAfter = sel ? my.tenpaiAfter[sel] : undefined;
|
||||
const winNow = my.canTsumo;
|
||||
return (
|
||||
<div className="mj-panel mj-me" aria-label="내 패">
|
||||
<div className={`mj-panel mj-me${myTurn ? ' anim-glow' : ''}`} aria-label="내 패">
|
||||
<div className="mj-myhead">
|
||||
<div className="row" style={{ gap: 6 }}>
|
||||
<strong>내 패</strong>
|
||||
@@ -423,14 +602,16 @@ function MyArea({ v, my, act, pending, players, deadline, tapConfirm }: { v: Mah
|
||||
{WIND[me.wind]}
|
||||
{me.isDealer ? ' 친' : ''}
|
||||
</span>
|
||||
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>{fmt(me.points)}점</strong>
|
||||
{my.riichi && <span className="mj-badge mj-b-riichi">리치</span>}
|
||||
<strong style={{ fontVariantNumeric: 'tabular-nums' }}>
|
||||
<Bump value={me.points} />점
|
||||
</strong>
|
||||
{my.riichi && <span className={`mj-badge mj-b-riichi${seen?.riichi[my.seat] ? '' : ' anim-pop'}`}>리치</span>}
|
||||
{my.furiten && <span className="mj-badge mj-b-furiten">{beginner ? '후리텐: 론 불가, 쯔모만 가능' : '후리텐'}</span>}
|
||||
{my.autoPilot && <span className="mj-badge mj-b-away">자리 비움 · 아무 패나 누르면 돌아와요</span>}
|
||||
</div>
|
||||
{myTurn && <TurnTimer deadline={deadline} totalMs={v.deadlineTotalMs} mine size={36} />}
|
||||
</div>
|
||||
<Melds s={me} w={meldW} />
|
||||
<Melds s={me} w={meldW} seen={meldSeen(seen, my.seat)} />
|
||||
<div ref={ref} className="mj-hand" role="group" aria-label="내 손패. 좌우 방향키로 고르고 Enter로 고른 뒤 한 번 더 누르면 버려요" onKeyDown={onKey}>
|
||||
{all.map((code, i) => {
|
||||
const isDrawn = my.drawn === code && i === n - 1;
|
||||
@@ -453,7 +634,12 @@ function MyArea({ v, my, act, pending, players, deadline, tapConfirm }: { v: Mah
|
||||
텐
|
||||
</span>
|
||||
)}
|
||||
<Tile code={code} w={tw} />
|
||||
<Tile
|
||||
code={code}
|
||||
w={tw}
|
||||
className={isDrawn ? 'mj-drawn' : dealing ? 'anim-deal' : undefined}
|
||||
style={dealing ? ({ '--anim-delay': `${i * 30}ms`, '--from-y': '-70px' } as CSSProperties) : undefined}
|
||||
/>
|
||||
{locked.has(code) && (
|
||||
<span className="lock" aria-hidden>
|
||||
🔒
|
||||
@@ -643,7 +829,7 @@ function WinnerBlock({ w, v, players }: { w: WinnerView; v: MahjongView; players
|
||||
const limit = LIMIT_KO[w.limit] ?? '';
|
||||
const yakumanTotal = w.yakuman;
|
||||
return (
|
||||
<div className="mj-panel win">
|
||||
<div className="mj-panel win anim-slide-up">
|
||||
<strong style={{ fontSize: '1.1rem' }}>
|
||||
🀄 {name}님 {how}
|
||||
</strong>
|
||||
@@ -739,8 +925,8 @@ function ResultPanel({ v, players, me, act, pending, deadline }: { v: MahjongVie
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{v.seats.map((s) => (
|
||||
<tr key={s.seat}>
|
||||
{v.seats.map((s, i) => (
|
||||
<tr key={s.seat} className="anim-slide-up" style={{ '--anim-delay': `${250 + i * 90}ms` } as CSSProperties}>
|
||||
<td>
|
||||
{WIND[s.wind]} {nick(players, s.id)}
|
||||
{s.id === me ? ' (나)' : ''}
|
||||
@@ -782,8 +968,8 @@ function FinalPanel({ v, players, me }: { v: MahjongView; players: Record<string
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{f.ranking.map((r) => (
|
||||
<tr key={r.player}>
|
||||
{f.ranking.map((r, i) => (
|
||||
<tr key={r.player} className="anim-slide-up" style={{ '--anim-delay': `${i * 110}ms` } as CSSProperties}>
|
||||
<td>{r.rank}위</td>
|
||||
<td>
|
||||
{nick(players, r.player)}
|
||||
@@ -840,30 +1026,123 @@ function FinalPanel({ v, players, me }: { v: MahjongView; players: Record<string
|
||||
|
||||
// ---------------------------------------------------------------- board
|
||||
|
||||
/** Public facts compared between views to play sounds (only what everyone can see, plus my own hand/prompt). */
|
||||
interface Snap {
|
||||
hand: number;
|
||||
phase: MahjongView['phase'];
|
||||
disc: number[];
|
||||
dora: number;
|
||||
call: number;
|
||||
drawn: string | null;
|
||||
claim: string | null;
|
||||
canDiscard: boolean;
|
||||
}
|
||||
const snapOf = (v: MahjongView): Snap => ({
|
||||
hand: handId(v),
|
||||
phase: v.phase,
|
||||
disc: v.seats.map((s) => s.discards.length),
|
||||
dora: v.doraIndicators.length,
|
||||
call: v.lastCall?.seq ?? -1,
|
||||
drawn: v.my?.drawn ?? null,
|
||||
claim: v.my?.claim && !v.my.claim.responded ? `${v.seq}:${v.my.claim.tile}` : null,
|
||||
canDiscard: !!v.my?.canDiscard,
|
||||
});
|
||||
|
||||
type Banner = { key: number; kind: 'ron' | 'tsumo' | 'draw' | 'final'; text: string; sub?: string };
|
||||
|
||||
function MahjongBoard({ view: v, me, players, act, pending, deadline, tapConfirm }: BoardProps<MahjongView>) {
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const [callout, setCallout] = useState<{ seq: number; text: string } | null>(null);
|
||||
const [callout, setCallout] = useState<{ seq: number; text: string; call: string } | null>(null);
|
||||
const [banner, setBanner] = useState<Banner | null>(null);
|
||||
const [dealing, setDealing] = useState(false);
|
||||
const [ref, width, mainH] = useBox<HTMLDivElement>();
|
||||
const seen = useSeen(v);
|
||||
const mine = isMyTurn(v, me);
|
||||
const prevMine = useRef(false);
|
||||
const snap = useRef<Snap | null>(null);
|
||||
const bannerSeq = useRef(0);
|
||||
const showBanner = (b: Omit<Banner, 'key'>) => setBanner({ ...b, key: ++bannerSeq.current });
|
||||
|
||||
// Sounds follow the view (my own clicks too), so nothing plays twice; the first view only sets the baseline.
|
||||
useEffect(() => {
|
||||
const prev = snap.current;
|
||||
const cur = snapOf(v);
|
||||
snap.current = cur;
|
||||
if (!prev) return;
|
||||
const call = cur.call !== prev.call ? v.lastCall : null;
|
||||
if (call) {
|
||||
CALL_SOUND[call.call]?.();
|
||||
const who = nick(players, v.seats[call.seat]!.id);
|
||||
setAnnounce(`${who}님 ${CALL_KO[call.call]?.replace('!', '') ?? ''}`);
|
||||
if (call.call === 'ron' || call.call === 'tsumo') {
|
||||
const many = (v.result?.winners.length ?? 1) > 1;
|
||||
showBanner({ kind: call.call, text: many ? `${v.result!.winners.length}명 론!` : CALL_KO[call.call]!, sub: many ? undefined : who });
|
||||
} else setCallout({ seq: call.seq, text: `${who} ${CALL_KO[call.call] ?? ''}`, call: call.call });
|
||||
}
|
||||
if (cur.phase === 'finished') {
|
||||
if (prev.phase === 'finished') return;
|
||||
const top = v.final?.ranking[0];
|
||||
// Players hear the win/lose sound from the room page's result panel; spectators get a fanfare here.
|
||||
if (!(me && v.final?.ranking.some((r) => r.player === me))) sfx.fanfare();
|
||||
if (top) showBanner({ kind: 'final', text: `🏆 ${top.player === me ? '내가' : `${nick(players, top.player)}님`} 1위!`, sub: `${fmt(top.points)}점` });
|
||||
return;
|
||||
}
|
||||
if (cur.phase === 'handResult') {
|
||||
if (prev.phase !== 'handResult' && v.result) {
|
||||
if (v.result.kind === 'agari') mjSound.payout(call ? 950 : 0);
|
||||
else {
|
||||
mjSound.ryuukyoku();
|
||||
showBanner({ kind: 'draw', text: v.result.kind === 'exhaustive' ? '유국' : '도중유국', sub: v.result.kind === 'abortive' ? ABORT_KO[v.result.abortiveReason ?? ''] : undefined });
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cur.phase !== 'playing') return;
|
||||
const newHand = prev.phase !== 'playing' || prev.hand !== cur.hand;
|
||||
if (newHand) mjSound.shuffle();
|
||||
else {
|
||||
if (cur.disc.some((n, i) => n > (prev.disc[i] ?? 0))) mjSound.discard();
|
||||
if (cur.dora > prev.dora) mjSound.flip(150);
|
||||
if (cur.drawn && cur.drawn !== prev.drawn) mjSound.draw();
|
||||
}
|
||||
if (cur.claim && cur.claim !== prev.claim) mjSound.prompt(!!v.my?.claim?.ron);
|
||||
// My turn to discard (not right after my own call — that already made its sound).
|
||||
else if (cur.canDiscard && !prev.canDiscard && !(call && call.seat === v.my?.seat)) sounds.myTurn();
|
||||
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// A new hand dealt while watching: my tiles fly in (not on the first view).
|
||||
const hand = handId(v);
|
||||
const firstHand = useRef(hand);
|
||||
useEffect(() => {
|
||||
if (v.phase !== 'playing' || hand === firstHand.current) return;
|
||||
firstHand.current = hand;
|
||||
setDealing(true);
|
||||
}, [hand, v.phase]);
|
||||
useEffect(() => {
|
||||
if (!dealing) return;
|
||||
const t = setTimeout(() => setDealing(false), 900);
|
||||
return () => clearTimeout(t);
|
||||
}, [dealing]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!banner) return;
|
||||
const t = setTimeout(() => setBanner((b) => (b && b.key === banner.key ? null : b)), 1700);
|
||||
return () => clearTimeout(t);
|
||||
}, [banner]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mine && !prevMine.current) {
|
||||
haptic(40);
|
||||
sounds.myTurn();
|
||||
if (v.my?.claim) setAnnounce(v.my.claim.ron ? '론할 수 있어요!' : '울 수 있어요. 고르거나 패스해 주세요.');
|
||||
else if (v.phase === 'playing') setAnnounce(v.my?.canTsumo ? '내 차례예요. 쯔모할 수 있어요!' : '내 차례예요.');
|
||||
}
|
||||
prevMine.current = mine;
|
||||
}, [mine]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useEffect(() => {
|
||||
const c = v.lastCall;
|
||||
if (!c) return;
|
||||
const text = `${nick(players, v.seats[c.seat]!.id)} ${CALL_KO[c.call] ?? ''}`;
|
||||
setCallout({ seq: c.seq, text });
|
||||
setAnnounce(`${nick(players, v.seats[c.seat]!.id)}님 ${CALL_KO[c.call]?.replace('!', '') ?? ''}`);
|
||||
const t = setTimeout(() => setCallout((x) => (x && x.seq === c.seq ? null : x)), 1300);
|
||||
if (!callout) return;
|
||||
const t = setTimeout(() => setCallout((x) => (x && x.seq === callout.seq ? null : x)), 1300);
|
||||
return () => clearTimeout(t);
|
||||
}, [v.lastCall?.seq]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [callout]);
|
||||
useEffect(() => {
|
||||
if (v.claimOn && v.claimOn.source === 'discard' && v.claimOn.from !== v.my?.seat) setAnnounce(`${nick(players, v.seats[v.claimOn.from]!.id)}님이 ${eulReul(tileName(v.claimOn.tile))} 버렸어요.`);
|
||||
}, [v.claimOn?.tile, v.claimOn?.from]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
@@ -881,7 +1160,7 @@ function MahjongBoard({ view: v, me, players, act, pending, deadline, tapConfirm
|
||||
<style>{CSS}</style>
|
||||
<ul className="mj-opps" aria-label="다른 사람">
|
||||
{others.map((s) => (
|
||||
<SeatChip key={s.seat} v={v} s={s} players={players} me={me} deadline={deadline} w={phone ? 13 : 18} />
|
||||
<SeatChip key={s.seat} v={v} s={s} players={players} me={me} deadline={deadline} w={phone ? 13 : 18} seen={seen} />
|
||||
))}
|
||||
</ul>
|
||||
<div className="mj-main" style={wide ? { width: tableWidth, maxHeight: mainH > 0 ? mainH - 12 : undefined } : undefined}>
|
||||
@@ -889,11 +1168,19 @@ function MahjongBoard({ view: v, me, players, act, pending, deadline, tapConfirm
|
||||
{v.phase === 'finished' && <FinalPanel v={v} players={players} me={me} />}
|
||||
{showTable && (
|
||||
<div className="mj-table-wrap">
|
||||
<Table v={v} players={players} width={tableWidth} callout={callout ? <span key={callout.seq} className="mj-callout">{callout.text}</span> : null} />
|
||||
<Table v={v} players={players} width={tableWidth} callout={callout ? <span key={callout.seq} className={`mj-callout c-${callout.call}`}>{callout.text}</span> : null} seen={seen} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{v.phase === 'playing' && v.my && <MyArea v={v} my={v.my} act={act} pending={pending} players={players} deadline={deadline} tapConfirm={tapConfirm} />}
|
||||
{v.phase === 'playing' && v.my && <MyArea v={v} my={v.my} act={act} pending={pending} players={players} deadline={deadline} tapConfirm={tapConfirm} seen={seen} dealing={dealing} />}
|
||||
{banner && (
|
||||
<div key={banner.key} className={`mj-banner ${banner.kind}`} aria-hidden>
|
||||
<span className="anim-banner">
|
||||
{banner.text}
|
||||
{banner.sub && <small>{banner.sub}</small>}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
@@ -962,7 +1249,7 @@ function MahjongSide({ view: v, me, players, deadline, act, pending }: BoardProp
|
||||
</span>
|
||||
)}
|
||||
<strong aria-hidden style={{ fontVariantNumeric: 'tabular-nums' }}>
|
||||
{fmt(s.points)}
|
||||
<Bump value={s.points} />
|
||||
</strong>
|
||||
</li>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user