움직임 더하기 2차: 루미큐브·마피아·라이어·바둑·클루·오목·포커
- 루미큐브: 옮긴 타일이 원래 자리에서 미끄러져 가고, 남이 바닥에 낸 타일은 그 사람 칸에서 날아옴. 가져온 타일은 남은 타일 더미에서 받침대로 날아오고, 남이 가져가면 뒤집힌 타일이 그 사람 칸으로 날아감. 배너를 공통 useBanner로 바꾸고 "루미큐브!"·"판 끝"·승리 배너 추가 - 마피아: 밤에는 화면이 남색으로 어두워지며 달, 아침에는 해가 떠오름. 득표 막대가 한 줄씩 자라고, 탈락한 사람 칸이 뒤집히며 흐려짐. 탈락·살았다·버텼다·조용한 밤·이긴 팀 배너를 차례로 - 라이어: 득표가 한 줄씩 나온 뒤 지목된 사람에게 스포트라이트와 흔들림, "잡았다!"/"헛다리!"·동점·정답/땡·승리 배너 - 바둑: 패스·계가 배너, 계가 때 집 표시가 차례로 나타나고 결과 점수가 0부터 올라감, 승리 배너 - 클루: 말과 흉기가 새 자리로 튀어 오르며 미끄러져 감, 추리한 세 장이 사건 봉투로 날아가고, 보여 준 카드는 뒤집히며(남에게는 뒷면 카드가 날아감) - 오목: 금수 자리를 누르면 빨간 ✕와 "금수" 글자, 판이 흔들림(키보드 Enter도 같은 안내). "오목!"·승패 배너 - 포커: 쇼다운·인디언 이마 카드가 뒷면이 돌아간 뒤 앞면이 돌아 나오는 진짜 뒤집기로 - 모두 누구의 행동이든 화면 변화에 반응하고, 클릭을 막지 않으며, 동작 줄이기 설정을 따름. 게임 문서 UI 절에 반영 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/** 루미큐브 화면 (docs/games/rummikub.md §9). Tap a tile to pick it up, then tap where it goes. */
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties } from 'react';
|
||||
// Pure tile/set helpers only (no zod): keeps this lazy chunk small.
|
||||
import { findMeld, normalizeSet, pickDisjoint, setProblem, sortTiles, tileLabel, tileOf, type DraftSet, type JokerAs, type TileColor } from '@bg/games/rummikub/rules';
|
||||
import type { LogEntry, RummikubOptions, RummikubView } from '@bg/games/rummikub';
|
||||
@@ -7,6 +7,7 @@ import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar, ConfirmSheet } from '../../components/ui';
|
||||
import { TurnTimer } from '../../components/TurnTimer';
|
||||
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import { bump, cssEsc, flyFrom, flyGhost, fxEl, seatEl, useBanner, useNewEntries } from '../card-fx';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -74,10 +75,9 @@ function Bump({ value, children }: { value: number; children: React.ReactNode })
|
||||
const CSS = `
|
||||
.rk-root { position: relative; width: 100%; align-self: stretch; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
|
||||
.rk-bump { display: inline-block; }
|
||||
.rk-banner { position: fixed; z-index: 40; top: 34%; left: 0; right: 0; margin: 0 auto; width: max-content; max-width: 92vw; text-align: center;
|
||||
padding: 12px 26px; border-radius: 18px; font-size: clamp(1.4rem, 5vw, 2.2rem); font-weight: 900; letter-spacing: -.01em;
|
||||
background: linear-gradient(#fffdf7, #f1e7cf); color: #111827; border: 2px solid #c9b98f; box-shadow: 0 4px 0 #b5a172, 0 12px 30px rgba(0,0,0,.35); }
|
||||
.rk-banner.big { background: linear-gradient(#fde68a, #f59e0b); border-color: #b45309; box-shadow: 0 4px 0 #92400e, 0 12px 30px rgba(0,0,0,.35); }
|
||||
/* A face-down tile flying from the pool to someone's seat (card-fx ghost). */
|
||||
.fx-ghost.rk-ghost { width: 30px; height: 42px; border-radius: 6px; background: linear-gradient(#fffdf7, #e8dcbc); border: 1px solid #c9b98f;
|
||||
box-shadow: 0 2px 0 #b5a172, 0 4px 8px rgba(0,0,0,.3); }
|
||||
.rk-players { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.rk-player { display: flex; align-items: center; gap: 6px; background: var(--surface); color: var(--text); border: 3px solid transparent;
|
||||
border-radius: 12px; padding: 4px 10px 4px 6px; box-shadow: var(--shadow); font-size: .9rem; min-height: 44px; }
|
||||
@@ -148,7 +148,6 @@ button.rk-tile:disabled { cursor: default; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.rk-tile { transition: none; }
|
||||
.rk-banner { display: none; }
|
||||
.rk-set.changed { animation: none; box-shadow: 0 0 0 3px #fde047; }
|
||||
}
|
||||
`;
|
||||
@@ -203,13 +202,13 @@ function Tile({ id, size = 'md', as, selected, hint, fresh, anim, style, onClick
|
||||
const dataC = t.kind === 'num' ? t.color : undefined;
|
||||
if (!onClick) {
|
||||
return (
|
||||
<span className={cls} data-c={dataC} role="img" aria-label={label} style={style}>
|
||||
<span className={cls} data-c={dataC} data-tile={id} role="img" aria-label={label} style={style}>
|
||||
{body}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<button type="button" className={cls} data-c={dataC} aria-pressed={!!selected} aria-label={label} onClick={onClick} style={style}>
|
||||
<button type="button" className={cls} data-c={dataC} data-tile={id} aria-pressed={!!selected} aria-label={label} onClick={onClick} style={style}>
|
||||
{body}
|
||||
</button>
|
||||
);
|
||||
@@ -257,13 +256,16 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const wasMine = useRef(false);
|
||||
const lastLog = useRef<string>('');
|
||||
// Animations: tiles flying onto my rack, tiles newly on the table, a shaking area, a big banner.
|
||||
// Animations: tiles dealt onto my rack, a shaking area, a big banner (tile flights use card-fx, see below).
|
||||
const [fly, setFly] = useTimed<{ ids: string[]; gap: number }>();
|
||||
const [pop, setPop] = useTimed<Set<string>>();
|
||||
const [shake, setShake] = useTimed<string>();
|
||||
const [banner, setBanner] = useTimed<{ text: string; big: boolean; seq: number }>();
|
||||
const bannerSeq = useRef(0);
|
||||
const showBanner = (text: string, big = false) => setBanner({ text, big, seq: ++bannerSeq.current }, 1700);
|
||||
const [banner, showBanner] = useBanner();
|
||||
/** Where the tiles I just moved were (captured on the tap), so they fly from there to their new place. */
|
||||
const movedFrom = useRef<Map<string, DOMRect> | null>(null);
|
||||
/** Who had the turn on the previous render: tiles that newly show up on the table come from that seat. */
|
||||
const prevCurrent = useRef(v.current);
|
||||
const winTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
||||
useEffect(() => () => clearTimeout(winTimer.current), []);
|
||||
const snap = useRef<{ log: string; gameNo: number; phase: string; turnNo: number; edits: number; melded: Record<string, boolean>; table: Set<string> } | null>(null);
|
||||
|
||||
const serverSets: DraftSet[] = useMemo(
|
||||
@@ -303,7 +305,8 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
}, [v.log]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// Sounds + animations for what everybody did, from view changes only (the first view is just recorded).
|
||||
useEffect(() => {
|
||||
// A layout effect, so tiles that just appeared can still be sent flying before they are painted in place.
|
||||
useLayoutEffect(() => {
|
||||
const e = v.log[v.log.length - 1];
|
||||
const now = {
|
||||
log: e ? `${v.match.gameNo}-${e.turn}-${e.kind}-${e.by}` : '',
|
||||
@@ -331,22 +334,20 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
const name = nick(players, e.by);
|
||||
if (e.kind === 'commit' || e.kind === 'timeoutCommit') {
|
||||
snd.places(e.count);
|
||||
const added = [...now.table].filter((id) => !prev.table.has(id));
|
||||
if (!mineMove && added.length) setPop(new Set(added), 900);
|
||||
const firstMeld = !prev.melded[e.by] && now.melded[e.by];
|
||||
if (mineMove || firstMeld) sfx.good();
|
||||
if (firstMeld && !(v.phase !== 'playing' && v.round?.endReason === 'rackEmpty')) showBanner(mineMove ? '첫 등록 성공!' : `${name}님 첫 등록!`);
|
||||
if (firstMeld && !(v.phase !== 'playing' && v.round?.endReason === 'rackEmpty')) showBanner('첫 등록!', 'green', mineMove ? '바닥에 처음 내려놓았어요' : `${name}님`);
|
||||
} else if (e.kind === 'draw' || e.kind === 'timeoutDraw') {
|
||||
snd.draw();
|
||||
if (mineMove && v.my?.lastDrawn.length) setFly({ ids: v.my.lastDrawn, gap: 90 }, 900);
|
||||
drawFx(e.by, mineMove ? (v.my?.lastDrawn ?? []) : [], e.count || 1, 90);
|
||||
} else if (e.kind === 'penalty') {
|
||||
sfx.bad();
|
||||
for (let i = 0; i < Math.min(e.count, 3); i++) snd.draw(250 + i * 160);
|
||||
setShake(mineMove ? 'rack' : `p:${e.by}`, 500);
|
||||
drawFx(e.by, mineMove ? (v.my?.lastDrawn ?? []) : [], e.count, 120);
|
||||
if (mineMove) {
|
||||
haptic([60, 40, 60]);
|
||||
if (v.my?.lastDrawn.length) setFly({ ids: v.my.lastDrawn, gap: 120 }, 1100);
|
||||
showBanner(`벌칙! ${e.count}장 가져오기`);
|
||||
showBanner(`벌칙! ${e.count}장`, 'red', '묶음을 다 맞추지 못했어요');
|
||||
}
|
||||
} else if (e.kind === 'pass') {
|
||||
sfx.whoosh();
|
||||
@@ -355,14 +356,57 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
// Somebody else is moving tiles around in their turn.
|
||||
snd.shuffleQuiet();
|
||||
}
|
||||
// The round is over: "다 냈다!" (the match result sound itself is played by the room page).
|
||||
if (prev.phase === 'playing' && v.phase !== 'playing' && v.round?.endReason === 'rackEmpty') {
|
||||
// The round is over: "루미큐브!" when somebody emptied the rack (the match result sound itself is played by the room page).
|
||||
if (prev.phase === 'playing' && v.phase !== 'playing' && v.round) {
|
||||
const w = v.round.winners;
|
||||
showBanner(w.includes(me ?? '') ? '다 냈다!' : `${w.map((p) => nick(players, p)).join(', ')}님 다 냈다!`, true);
|
||||
if (v.phase === 'roundEnd') sfx.fanfare();
|
||||
const who = w.includes(me ?? '') ? '내가' : `${w.map((p) => nick(players, p)).join(', ')}님이`;
|
||||
if (v.round.endReason === 'rackEmpty') {
|
||||
showBanner('루미큐브!', 'gold', `${who} 타일을 다 냈어요`);
|
||||
for (const p of w) bump(seatEl(p));
|
||||
if (v.phase === 'roundEnd') sfx.fanfare();
|
||||
} else if (v.round.endReason === 'stalemate') showBanner('판 끝', 'dark', '더 낼 수 있는 사람이 없어요');
|
||||
}
|
||||
// The match is over: who won (after the round banner, if there was one).
|
||||
if (prev.phase !== 'finished' && v.phase === 'finished' && v.result?.reason === 'normal') {
|
||||
const top = v.result.ranking[0] ?? [];
|
||||
const iWon = top.includes(me ?? '');
|
||||
const text = iWon ? '승리!' : top.length ? `${top.map((p) => nick(players, p)).join(', ')}님 승리` : '게임 끝';
|
||||
clearTimeout(winTimer.current);
|
||||
winTimer.current = setTimeout(() => showBanner(text, iWon ? 'gold' : 'blue', v.match.total > 1 ? `${v.match.total}판 합계` : undefined), prev.phase === 'playing' ? 1500 : 0);
|
||||
}
|
||||
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
/** Tiles drawn from the pool: mine fly out of it onto my rack, anyone else's as face-down tiles to their seat. */
|
||||
const drawFx = (by: string, mineIds: string[], n: number, gap: number) => {
|
||||
const pool = fxEl('rk-pool');
|
||||
if (by === me) mineIds.forEach((id, i) => flyFrom(document.querySelector(`.rk-rack [data-tile="${cssEsc(id)}"]`), pool, { delay: i * gap, rotate: 8 }));
|
||||
else flyGhost(pool, seatEl(by), { className: 'rk-ghost', count: Math.min(n, 6), gap });
|
||||
};
|
||||
|
||||
// Tiles I moved (rack ↔ table, between sets) slide from where I tapped them.
|
||||
useLayoutEffect(() => {
|
||||
const from = movedFrom.current;
|
||||
if (!from) return;
|
||||
movedFrom.current = null;
|
||||
[...from].forEach(([id, r], i) => flyFrom(document.querySelector(`.rk-root [data-tile="${cssEsc(id)}"]`), r, { ms: 300, delay: i * 35, scale: 0.9, rotate: 0 }));
|
||||
});
|
||||
// Tiles that newly show up on the table in somebody else's turn (their live draft or their commit) fly from their seat.
|
||||
const tableIds = useMemo(() => (mine ? [] : sets.flatMap((d) => d.tileIds)), [mine, sets]);
|
||||
useNewEntries(
|
||||
tableIds,
|
||||
(id) => id,
|
||||
(fresh) => {
|
||||
const by = prevCurrent.current;
|
||||
if (!by || by === me) return;
|
||||
const seat = seatEl(by);
|
||||
fresh.forEach((id, i) => flyFrom(document.querySelector(`.rk-table [data-tile="${cssEsc(id)}"]`), seat, { delay: i * 60, rotate: -8 }));
|
||||
},
|
||||
20,
|
||||
);
|
||||
useLayoutEffect(() => {
|
||||
prevCurrent.current = v.current;
|
||||
});
|
||||
|
||||
// Drop selected tiles that disappeared (e.g. after undo on the server).
|
||||
useEffect(() => {
|
||||
setSel((s) => (s.every((id) => inSets.has(id) || rack.includes(id)) ? s : s.filter((id) => inSets.has(id) || rack.includes(id))));
|
||||
@@ -391,6 +435,12 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
else setMsg('');
|
||||
const next = moveTiles(sets, sel, target, onTable0);
|
||||
if (!next) return;
|
||||
const rects = new Map<string, DOMRect>();
|
||||
for (const id of sel) {
|
||||
const el = document.querySelector(`.rk-root [data-tile="${cssEsc(id)}"]`);
|
||||
if (el) rects.set(id, el.getBoundingClientRect());
|
||||
}
|
||||
movedFrom.current = rects;
|
||||
snd.place();
|
||||
setSel([]);
|
||||
send(next);
|
||||
@@ -458,7 +508,7 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
{showingDraft && !mine ? `${curName}님이 고민 중인 배치` : mine && my?.changed ? '바닥(확정 전)' : '바닥'}
|
||||
{thinking && !showingDraft ? ` · ${curName}님이 생각 중…` : ''}
|
||||
</span>
|
||||
<span aria-label={`남은 타일 ${v.poolCount}장`}>
|
||||
<span aria-label={`남은 타일 ${v.poolCount}장`} data-fx="rk-pool">
|
||||
남은 타일 <Bump value={v.poolCount}>{v.poolCount}</Bump>장
|
||||
</span>
|
||||
</div>
|
||||
@@ -493,7 +543,7 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
</button>
|
||||
)}
|
||||
{d.tileIds.map((id) => (
|
||||
<Tile key={id} id={id} size="sm" as={jokerAs[id]} selected={sel.includes(id)} anim={pop?.has(id) ? 'anim-pop' : undefined} onClick={mine ? () => toggle(id) : undefined} />
|
||||
<Tile key={id} id={id} size="sm" as={jokerAs[id]} selected={sel.includes(id)} onClick={mine ? () => toggle(id) : undefined} />
|
||||
))}
|
||||
{mine && sel.length > 0 && (
|
||||
<button type="button" className="rk-slot" aria-label={`묶음 ${i + 1} 뒤에 놓기`} onClick={() => move({ set: i, at: 'end' })}>
|
||||
@@ -592,7 +642,7 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className={`rk-rack${shake === 'rack' ? ' anim-shake' : ''}`} role="group" aria-label="내 받침대">
|
||||
<div className={`rk-rack${shake === 'rack' ? ' anim-shake' : ''}`} role="group" aria-label="내 받침대" data-fx="rk-rack">
|
||||
{rack.length === 0 && <span className="rk-rack-empty">{my.rack.length ? '모두 바닥에 놓았어요.' : '타일이 없어요.'}</span>}
|
||||
{rack.map((id) => {
|
||||
const k = fly ? fly.ids.indexOf(id) : -1;
|
||||
@@ -616,11 +666,7 @@ function RummikubBoard({ view: v, me, players, act, pending, deadline }: BoardPr
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
{banner && (
|
||||
<div key={banner.seq} className={`rk-banner anim-banner${banner.big ? ' big' : ''}`} aria-hidden>
|
||||
{banner.text}
|
||||
</div>
|
||||
)}
|
||||
{banner}
|
||||
{confirm === 'draw' && (
|
||||
<ConfirmSheet
|
||||
title="놓은 타일을 되돌리고 한 장 가져올까요?"
|
||||
@@ -654,6 +700,7 @@ function Players({ v, me, players, deadline, shake }: { v: RummikubView; me: str
|
||||
<div
|
||||
key={s.id}
|
||||
role="listitem"
|
||||
data-fx-seat={s.id}
|
||||
className={`rk-player${turn ? ' turn' : ''}${s.left || !s.inRound ? ' gone' : ''}${shake === `p:${s.id}` ? ' anim-shake' : turn && v.phase === 'playing' ? ' anim-glow' : ''}`}
|
||||
aria-label={`${u.nickname}${s.id === me ? '(나)' : ''}, 타일 ${s.tiles}장, ${s.melded ? '첫 등록 함' : '첫 등록 전'}${turn ? ', 지금 차례' : ''}${s.left ? ', 나감' : s.away ? ', 자리 비움' : ''}`}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user