|
|
|
|
@@ -11,7 +11,7 @@ import { TOPIC_IDS, TOPIC_KO } from '@bg/games/liar/topics';
|
|
|
|
|
import type { PublicUser } from '@bg/shared/lite';
|
|
|
|
|
import { Avatar } from '../../components/ui';
|
|
|
|
|
import { useServerNow } from '../../components/TurnTimer';
|
|
|
|
|
import { haptic, sounds } from '../../lib/feedback';
|
|
|
|
|
import { haptic, sfx, sounds, tone } from '../../lib/feedback';
|
|
|
|
|
import { ChatMessage, nameHue, sameRun } from '../../components/ChatMessage';
|
|
|
|
|
import { useStickToBottom } from '../../lib/useStickToBottom';
|
|
|
|
|
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
|
|
|
|
@@ -126,6 +126,12 @@ button.lg-tile { cursor: pointer; }
|
|
|
|
|
.lg-final .word { font-size: 1.3rem; font-weight: 900; }
|
|
|
|
|
.lg-log { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; max-height: 320px; overflow: auto; }
|
|
|
|
|
@keyframes lg-pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
|
|
|
.lg-unl { font-size: 1.6rem; }
|
|
|
|
|
.lg-unl small { display: block; font-size: .7rem; font-weight: 800; }
|
|
|
|
|
.lg-tile[aria-pressed='true'] { animation: lg-pick .28s ease-out; }
|
|
|
|
|
.lg-tile.accused { animation: anim-shake .45s ease both; }
|
|
|
|
|
@keyframes lg-pick { 50% { transform: scale(1.07); } }
|
|
|
|
|
.lg-card[data-show='true'] { animation: anim-flip .35s ease both; }
|
|
|
|
|
@keyframes lg-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
|
|
|
|
|
@media (max-width: 1099px) {
|
|
|
|
|
.lg { height: auto; }
|
|
|
|
|
@@ -144,14 +150,20 @@ button.lg-tile { cursor: pointer; }
|
|
|
|
|
.lg-msgs { min-height: 160px; max-height: 300px; }
|
|
|
|
|
}
|
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
|
|
|
.lg-news, .lg-bar .tr i { animation: none; }
|
|
|
|
|
.lg-news, .lg-bar .tr i, .lg-tile[aria-pressed='true'], .lg-tile.accused, .lg-card[data-show='true'] { animation: none; }
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- small parts
|
|
|
|
|
|
|
|
|
|
function Clock({ endsAt }: { endsAt: number | null }) {
|
|
|
|
|
function Clock({ endsAt, unlimited }: { endsAt: number | null; unlimited: boolean }) {
|
|
|
|
|
const now = useServerNow(500);
|
|
|
|
|
if (unlimited)
|
|
|
|
|
return (
|
|
|
|
|
<span className="lg-clock lg-unl" role="timer" aria-label="시간 제한 없음">
|
|
|
|
|
∞<small>무제한</small>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
if (endsAt === null) return null;
|
|
|
|
|
const sec = Math.max(0, Math.ceil((endsAt - now) / 1000));
|
|
|
|
|
const text = sec >= 60 ? `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, '0')}` : `${sec}`;
|
|
|
|
|
@@ -224,7 +236,7 @@ function eventText(e: PublicEvent, players: Record<string, PublicUser>): string
|
|
|
|
|
case 'accused':
|
|
|
|
|
return e.liar ? `${josa(n(e.p), ['은', '는'])} 라이어가 맞아요!` : `${josa(n(e.p), ['은', '는'])} 라이어가 아니었어요`;
|
|
|
|
|
case 'guess':
|
|
|
|
|
return e.text === null ? '라이어가 시간 안에 답하지 못했어요' : `라이어의 답: "${e.text}" — ${e.correct ? '정답!' : '틀렸어요'}`;
|
|
|
|
|
return e.text === null ? '라이어가 답하지 못했어요' : `라이어의 답: "${e.text}" — ${e.correct ? '정답!' : '틀렸어요'}`;
|
|
|
|
|
case 'left':
|
|
|
|
|
return `${josa(n(e.p), ['이', '가'])} 게임을 나갔어요`;
|
|
|
|
|
case 'end':
|
|
|
|
|
@@ -321,8 +333,8 @@ function Players({ v, players, me, pick, pending }: { v: LiarView; players: Reco
|
|
|
|
|
{id === me ? ' (나)' : ''}
|
|
|
|
|
</span>
|
|
|
|
|
{speaking && <span className="lg-tag say">말하는 중</span>}
|
|
|
|
|
{ph.kind === 'vote' && p.voted && <span className="lg-tag ok">투표함</span>}
|
|
|
|
|
{p.liar === true && <span className="lg-tag liar">🤥 라이어</span>}
|
|
|
|
|
{ph.kind === 'vote' && p.voted && <span className="lg-tag ok anim-pop">투표함</span>}
|
|
|
|
|
{p.liar === true && <span className="lg-tag liar anim-pop">🤥 라이어</span>}
|
|
|
|
|
{p.left && <span className="lg-tag">나감</span>}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
@@ -371,9 +383,9 @@ function Descriptions({ v, players, me }: { v: LiarView; players: Record<string,
|
|
|
|
|
{v.descriptions
|
|
|
|
|
.filter((d) => d.round === r)
|
|
|
|
|
.map((d) => (
|
|
|
|
|
<li key={d.n} className={`${d.from === me ? 'mine' : ''}${d.text === null ? ' skip' : ''}`} style={{ '--name-h': nameHue(d.from) } as CSSProperties}>
|
|
|
|
|
<li key={d.n} className={`${d.from === me ? 'mine' : ''}${d.text === null ? ' skip' : ''} anim-slide-up`} style={{ '--name-h': nameHue(d.from) } as CSSProperties}>
|
|
|
|
|
<strong>{nick(players, d.from)}</strong>
|
|
|
|
|
{d.text ?? '(시간이 지나 넘어갔어요)'}
|
|
|
|
|
{d.text ?? (v.options.describeSeconds === null ? '(자리를 비워 넘어갔어요)' : '(시간이 지나 넘어갔어요)')}
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
{v.phase.kind === 'describe' && v.phase.round === r && v.phase.speaker && (
|
|
|
|
|
@@ -524,7 +536,10 @@ function Actions({ v, players, me, act, pending }: { v: LiarView; players: Recor
|
|
|
|
|
body = my.canDescribe ? (
|
|
|
|
|
<>
|
|
|
|
|
<p className="lg-prompt">내 차례예요! 한 문장으로 설명해 주세요</p>
|
|
|
|
|
<span className="small">{my.role === 'liar' ? '제시어를 모르니 앞사람 말을 잘 듣고 아는 척해요.' : '제시어는 직접 말할 수 없어요. 너무 쉬우면 라이어가 알아채요.'}</span>
|
|
|
|
|
<span className="small">
|
|
|
|
|
{my.role === 'liar' ? '제시어를 모르니 앞사람 말을 잘 듣고 아는 척해요.' : '제시어는 직접 말할 수 없어요. 너무 쉬우면 라이어가 알아채요.'}
|
|
|
|
|
{ph.endsAt === null ? ' 시간 제한은 없어요.' : ''}
|
|
|
|
|
</span>
|
|
|
|
|
<DescribeForm key={`${ph.round}-${ph.turn}`} act={act} pending={pending} />
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
@@ -546,7 +561,7 @@ function Actions({ v, players, me, act, pending }: { v: LiarView; players: Recor
|
|
|
|
|
{my.ready ? `기다리는 중 (${ph.readyCount}/${ph.readyNeeded})` : `토론 끝내기 (${ph.readyCount}/${ph.readyNeeded})`}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<span className="small muted">모두 누르면 바로 투표로 넘어가요.</span>
|
|
|
|
|
<span className="small muted">{ph.endsAt === null ? '토론 시간이 무제한이에요. ' : ''}모두 누르면 바로 투표로 넘어가요.</span>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else if (ph.kind === 'vote') {
|
|
|
|
|
@@ -567,7 +582,10 @@ function Actions({ v, players, me, act, pending }: { v: LiarView; players: Recor
|
|
|
|
|
body = my.canGuess ? (
|
|
|
|
|
<>
|
|
|
|
|
<p className="lg-prompt">들켰어요! 제시어를 맞히면 그래도 이겨요</p>
|
|
|
|
|
<span className="small">주제는 {v.topicKo}이에요. {v.options.guessMode === 'choice' ? '목록에서 하나를 골라요. 기회는 한 번이에요.' : '띄어쓰기는 상관없어요. 기회는 한 번이에요.'}</span>
|
|
|
|
|
<span className="small">
|
|
|
|
|
주제는 {v.topicKo}이에요. {v.options.guessMode === 'choice' ? '목록에서 하나를 골라요. 기회는 한 번이에요.' : '띄어쓰기는 상관없어요. 기회는 한 번이에요.'}
|
|
|
|
|
{ph.endsAt === null ? ' 시간 제한은 없어요.' : ''}
|
|
|
|
|
</span>
|
|
|
|
|
<GuessForm v={v} act={act} pending={pending} />
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
@@ -635,6 +653,36 @@ function FinalReveal({ v, players }: { v: LiarView; players: Record<string, Publ
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- board
|
|
|
|
|
|
|
|
|
|
/** Game sounds on top of the shared palette (site volume applies). */
|
|
|
|
|
const lgSound = {
|
|
|
|
|
/** Someone else's description lands. */
|
|
|
|
|
said: () => tone(660, 70, 'triangle', 0.09),
|
|
|
|
|
/** The accused really is the liar. */
|
|
|
|
|
caught: () => [523, 784].forEach((f, i) => tone(f, 140, 'square', 0.07, i * 120)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Sounds for what anyone did: descriptions, votes being cast, results (the room plays win / lose at the end). */
|
|
|
|
|
function useLiarSounds(v: LiarView, me: string | null): void {
|
|
|
|
|
const prev = useRef(v);
|
|
|
|
|
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);
|
|
|
|
|
if (fresh.some((e) => e.t === 'end')) return;
|
|
|
|
|
const acc = fresh.find((e) => e.t === 'accused');
|
|
|
|
|
if (acc && acc.t === 'accused') return acc.liar ? lgSound.caught() : sfx.bad();
|
|
|
|
|
if (fresh.some((e) => e.t === 'vote')) return sfx.chips(3);
|
|
|
|
|
if (fresh.some((e) => e.t === 'left')) return sfx.whoosh();
|
|
|
|
|
const newDesc = v.descriptions.slice(p.descriptions.length);
|
|
|
|
|
if (newDesc.some((d) => d.from !== me)) return newDesc.some((d) => d.text === null) ? sfx.tick() : lgSound.said();
|
|
|
|
|
if (v.my?.vote !== p.my?.vote && v.my?.vote) return sfx.select();
|
|
|
|
|
const same = v.phase.kind === p.phase.kind && v.phase.voteRound === p.phase.voteRound;
|
|
|
|
|
if (same && (v.phase.votedCount > p.phase.votedCount || v.phase.readyCount > p.phase.readyCount)) sfx.chip();
|
|
|
|
|
}, [v]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function LiarBoard({ view: v, me, players, act, pending }: BoardProps<LiarView>) {
|
|
|
|
|
const ph = v.phase;
|
|
|
|
|
const my = v.my;
|
|
|
|
|
@@ -652,6 +700,7 @@ function LiarBoard({ view: v, me, players, act, pending }: BoardProps<LiarView>)
|
|
|
|
|
sounds.myTurn();
|
|
|
|
|
}
|
|
|
|
|
}, [phaseKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
useLiarSounds(v, me);
|
|
|
|
|
|
|
|
|
|
const pick: Pick = my && ph.kind === 'vote' && my.voteTargets.length ? { ids: my.voteTargets, chosen: my.vote, onPick: (id) => act({ type: 'vote', target: id }) } : null;
|
|
|
|
|
const hot = ph.kind === 'guess' || (ph.kind === 'describe' && !!my?.canDescribe);
|
|
|
|
|
@@ -667,10 +716,12 @@ function LiarBoard({ view: v, me, players, act, pending }: BoardProps<LiarView>)
|
|
|
|
|
<section className="lg-banner" data-time={ph.kind === 'ended' ? 'end' : 'play'} data-hot={hot} aria-label="진행 상황">
|
|
|
|
|
<span className="lg-ph">
|
|
|
|
|
<span className="d">🤥 라이어 게임</span>
|
|
|
|
|
<strong>{phaseTitle(v)}</strong>
|
|
|
|
|
<strong key={phaseKey} className="anim-slide-up">
|
|
|
|
|
{phaseTitle(v)}
|
|
|
|
|
</strong>
|
|
|
|
|
<span className="s">{sub}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<Clock endsAt={ph.endsAt} />
|
|
|
|
|
<Clock endsAt={ph.endsAt} unlimited={ph.endsAt === null && ph.kind !== 'ended'} />
|
|
|
|
|
{my && <WordCard v={v} always={ph.kind === 'ended'} />}
|
|
|
|
|
</section>
|
|
|
|
|
<News v={v} players={players} />
|
|
|
|
|
@@ -762,7 +813,7 @@ function statusText(v: LiarView, me: string | null, players: Record<string, Publ
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- options
|
|
|
|
|
|
|
|
|
|
function Seg<T extends string | number | boolean>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
|
|
|
|
function Seg<T extends string | number | boolean | null>({ value, options, onChange, label }: { value: T; options: [T, string][]; onChange: (v: T) => void; label: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="segmented" role="group" aria-label={label} style={{ flexWrap: 'wrap' }}>
|
|
|
|
|
{options.map(([k, l]) => (
|
|
|
|
|
@@ -788,7 +839,7 @@ const onOff: [boolean, string][] = [
|
|
|
|
|
[true, '켜기'],
|
|
|
|
|
[false, '끄기'],
|
|
|
|
|
];
|
|
|
|
|
const secs = <T extends number>(...v: T[]): [T, string][] => v.map((x) => [x, `${x}초`]);
|
|
|
|
|
const secs = <T extends number>(...v: T[]): [T | null, string][] => [...v.map((x): [T, string] => [x, `${x}초`]), [null, '무제한']];
|
|
|
|
|
|
|
|
|
|
function Options({ value: o, onChange }: OptionsProps<LiarOptions>) {
|
|
|
|
|
const [more, setMore] = useState(false);
|
|
|
|
|
@@ -828,18 +879,21 @@ function Options({ value: o, onChange }: OptionsProps<LiarOptions>) {
|
|
|
|
|
</button>
|
|
|
|
|
{more && (
|
|
|
|
|
<>
|
|
|
|
|
<Field label="한 사람 설명 시간">
|
|
|
|
|
<Field label="한 사람 설명 시간" help={o.describeSeconds === null ? '설명을 보낼 때까지 기다려요.' : undefined}>
|
|
|
|
|
<Seg label="설명 시간" value={o.describeSeconds} options={secs(15, 20, 30, 45, 60)} onChange={(describeSeconds) => set({ describeSeconds })} />
|
|
|
|
|
</Field>
|
|
|
|
|
<Field label="자유 토론 시간">
|
|
|
|
|
<Field label="자유 토론 시간" help={o.discussionSeconds === null ? '모두 [토론 끝내기]를 누르면 투표로 넘어가요.' : undefined}>
|
|
|
|
|
<Seg label="토론 시간" value={o.discussionSeconds} options={secs(30, 60, 90, 120, 180)} onChange={(discussionSeconds) => set({ discussionSeconds })} />
|
|
|
|
|
</Field>
|
|
|
|
|
<Field label="투표 시간">
|
|
|
|
|
<Field label="투표 시간" help={o.voteSeconds === null ? '모두 투표하면 결과가 나와요.' : undefined}>
|
|
|
|
|
<Seg label="투표 시간" value={o.voteSeconds} options={secs(15, 20, 30, 45)} onChange={(voteSeconds) => set({ voteSeconds })} />
|
|
|
|
|
</Field>
|
|
|
|
|
<Field label="정답 맞히기 시간">
|
|
|
|
|
<Field label="정답 맞히기 시간" help={o.guessSeconds === null ? '라이어가 답할 때까지 기다려요.' : undefined}>
|
|
|
|
|
<Seg label="정답 맞히기 시간" value={o.guessSeconds} options={secs(20, 30, 45, 60)} onChange={(guessSeconds) => set({ guessSeconds })} />
|
|
|
|
|
</Field>
|
|
|
|
|
{[o.describeSeconds, o.discussionSeconds, o.voteSeconds, o.guessSeconds].includes(null) && (
|
|
|
|
|
<span className="small muted">무제한이어도 연결이 끊긴 채 돌아오지 않는 사람은 잠시 뒤 넘어가요(설명 넘김, 표 없음, 답 없음).</span>
|
|
|
|
|
)}
|
|
|
|
|
<Field label="고운 말 필터(욕설·링크·전화번호 막기)">
|
|
|
|
|
<Seg label="고운 말 필터" value={o.kidSafeChat} options={onOff} onChange={(kidSafeChat) => set({ kidSafeChat })} />
|
|
|
|
|
</Field>
|
|
|
|
|
@@ -852,7 +906,7 @@ function Options({ value: o, onChange }: OptionsProps<LiarOptions>) {
|
|
|
|
|
function optionsSummary(o: LiarOptions): string {
|
|
|
|
|
const parts = [o.topic === 'random' ? '주제 무작위' : `주제 ${TOPIC_KO[o.topic]}`];
|
|
|
|
|
if (o.foolMode) parts.push('바보 모드');
|
|
|
|
|
parts.push(o.rounds === 2 ? '두 바퀴' : '한 바퀴', `설명 ${o.describeSeconds}초`, `토론 ${o.discussionSeconds}초`, o.guessMode === 'choice' ? '정답은 목록에서' : '정답은 직접 적기');
|
|
|
|
|
parts.push(o.rounds === 2 ? '두 바퀴' : '한 바퀴', o.describeSeconds === null ? '설명 무제한' : `설명 ${o.describeSeconds}초`, o.discussionSeconds === null ? '토론 무제한' : `토론 ${o.discussionSeconds}초`, o.guessMode === 'choice' ? '정답은 목록에서' : '정답은 직접 적기');
|
|
|
|
|
return parts.join(' · ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -873,6 +927,7 @@ function Rules() {
|
|
|
|
|
<li>라이어가 아닌 사람이 지목되면 라이어 승리. 라이어가 지목되면 제시어를 한 번 맞힐 수 있어요(띄어쓰기·대소문자 무시). 맞히면 라이어, 틀리면 시민 승리예요.</li>
|
|
|
|
|
<li>점수: 시민이 이기면 시민마다 1점, 라이어가 이기면 라이어 2점.</li>
|
|
|
|
|
<li>바보 모드: 라이어도 같은 주제의 다른 단어를 받고, 자기가 라이어인지 몰라요.</li>
|
|
|
|
|
<li>시간 무제한: 설명·토론·투표·정답 맞히기 시간을 무제한으로 할 수 있어요. 그 단계는 할 일을 다 마칠 때까지 기다려요.</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p className="small muted">내 제시어는 "내 제시어" 카드를 꾹 누르고 있을 때만 보여요. 게임 중에는 방 채팅 대신 게임 화면의 채팅을 써요.</p>
|
|
|
|
|
</div>
|
|
|
|
|
|