모든 게임: 결과·팝업은 애니메이션이 끝난 뒤에, 증강 윷놀이: 이의있음!이 다음 판에도 뜨게, 증강 고르는 목록·나오게 할 증강을 팝업 목록으로
- lib/motion: motionBusy / useMotionHold / useMotionSettled / useAfterMotionValue / AfterMotion - 방 화면: 결과 창과 상태 줄은 판이 멈춘 뒤에(실시간 게임은 상태 줄 그대로), 새 판마다 판 화면을 새로 그림 (결과 창에 둔 채 다음 판이 시작되면 이전 판의 효과 번호가 남아 이의있음!·알림이 안 뜨던 문제) - 41개 게임: 결과 패널·배너·점수·팝업이 마지막 움직임 뒤에 나오도록 게임별로 정리 - 증강 윷놀이: 명탐정·배달·손버릇·따라쟁이·착각 대상은 아이콘과 설명이 다 보이는 목록에서, 방 설정의 나오게 할 증강은 팝업 목록에서 스위치로 켜고 끔 - e2e: 늦게 바뀌는 상태 줄·결과 창과 새 증강 화면에 맞춤 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* 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 CSSProperties, type KeyboardEvent, type ReactNode } from 'react';
|
||||
import { useEffect, useLayoutEffect, 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';
|
||||
@@ -19,7 +19,7 @@ import { keepFocus, useTypingSignal } from '../../lib/chat-input';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
import { fxMs } from '../../lib/motion';
|
||||
import { AfterMotion, fxMs, useAfterMotionValue, useMotionHold, useMotionSettled } from '../../lib/motion';
|
||||
|
||||
// ---------------------------------------------------------------- names (original names only, docs §12)
|
||||
|
||||
@@ -392,15 +392,18 @@ type Pick = { ids: string[]; chosen: string | null; onPick: (id: string) => void
|
||||
/** 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, fx }: { v: MafiaView; players: Record<string, PublicUser>; me: string | null; pick: Pick; pending: boolean; fx: TileFx | null }) {
|
||||
function Players({ v, players, me, pick, pending, fx, hiddenDead, hideRoles }: { v: MafiaView; players: Record<string, PublicUser>; me: string | null; pick: Pick; pending: boolean; fx: TileFx | null; hiddenDead: string[]; hideRoles: boolean }) {
|
||||
const mafiaChoice = v.my?.night?.action === 'mafiaTarget' ? v.my.night.choice : null;
|
||||
// Deaths whose turn-over has not played yet still look alive (the sun is still coming up).
|
||||
const aliveCount = v.aliveCount + hiddenDead.length;
|
||||
return (
|
||||
<section className="mf-box" aria-label={`사람들. 살아 있는 사람 ${v.aliveCount}명`}>
|
||||
<section className="mf-box" aria-label={`사람들. 살아 있는 사람 ${aliveCount}명`}>
|
||||
<h2>
|
||||
사람들 <span className="small muted">살아 있는 사람 {v.aliveCount}명</span>
|
||||
사람들 <span className="small muted">살아 있는 사람 {aliveCount}명</span>
|
||||
</h2>
|
||||
<div className="mf-tiles">
|
||||
{v.players.map((p) => {
|
||||
{v.players.map((q) => {
|
||||
const p = hiddenDead.includes(q.id) ? { ...q, alive: true, role: q.id === me || v.my?.mates.includes(q.id) ? q.role : null, team: null } : q;
|
||||
const u = userOf(players, p.id);
|
||||
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;
|
||||
@@ -411,7 +414,7 @@ function Players({ v, players, me, pick, pending, fx }: { v: MafiaView; players:
|
||||
{u.nickname}
|
||||
{p.id === me ? ' (나)' : ''}
|
||||
</span>
|
||||
<RoleTag p={p} meId={me} />
|
||||
{!hideRoles && <RoleTag p={p} meId={me} />}
|
||||
{!p.alive && <span className="mf-tag">탈락 · {p.diedDay}일차</span>}
|
||||
{p.id === v.phase.accused && <span className="mf-tag mark">지목됨</span>}
|
||||
{mafiaChoice === p.id && !pick && <span className="mf-tag mark">🎯 오늘 밤 대상</span>}
|
||||
@@ -585,6 +588,9 @@ function Actions({ v, players, me, act, pending }: { v: MafiaView; players: Reco
|
||||
const my = v.my;
|
||||
const ph = v.phase;
|
||||
const n = (id: string) => `${nick(players, id)}님`;
|
||||
// A night's investigation result shows once the morning has come up on screen.
|
||||
const resultCount = useAfterMotionValue(my?.results.length ?? 0);
|
||||
const results = my ? my.results.slice(0, resultCount) : [];
|
||||
let body: ReactNode = null;
|
||||
if (!my) {
|
||||
body = <p className="mf-prompt">관전 중이에요. 낮 채팅과 발표만 볼 수 있어요.</p>;
|
||||
@@ -720,11 +726,11 @@ function Actions({ v, players, me, act, pending }: { v: MafiaView; players: Reco
|
||||
<h2>{ph.kind === 'night' ? '🌙 오늘 밤' : ph.kind === 'ended' ? '🏁 결과' : '☀️ 할 일'}</h2>
|
||||
{body}
|
||||
{my?.idleWarning && ph.kind !== 'ended' && <strong style={{ color: 'var(--danger)' }}>오늘도 아무것도 하지 않으면 자리 비움으로 탈락해요.</strong>}
|
||||
{my && my.results.length > 0 && (
|
||||
{my && results.length > 0 && (
|
||||
<>
|
||||
<strong className="small">{my.role === 'medium' ? '영매 결과 (나만 봐요)' : '조사 결과 (나만 봐요)'}</strong>
|
||||
<ul className="mf-results">
|
||||
{my.results.map((r) => (
|
||||
{results.map((r) => (
|
||||
<li key={r.id}>{resultText(r, players)}</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -792,11 +798,16 @@ 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 {
|
||||
function useMafiaFx(v: MafiaView, players: Record<string, PublicUser>, showBanner: ShowBanner, setTileFx: (fx: TileFx | null) => void): string[] {
|
||||
const prev = useRef(v);
|
||||
const timers = useRef<ReturnType<typeof setTimeout>[]>([]);
|
||||
// The banners / tile motion still to come (timers): results wait for them. Deaths whose tile has not turned over yet.
|
||||
const [staging, setStaging] = useState(false);
|
||||
const [hiddenDead, setHiddenDead] = useState<string[]>([]);
|
||||
useMotionHold(staging);
|
||||
useEffect(() => () => timers.current.forEach(clearTimeout), []);
|
||||
useEffect(() => {
|
||||
// Layout effect: a new death must not show on its tile for even one frame before its turn.
|
||||
useLayoutEffect(() => {
|
||||
const p = prev.current;
|
||||
prev.current = v;
|
||||
if (p === v) return;
|
||||
@@ -828,11 +839,18 @@ function useMafiaFx(v: MafiaView, players: Record<string, PublicUser>, showBanne
|
||||
timers.current = [];
|
||||
const later = (ms: number, f: () => void) => (ms ? void timers.current.push(setTimeout(f, fxMs(ms))) : f());
|
||||
const start = isNight(p) && !isNight(v) ? 900 : 0;
|
||||
setHiddenDead(dying);
|
||||
if (dying.length || saved.length) {
|
||||
later(start, () => setTileFx({ dying, saved }));
|
||||
later(start, () => {
|
||||
setHiddenDead([]);
|
||||
setTileFx({ dying, saved });
|
||||
});
|
||||
later(start + 1200, () => setTileFx(null));
|
||||
}
|
||||
banners.forEach(([text, tone, sub], i) => later(start + i * 1500, () => showBanner(text, tone, sub)));
|
||||
const end = Math.max(dying.length || saved.length ? start + 1200 : 0, banners.length ? start + (banners.length - 1) * 1500 : 0);
|
||||
setStaging(end > 0);
|
||||
later(end, () => setStaging(false));
|
||||
}
|
||||
let played = false;
|
||||
const play = (f: () => void) => {
|
||||
@@ -856,6 +874,13 @@ function useMafiaFx(v: MafiaView, players: Record<string, PublicUser>, showBanne
|
||||
if (my && pm && (my.vote !== pm.vote || my.ballot !== pm.ballot || my.night?.choice !== pm.night?.choice)) return play(sfx.select);
|
||||
if (v.phase.readyCount > p.phase.readyCount && v.phase.kind === p.phase.kind) play(sfx.chip);
|
||||
}, [v]);
|
||||
return hiddenDead;
|
||||
}
|
||||
|
||||
/** `v.events` up to the last one whose banners / motion have finished playing. */
|
||||
function useShownEvents(v: MafiaView): PublicEvent[] {
|
||||
const shownN = useAfterMotionValue(v.events.at(-1)?.n ?? 0);
|
||||
return useMemo(() => (v.events.at(-1)?.n ?? 0) <= shownN ? v.events : v.events.filter((e) => e.n <= shownN), [v.events, shownN]);
|
||||
}
|
||||
|
||||
function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView>) {
|
||||
@@ -880,7 +905,14 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
}, [phaseKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const [banner, showBanner] = useBanner();
|
||||
const [tileFx, setTileFx] = useState<TileFx | null>(null);
|
||||
useMafiaFx(v, players, showBanner, setTileFx);
|
||||
const hiddenDead = useMafiaFx(v, players, showBanner, setTileFx);
|
||||
// Announcements (news, chat lines) and the final reveal show once the banners and the sky have played.
|
||||
const shownEvents = useShownEvents(v);
|
||||
const shownV = shownEvents === v.events ? v : { ...v, events: shownEvents };
|
||||
const endShown = useMotionSettled(ph.kind === 'ended');
|
||||
// My own death shows (role card, 탈락 panel) when my tile turns over, like everyone else's.
|
||||
const meHidden = !!me && !!my && hiddenDead.includes(me);
|
||||
const actV = meHidden ? { ...v, my: { ...my!, alive: true } } : v;
|
||||
// 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));
|
||||
@@ -907,7 +939,9 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
: ph.kind === 'discussion' && ph.adjustedBy.length
|
||||
? `시간 바꾼 사람: ${ph.adjustedBy.map((id) => nick(players, id)).join(', ')}`
|
||||
: ph.kind === 'ended'
|
||||
? v.final?.summary
|
||||
? endShown
|
||||
? v.final?.summary
|
||||
: ''
|
||||
: `살아 있는 사람 ${v.aliveCount}명`;
|
||||
return (
|
||||
<div className="mf">
|
||||
@@ -923,19 +957,21 @@ function MafiaBoard({ view: v, me, players, act, pending }: BoardProps<MafiaView
|
||||
<span className="s">{sub}</span>
|
||||
</span>
|
||||
<Clock endsAt={ph.endsAt} unlimited={ph.endsAt === null && ph.kind !== 'ended'} />
|
||||
{my && <RoleCard role={my.role} mates={my.mates} players={players} always={!!v.winner || !my.alive} />}
|
||||
{my && <RoleCard role={my.role} mates={my.mates} players={players} always={!!v.winner || !actV.my!.alive} />}
|
||||
</section>
|
||||
<News v={v} players={players} />
|
||||
{v.final && <FinalReveal v={v} players={players} />}
|
||||
<News v={shownV} players={players} />
|
||||
<AfterMotion when={!!v.final}>
|
||||
<FinalReveal v={v} players={players} />
|
||||
</AfterMotion>
|
||||
<div className="mf-grid">
|
||||
<div className="mf-col mf-players">
|
||||
<Players v={v} players={players} me={me} pick={pick} pending={pending} fx={tileFx} />
|
||||
<Players v={v} players={players} me={me} pick={pick} pending={pending} fx={tileFx} hiddenDead={hiddenDead} hideRoles={ph.kind === 'ended' && !endShown} />
|
||||
</div>
|
||||
<div className="mf-col mf-chatwrap">
|
||||
<ChatBox v={v} players={players} me={me} act={act} />
|
||||
<ChatBox v={shownV} players={players} me={me} act={act} />
|
||||
</div>
|
||||
<div className="mf-col mf-actions">
|
||||
<Actions v={v} players={players} me={me} act={act} pending={pending} />
|
||||
<Actions v={actV} players={players} me={me} act={act} pending={pending} />
|
||||
</div>
|
||||
</div>
|
||||
<p className="sr-only" aria-live="polite">
|
||||
@@ -960,6 +996,7 @@ function composition(setup: MafiaView['setup']): string {
|
||||
}
|
||||
|
||||
function MafiaSide({ view: v, players }: BoardProps<MafiaView>) {
|
||||
const events = useShownEvents(v);
|
||||
return (
|
||||
<>
|
||||
<style>{CSS}</style>
|
||||
@@ -970,11 +1007,11 @@ function MafiaSide({ view: v, players }: BoardProps<MafiaView>) {
|
||||
<span className="small">이번 판 직업: {composition(v.setup)}</span>
|
||||
<span className="small muted">{optionsSummary(v.options)}</span>
|
||||
</div>
|
||||
{v.events.length > 0 && (
|
||||
{events.length > 0 && (
|
||||
<details className="card wide-open" open style={{ padding: 12 }}>
|
||||
<summary style={{ cursor: 'pointer', fontWeight: 700 }}>발표 기록</summary>
|
||||
<ol className="mf-log">
|
||||
{[...v.events]
|
||||
{[...events]
|
||||
.reverse()
|
||||
.filter((e) => e.t !== 'phase')
|
||||
.map((e) => (
|
||||
|
||||
Reference in New Issue
Block a user