움직임 더하기 2차: 루미큐브·마피아·라이어·바둑·클루·오목·포커
- 루미큐브: 옮긴 타일이 원래 자리에서 미끄러져 가고, 남이 바닥에 낸 타일은 그 사람 칸에서 날아옴. 가져온 타일은 남은 타일 더미에서 받침대로 날아오고, 남이 가져가면 뒤집힌 타일이 그 사람 칸으로 날아감. 배너를 공통 useBanner로 바꾸고 "루미큐브!"·"판 끝"·승리 배너 추가 - 마피아: 밤에는 화면이 남색으로 어두워지며 달, 아침에는 해가 떠오름. 득표 막대가 한 줄씩 자라고, 탈락한 사람 칸이 뒤집히며 흐려짐. 탈락·살았다·버텼다·조용한 밤·이긴 팀 배너를 차례로 - 라이어: 득표가 한 줄씩 나온 뒤 지목된 사람에게 스포트라이트와 흔들림, "잡았다!"/"헛다리!"·동점·정답/땡·승리 배너 - 바둑: 패스·계가 배너, 계가 때 집 표시가 차례로 나타나고 결과 점수가 0부터 올라감, 승리 배너 - 클루: 말과 흉기가 새 자리로 튀어 오르며 미끄러져 감, 추리한 세 장이 사건 봉투로 날아가고, 보여 준 카드는 뒤집히며(남에게는 뒷면 카드가 날아감) - 오목: 금수 자리를 누르면 빨간 ✕와 "금수" 글자, 판이 흔들림(키보드 Enter도 같은 안내). "오목!"·승패 배너 - 포커: 쇼다운·인디언 이마 카드가 뒷면이 돌아간 뒤 앞면이 돌아 나오는 진짜 뒤집기로 - 모두 누구의 행동이든 화면 변화에 반응하고, 클릭을 막지 않으며, 동작 줄이기 설정을 따름. 게임 문서 UI 절에 반영 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,12 +6,13 @@
|
||||
* While the game runs the room chat panel and quick reactions are closed (`ownChat`), so night talk
|
||||
* cannot leak through the room chat; after the game the room chat opens again.
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import type { Channel, ChatView, MafiaOptions, MafiaView, PlayerView, PrivateResult, PublicEvent, Role, Team } from '@bg/games/mafia';
|
||||
import type { PublicUser } from '@bg/shared/lite';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { useServerNow } from '../../components/TurnTimer';
|
||||
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import { useBanner, type BannerTone } from '../card-fx';
|
||||
import { ChatMessage, sameRun } from '../../components/ChatMessage';
|
||||
import { useStickToBottom } from '../../lib/useStickToBottom';
|
||||
import { useChatOutbox, useTypingSignal } from '../../lib/chat-input';
|
||||
@@ -164,6 +165,23 @@ button.mf-tile { cursor: pointer; }
|
||||
@keyframes mf-pick { 50% { transform: scale(1.07); } }
|
||||
.mf-rolecard[data-show='true'] { animation: anim-flip .35s ease both; }
|
||||
@keyframes mf-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
|
||||
/* Vote results come in one row at a time (--d = the row's delay). */
|
||||
.mf-bar { animation: anim-slide-up .3s ease-out both; animation-delay: var(--d, 0ms); }
|
||||
.mf-bar .tr i { animation-delay: var(--d, 0ms); animation-fill-mode: both; }
|
||||
.mf-bar .ct { animation: anim-pop .32s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(var(--d, 0ms) + 450ms); }
|
||||
/* Night falls / morning comes: the whole screen dims to night blue with a moon, or lights up with a sun (never takes clicks). */
|
||||
.mf-sky { position: fixed; inset: 0; z-index: 55; pointer-events: none; display: flex; align-items: center; justify-content: center; animation: mf-sky 1.7s ease both; }
|
||||
.mf-sky.night { background: radial-gradient(circle at 50% 42%, rgba(67,56,202,.4), rgba(15,23,42,.7) 70%); }
|
||||
.mf-sky.day { background: radial-gradient(circle at 50% 38%, rgba(254,240,138,.8), rgba(251,191,36,.35) 40%, rgba(255,247,214,0) 75%); }
|
||||
.mf-sky span { font-size: clamp(4rem, 16vw, 8rem); line-height: 1; animation: mf-sky-icon 1.7s cubic-bezier(.2,.8,.3,1) both; filter: drop-shadow(0 6px 18px rgba(0,0,0,.35)); }
|
||||
.mf-sky.day span { filter: drop-shadow(0 0 28px rgba(251,191,36,.9)); }
|
||||
@keyframes mf-sky { 0% { opacity: 0; } 22% { opacity: 1; } 68% { opacity: 1; } 100% { opacity: 0; } }
|
||||
@keyframes mf-sky-icon { 0% { transform: translateY(60px) scale(.6) rotate(-20deg); opacity: 0; } 35% { transform: none; opacity: 1; } 72% { opacity: 1; } 100% { transform: translateY(-24px) scale(1.05); opacity: 0; } }
|
||||
/* The player who just left the game: the tile turns over and greys out. */
|
||||
.mf-tile.dying { animation: mf-die .9s ease both; }
|
||||
@keyframes mf-die { 0% { transform: perspective(600px) rotateY(0); filter: none; opacity: 1; } 45% { transform: perspective(600px) rotateY(90deg); filter: none; }
|
||||
55% { transform: perspective(600px) rotateY(90deg); filter: grayscale(1); } 100% { transform: perspective(600px) rotateY(0); filter: grayscale(1); opacity: .6; } }
|
||||
.mf-tile.saved { animation: anim-pop .45s cubic-bezier(.3, 1.6, .5, 1) both; box-shadow: 0 0 0 4px rgba(21,128,61,.45); }
|
||||
@media (max-width: 1099px) {
|
||||
.mf { height: auto; }
|
||||
.mf-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: 'actions players' 'chat chat'; }
|
||||
@@ -182,7 +200,8 @@ button.mf-tile { cursor: pointer; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.mf-banner { transition: none; }
|
||||
.mf-news, .mf-bar .tr i, .mf-tile[aria-pressed='true'], .mf-rolecard[data-show='true'] { animation: none; }
|
||||
.mf-news, .mf-bar, .mf-bar .tr i, .mf-bar .ct, .mf-tile[aria-pressed='true'], .mf-rolecard[data-show='true'], .mf-tile.dying, .mf-tile.saved { animation: none; }
|
||||
.mf-sky { display: none; }
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -342,13 +361,14 @@ function VoteBars({ e, players }: { e: Extract<PublicEvent, { t: 'vote' }>; play
|
||||
<span className="big">{eventText(e, players)}</span>
|
||||
{rows.length > 0 && (
|
||||
<div className="mf-bars" role="list" aria-label="득표">
|
||||
{rows.map(([id, n]) => (
|
||||
<div key={id} className="mf-bar" data-top={id === e.accused} role="listitem" aria-label={`${nick(players, id)} ${n}표`}>
|
||||
{/* Least votes first, so the top one lands last (one row every 0.35 s). */}
|
||||
{rows.map(([id, n], i) => (
|
||||
<div key={id} className="mf-bar" data-top={id === e.accused} role="listitem" aria-label={`${nick(players, id)} ${n}표`} style={{ '--d': `${(rows.length - 1 - i) * 350}ms` } as CSSProperties}>
|
||||
<span className="nm">{nick(players, id)}</span>
|
||||
<span className="tr" aria-hidden>
|
||||
<i style={{ width: `${(n / max) * 100}%` }} />
|
||||
</span>
|
||||
<span>{n}표</span>
|
||||
<span className="ct">{n}표</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -368,8 +388,10 @@ function VoteBars({ e, players }: { e: Extract<PublicEvent, { t: 'vote' }>; play
|
||||
// ---------------------------------------------------------------- players
|
||||
|
||||
type Pick = { ids: string[]; chosen: string | null; onPick: (id: string) => void } | null;
|
||||
/** Tiles animating right now: who just left the game (turns over and greys out), who was spared. */
|
||||
type TileFx = { dying: string[]; saved: string[] };
|
||||
|
||||
function Players({ v, players, me, pick, pending }: { v: MafiaView; players: Record<string, PublicUser>; me: string | null; pick: Pick; pending: boolean }) {
|
||||
function Players({ v, players, me, pick, pending, fx }: { v: MafiaView; players: Record<string, PublicUser>; me: string | null; pick: Pick; pending: boolean; fx: TileFx | null }) {
|
||||
const mafiaChoice = v.my?.night?.action === 'mafiaTarget' ? v.my.night.choice : null;
|
||||
return (
|
||||
<section className="mf-box" aria-label={`사람들. 살아 있는 사람 ${v.aliveCount}명`}>
|
||||
@@ -379,7 +401,7 @@ function Players({ v, players, me, pick, pending }: { v: MafiaView; players: Rec
|
||||
<div className="mf-tiles">
|
||||
{v.players.map((p) => {
|
||||
const u = userOf(players, p.id);
|
||||
const cls = `mf-tile${p.id === me ? ' me' : ''}${!p.alive ? ' dead' : ''}${p.id === v.phase.accused ? ' accused' : ''}`;
|
||||
const cls = `mf-tile${p.id === me ? ' me' : ''}${!p.alive ? ' dead' : ''}${p.id === v.phase.accused ? ' accused' : ''}${fx?.dying.includes(p.id) ? ' dying' : fx?.saved.includes(p.id) ? ' saved' : ''}`;
|
||||
const can = pick?.ids.includes(p.id) ?? false;
|
||||
const body = (
|
||||
<>
|
||||
@@ -758,15 +780,54 @@ function FinalReveal({ v, players }: { v: MafiaView; players: Record<string, Pub
|
||||
|
||||
// ---------------------------------------------------------------- board
|
||||
|
||||
/** Sounds for what anyone did: announcements (votes, deaths, saves, the end), choices, the done count. */
|
||||
function useMafiaSounds(v: MafiaView): void {
|
||||
type ShowBanner = (text: string, tone?: BannerTone, sub?: string) => void;
|
||||
|
||||
/**
|
||||
* Sounds and motion for what anyone did: announcements (votes, deaths, saves, the end), choices, the done count.
|
||||
* Banners come one after another (a morning death, then the winning side); a new announcement cancels queued ones.
|
||||
*/
|
||||
function useMafiaFx(v: MafiaView, players: Record<string, PublicUser>, showBanner: ShowBanner, setTileFx: (fx: TileFx | null) => void): void {
|
||||
const prev = useRef(v);
|
||||
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
||||
useEffect(() => () => timers.current.forEach(clearTimeout), []);
|
||||
useEffect(() => {
|
||||
const p = prev.current;
|
||||
prev.current = v;
|
||||
if (p === v) return;
|
||||
const last = p.events.at(-1)?.n ?? 0;
|
||||
const fresh = v.events.filter((e) => e.n > last);
|
||||
// Banners + tile motion. At daybreak they wait for the sun to come up.
|
||||
const banners: [string, BannerTone, string?][] = [];
|
||||
const dying: string[] = [];
|
||||
const saved: string[] = [];
|
||||
const name = (id: string) => `${nick(players, id)}님`;
|
||||
for (const e of fresh) {
|
||||
if (e.t === 'death') {
|
||||
dying.push(e.p);
|
||||
const role = e.role ? `${ROLE_INFO[e.role].icon} ${ROLE_INFO[e.role].name}였어요` : e.team ? (e.team === 'mafia' ? '마피아였어요!' : '마피아가 아니었어요') : undefined;
|
||||
const how = e.by === 'mafia' ? '밤사이 마피아에게 당했어요' : e.by === 'vote' ? '투표로 탈락했어요' : '자리를 비워 탈락했어요';
|
||||
banners.push([`${name(e.p)} 탈락`, e.by === 'vote' ? 'red' : 'dark', role ? `${how} · ${role}` : how]);
|
||||
} else if (e.t === 'confirm' && e.outcome !== 'executed') {
|
||||
saved.push(e.accused);
|
||||
banners.push(e.outcome === 'politician' ? ['정치인!', 'blue', `${name(e.accused)}은 투표로 탈락하지 않아요`] : ['살아남았다!', 'green', `반대 ${e.no} · 찬성 ${e.yes}`]);
|
||||
} else if (e.t === 'healed') banners.push(['살았다!', 'green', '의사가 지켜 냈어요']);
|
||||
else if (e.t === 'soldier') {
|
||||
saved.push(e.p);
|
||||
banners.push(['버텼다!', 'green', `군인 ${name(e.p)}이 공격을 막았어요`]);
|
||||
} else if (e.t === 'quiet') banners.push(['조용한 밤', 'blue', '아무도 탈락하지 않았어요']);
|
||||
else if (e.t === 'end') banners.push([`${TEAM_KO[e.winner]} 승리!`, e.winner === 'mafia' ? 'red' : 'blue']);
|
||||
}
|
||||
if (fresh.length) {
|
||||
timers.current.forEach(clearTimeout);
|
||||
timers.current = [];
|
||||
const later = (ms: number, f: () => void) => (ms ? void timers.current.push(setTimeout(f, ms)) : f());
|
||||
const start = isNight(p) && !isNight(v) ? 900 : 0;
|
||||
if (dying.length || saved.length) {
|
||||
later(start, () => setTileFx({ dying, saved }));
|
||||
later(start + 1200, () => setTileFx(null));
|
||||
}
|
||||
banners.forEach(([text, tone, sub], i) => later(start + i * 1500, () => showBanner(text, tone, sub)));
|
||||
}
|
||||
let played = false;
|
||||
const play = (f: () => void) => {
|
||||
if (played) return;
|
||||
@@ -809,7 +870,21 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
else if (ph.kind === 'discussion' || ph.kind === 'greeting') mfSound.morning();
|
||||
else if (my?.alive && (ph.kind === 'vote' || (ph.kind === 'confirm' && my.canConfirm) || (ph.kind === 'defense' && ph.accused === me))) sounds.myTurn();
|
||||
}, [phaseKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useMafiaSounds(v);
|
||||
const [banner, showBanner] = useBanner();
|
||||
const [tileFx, setTileFx] = useState<TileFx | null>(null);
|
||||
useMafiaFx(v, players, showBanner, setTileFx);
|
||||
// Night falls / morning comes (for everyone, whoever's button press moved the phase on).
|
||||
const [sky, setSky] = useState<{ kind: 'night' | 'day'; key: string } | null>(null);
|
||||
const wasNight = useRef(isNight(v));
|
||||
useEffect(() => {
|
||||
const night = isNight(v);
|
||||
const before = wasNight.current;
|
||||
wasNight.current = night;
|
||||
if (night === before || ph.kind === 'ended' || ph.kind === 'roleReveal') return;
|
||||
setSky({ kind: night ? 'night' : 'day', key: phaseKey });
|
||||
const t = setTimeout(() => setSky(null), 1800);
|
||||
return () => clearTimeout(t);
|
||||
}, [phaseKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
let pick: Pick = null;
|
||||
if (my?.alive && ph.kind === 'vote') pick = { ids: my.voteTargets, chosen: my.vote === 'abstain' ? null : my.vote, onPick: (id) => act({ type: 'vote', target: id }) };
|
||||
@@ -846,7 +921,7 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
{v.final && <FinalReveal v={v} players={players} />}
|
||||
<div className="mf-grid">
|
||||
<div className="mf-col mf-players">
|
||||
<Players v={v} players={players} me={me} pick={pick} pending={pending} />
|
||||
<Players v={v} players={players} me={me} pick={pick} pending={pending} fx={tileFx} />
|
||||
</div>
|
||||
<div className="mf-col mf-chatwrap">
|
||||
<ChatBox v={v} players={players} me={me} act={act} />
|
||||
@@ -858,6 +933,12 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
<p className="sr-only" aria-live="polite">
|
||||
{announce}
|
||||
</p>
|
||||
{sky && (
|
||||
<div key={sky.key} className={`mf-sky ${sky.kind}`} aria-hidden>
|
||||
<span>{sky.kind === 'night' ? '🌙' : '☀️'}</span>
|
||||
</div>
|
||||
)}
|
||||
{banner}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user