야단법석 달리기: 주사위·발걸음·능력·칸 효과·결승 소리, 말이 뛰는 움직임·넘어짐·메달, 뽑기 카드 등장; E2E: 그림 맞히기·클루·라이어·마피아 투표를 시간 무제한으로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-13 13:37:26 +09:00
parent 36c8033b65
commit 99c25cb260
2 changed files with 89 additions and 28 deletions

View File

@@ -5,7 +5,7 @@ import { RACERS, type RacerId } from '@bg/games/magical-athlete/racers';
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, sfx, sounds, tone } from '../../lib/feedback';
import type { BoardProps, GameUI, OptionsProps } from '../types';
import { helpNow } from './help';
import { quickStart } from './quick';
@@ -20,6 +20,27 @@ const seatColor = (v: MagicalAthleteView, p: string) => COLORS[v.seats.indexOf(p
const rname = (id: RacerId) => `${RACERS[id].emoji} ${RACERS[id].name}`;
const who = (players: Record<string, PublicUser>, me: string | null, p: string) => (p === me ? '나' : nick(players, p));
/** Game sounds on top of the shared palette (site volume applies); `d` = delay in ms (after the dice lands). */
const maSound = {
/** Footsteps along the track. */
steps: (d: number) => {
for (let i = 0; i < 3; i++) tone(i % 2 ? 560 : 470, 45, 'triangle', 0.09, d + i * 90);
},
/** A racer's power: a quick sparkle up. */
power: (d: number) => [880, 1175, 1568].forEach((f, i) => tone(f, 90, 'triangle', 0.08, d + i * 60)),
/** Star space (+1 point). */
star: (d: number) => {
tone(1318, 70, 'square', 0.05, d);
tone(1976, 160, 'square', 0.05, d + 70);
},
/** Rock space: tripped. */
trip: (d: number) => tone(300, 200, 'sawtooth', 0.05, d, { slideTo: 150 }),
/** Arrow space: slide forward / back. */
arrow: (d: number, up: boolean) => tone(up ? 500 : 900, 220, 'sine', 0.09, d, { slideTo: up ? 1000 : 450 }),
/** Crossing the finish line. */
finish: (d: number) => [784, 988, 1318].forEach((f, i) => tone(f, 130, 'triangle', 0.1, d + i * 90)),
};
const CSS = `
.ma-wrap { width: 100%; max-width: 1100px; display: flex; flex-direction: column; gap: 10px; }
/* Taller than the play area on PC: start at the top (centring would cut the top off where nobody can scroll to). */
@@ -42,6 +63,10 @@ const CSS = `
.ma-tok circle { stroke: #1f2937; stroke-width: 2; }
.ma-tok.cur circle { stroke: var(--focus); stroke-width: 4; }
.ma-tok.trip { opacity: .55; }
.ma-hop { transform-box: fill-box; transform-origin: center; animation: ma-hop .45s ease-out; }
@keyframes ma-hop { 30% { transform: translateY(-10px) scale(1.12); } 60% { transform: translateY(0) scale(.96); } }
.ma-hop.tripped { animation: anim-shake .45s ease both; }
.ma-medal { transform-box: fill-box; transform-origin: center; animation: anim-pop .32s cubic-bezier(.3,1.6,.5,1) both; }
.ma-emoji { font-size: 16px; }
.ma-lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.ma-panel { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
@@ -97,7 +122,7 @@ button.ma-card:hover:not(:disabled) { border-color: var(--primary); }
}
@media (prefers-reduced-motion: reduce) {
.ma-tok { transition: none; }
.ma-die.rolling, .ma-news .fresh { animation: none; }
.ma-die.rolling, .ma-news .fresh, .ma-hop, .ma-medal { animation: none; }
}
`;
@@ -209,12 +234,15 @@ function Track({ v, me, players }: { v: MagicalAthleteView; me: string | null; p
const isCur = r.cur === x.id;
return (
<g key={x.id} className={`ma-tok${isCur ? ' cur' : ''}${x.tripped ? ' trip' : ''}`} style={{ transform: `translate(${ox}px, ${oy}px)` }}>
<circle r={n === 1 ? 17 : size} fill={seatColor(v, x.owner)} />
<text className="ma-emoji" textAnchor="middle" dy={n === 1 ? 6 : 4} fontSize={n === 1 ? 17 : size + 2} transform={x.tripped ? 'rotate(90)' : undefined}>
{RACERS[x.id].emoji}
</text>
{/* Remounted on every move / trip: a hop (or a stumble) while the token slides. */}
<g key={`${x.pos}-${x.tripped}`} className={`ma-hop${x.tripped ? ' tripped' : ''}`}>
<circle r={n === 1 ? 17 : size} fill={seatColor(v, x.owner)} />
<text className="ma-emoji" textAnchor="middle" dy={n === 1 ? 6 : 4} fontSize={n === 1 ? 17 : size + 2} transform={x.tripped ? 'rotate(90)' : undefined}>
{RACERS[x.id].emoji}
</text>
</g>
{x.place && (
<text textAnchor="middle" x={n === 1 ? 14 : size} y={n === 1 ? 19 : size + 2} fontSize={n === 1 ? 13 : 10}>
<text className="ma-medal" textAnchor="middle" x={n === 1 ? 14 : size} y={n === 1 ? 19 : size + 2} fontSize={n === 1 ? 13 : 10}>
{x.place === 1 ? '🥇' : '🥈'}
</text>
)}
@@ -293,9 +321,11 @@ function RacePanel({ v, me, players, act, pending, rolling }: { v: MagicalAthlet
</button>
))}
</div>
<p className="small muted" style={{ margin: 0 }}>
시간이 지나면 {pr.timeoutText}.
</p>
{v.options.turnSeconds !== null && (
<p className="small muted" style={{ margin: 0 }}>
시간이 지나면 {pr.timeoutText}.
</p>
)}
</>
) : (
<p className="muted small" style={{ margin: 0 }}>
@@ -325,7 +355,7 @@ function Draft({ v, me, players, act, pending }: { v: MagicalAthleteView; me: st
</p>
<div className="ma-cards" role="group" aria-label="펼쳐진 선수">
{d.line.map((id) => (
<button key={id} type="button" className="ma-card" disabled={!mine || pending} aria-label={`${RACERS[id].name}: ${RACERS[id].text}${mine ? ' 누르면 뽑아요' : ''}`} onClick={() => act({ type: 'DRAFT', racer: id })}>
<button key={id} type="button" className="ma-card anim-deal" disabled={!mine || pending} aria-label={`${RACERS[id].name}: ${RACERS[id].text}${mine ? ' 누르면 뽑아요' : ''}`} onClick={() => act({ type: 'DRAFT', racer: id })}>
<span className="em" aria-hidden>
{RACERS[id].emoji}
</span>
@@ -487,6 +517,8 @@ function Board({ view: v, me, players, act, pending }: BoardProps<MagicalAthlete
const prevRace = useRef<number>(v.race?.no ?? 0);
const [fresh, setFresh] = useState(prevLog.current);
const prevTurn = useRef(v.turnSeq);
const soundReady = useRef(false);
const rollHeard = useRef(v.rollSeq);
useLayoutEffect(() => {
if (v.rollSeq <= prevRoll.current) {
@@ -494,12 +526,10 @@ function Board({ view: v, me, players, act, pending }: BoardProps<MagicalAthlete
return;
}
prevRoll.current = v.rollSeq;
if (reducedMotion()) return sounds.stone();
sfx.dice();
if (reducedMotion()) return;
setRolling(true);
const t = setTimeout(() => {
setRolling(false);
sounds.stone();
}, ROLL_MS);
const t = setTimeout(() => setRolling(false), ROLL_MS);
return () => clearTimeout(t);
}, [v.rollSeq]);
@@ -513,14 +543,38 @@ function Board({ view: v, me, players, act, pending }: BoardProps<MagicalAthlete
}
const last = r.log.at(-1)?.n ?? 0;
if (last <= prevLog.current) return;
const first = prevLog.current === 0 && !soundReady.current;
const added = r.log.filter((l) => l.n > prevLog.current && l.kind !== 'turn');
setFresh(prevLog.current);
prevLog.current = last;
soundReady.current = true;
if (added.length) setAnnounce(added.slice(-4).map((l) => l.text).join(' '));
if (added.some((l) => l.kind === 'power')) haptic(30);
if (added.some((l) => l.kind === 'finish')) sounds.ding();
// One sound per update, after the dice lands when this update rolled (the dice has its own sound).
if (first) return;
const d = v.rollSeq > rollHeard.current && !reducedMotion() ? ROLL_MS : 0;
rollHeard.current = v.rollSeq;
const sp = added.filter((l) => l.kind === 'space');
if (added.some((l) => l.kind === 'finish')) maSound.finish(d);
else if (added.some((l) => l.kind === 'power')) maSound.power(d);
else if (sp.some((l) => l.text.includes('별'))) maSound.star(d);
else if (sp.some((l) => l.text.includes('돌'))) maSound.trip(d);
else if (sp.length) maSound.arrow(d, sp.some((l) => l.text.includes('앞 화살표')));
else if (added.some((l) => l.kind === 'move')) maSound.steps(d);
}, [v.race?.log.at(-1)?.n, v.race?.no]); // eslint-disable-line react-hooks/exhaustive-deps
// Draft picks, race selections and a new race, whoever made them.
const drafted = Object.values(v.teams).flat().length;
const pickedN = Object.values(v.picked).filter(Boolean).length;
const prevPhase = useRef({ phase: v.phase, drafted, picked: pickedN, race: v.raceNo });
useEffect(() => {
const p = prevPhase.current;
prevPhase.current = { phase: v.phase, drafted, picked: pickedN, race: v.raceNo };
if (v.phase === 'race' && (p.phase !== 'race' || p.race !== v.raceNo)) return sfx.whoosh();
if (v.phase === 'draft' && drafted > p.drafted) return sfx.cardDeal();
if (v.phase === 'select' && pickedN > p.picked) sfx.chip();
}, [v.phase, drafted, pickedN, v.raceNo]);
useEffect(() => {
if (v.turnSeq === prevTurn.current) return;
prevTurn.current = v.turnSeq;