라이어 게임: 관리자 화면에서 주제·제시어 추가/수정/삭제, 바보 모드 라이어는 비슷한 단어(같은 묶음)

- 제시어 1,519개를 주제별 '비슷한 단어 묶음' 391개로 정리(bank/*.ts groups). 바보 모드 라이어는 제시어와 같은 묶음의 다른 단어를 받음
- 관리자 → 라이어 제시어(/admin/liar): 주제 추가·이름 변경·삭제(내장 주제는 다시 살리기/처음 값으로), 제시어·묶음·다른 표기·컴퓨터 설명 편집, 저장 시 topicProblems 검사
- 저장: liar_topics(바뀐 주제), liar_bank_versions(판본). 새 판 옵션에 bank 판본을 붙여(prepareOptions) 다시 보기·복구가 같은 은행 사용
- 판 상태에 주제 이름·단어 목록·다른 표기를 복사해 진행 중 판은 관리자 수정의 영향을 받지 않음
- 대기실 주제 목록은 GET /api/liar/topics, 관리자 API /api/admin/liar/topics, 기록 liar.topic.*
- 테스트: 엔진(묶음·바보 모드·판본·검사), 서버(관리자 API·새 판·재시작), E2E(관리자 편집 → 대기실 새 주제)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-18 04:16:17 +09:00
parent 5a878ba991
commit 1bd69200fd
46 changed files with 1639 additions and 75 deletions

View File

@@ -25,6 +25,32 @@ import { fxMs } from '../../lib/motion';
type Kind = LiarView['phase']['kind'];
// ---------------------------------------------------------------- topics (admins may add or delete some)
type TopicChoice = { id: string; ko: string };
/** The topics new games can use; the code's list until the server answers. */
let topicChoices: TopicChoice[] = TOPIC_IDS.map((id) => ({ id, ko: TOPIC_KO[id] }));
let topicsLoad: Promise<TopicChoice[]> | null = null;
function loadTopics(): Promise<TopicChoice[]> {
topicsLoad ??= fetch('/api/liar/topics', { credentials: 'same-origin' })
.then((r) => (r.ok ? (r.json() as Promise<{ topics: TopicChoice[] }>) : Promise.reject(new Error(String(r.status)))))
.then((d) => (topicChoices = d.topics))
.catch(() => ((topicsLoad = null), topicChoices));
return topicsLoad;
}
const topicName = (id: string) => topicChoices.find((t) => t.id === id)?.ko ?? (TOPIC_KO as Record<string, string>)[id] ?? '관리자가 고른 주제';
function useTopicChoices(): TopicChoice[] {
const [list, setList] = useState(topicChoices);
useEffect(() => {
let on = true;
void loadTopics().then((x) => on && setList(x));
return () => {
on = false;
};
}, []);
return list;
}
const PHASE_KO: Record<Kind, string> = {
reveal: '제시어 확인',
describe: '한 사람씩 설명',
@@ -662,7 +688,7 @@ function FinalReveal({ v, players }: { v: LiarView; players: Record<string, Publ
<h2>🏆 {f.winner === 'liar' ? '라이어 승리' : '시민 승리'}</h2>
<span>{REASON_KO[f.reason]}.</span>
<span>
제시어 <span className="word">{f.word}</span> · 주제 {TOPIC_KO[f.topic]}
제시어 <span className="word">{f.word}</span> · 주제 {f.topicKo ?? topicName(f.topic)}
{f.liarWord ? ` · 라이어가 받은 단어: ${f.liarWord}` : ''}
{f.guess !== null ? ` · 라이어의 답: "${f.guess}"` : ''}
</span>
@@ -954,13 +980,16 @@ const secs = <T extends number>(...v: T[]): [T | null, string][] => [...v.map((x
function Options({ value: o, onChange }: OptionsProps<LiarOptions>) {
const [more, setMore] = useState(false);
const topics = useTopicChoices();
// A topic an admin deleted plays as 무작위 (shown as such so the host isn't left with a hidden choice).
const topic = o.topic === 'random' || topics.some((t) => t.id === o.topic) ? o.topic : 'random';
const set = (patch: Partial<LiarOptions>) => onChange({ ...o, ...patch });
return (
<div className="stack" style={{ gap: 16 }}>
<Field label="주제">
<Seg<LiarOptions['topic']> label="주제" value={o.topic} options={[['random', '무작위'], ...TOPIC_IDS.map((t): [LiarOptions['topic'], string] => [t, TOPIC_KO[t]])]} onChange={(topic) => set({ topic })} />
<Seg<string> label="주제" value={topic} options={[['random', '무작위'], ...topics.map((t): [string, string] => [t.id, t.ko])]} onChange={(next) => set({ topic: next })} />
</Field>
<Field label="바보 모드" help="켜면 라이어도 같은 주제의 다른 단어를 받고, 자기가 라이어인지 몰라요.">
<Field label="바보 모드" help="켜면 라이어도 제시어와 비슷한 다른 단어(같은 묶음)를 받고, 자기가 라이어인지 몰라요.">
<Seg label="바보 모드" value={o.foolMode} options={onOff} onChange={(foolMode) => set({ foolMode })} />
</Field>
<Field label="설명 바퀴 수" help="두 바퀴면 두 번째 바퀴는 거꾸로 돌아요.">
@@ -1015,7 +1044,8 @@ function Options({ value: o, onChange }: OptionsProps<LiarOptions>) {
}
function optionsSummary(o: LiarOptions): string {
const parts = [o.topic === 'random' ? '주제 무작위' : `주제 ${TOPIC_KO[o.topic]}`];
void loadTopics();
const parts = [o.topic === 'random' ? '주제 무작위' : `주제 ${topicName(o.topic)}`];
if (o.foolMode) parts.push('바보 모드');
parts.push(o.rounds === 2 ? '두 바퀴' : '한 바퀴', o.describeSeconds === null ? '설명 무제한' : `설명 ${o.describeSeconds}초`, o.discussionSeconds === null ? '토론 무제한' : `토론 ${o.discussionSeconds}초`, o.guessMode === 'choice' ? '정답은 목록에서' : '정답은 직접 적기');
return parts.join(' · ');
@@ -1038,7 +1068,7 @@ function Rules() {
<li>투표는 나를 뺀 한 명을 골라요. 동점이면 동점인 사람끼리 한 번 더 투표하고, 또 동점이면 라이어가 이겨요.</li>
<li>라이어가 아닌 사람이 지목되면 라이어 승리. 라이어가 지목되면 제시어를 한 번 맞힐 수 있어요(띄어쓰기·대소문자 무시). 맞히면 라이어, 틀리면 시민 승리예요.</li>
<li>점수: 시민이 이기면 시민마다 1점, 라이어가 이기면 라이어 2점.</li>
<li>바보 모드: 라이어도 같은 주제의 다른 단어를 받고, 자기가 라이어인지 몰라요.</li>
<li>바보 모드: 라이어도 제시어와 비슷한 다른 단어(같은 주제, 같은 묶음)를 받고, 자기가 라이어인지 몰라요.</li>
<li>시간 무제한: 설명·토론·투표·정답 맞히기 시간을 무제한으로 할 수 있어요. 그 단계는 할 일을 다 마칠 때까지 기다려요.</li>
</ul>
<p className="small muted">내 제시어는 "내 제시어" 카드를 꾹 누르고 있을 때만 보여요. 게임 중에는 방 채팅 대신 게임 화면의 채팅을 써요.</p>