/** * Renders a case's design doc (docs/games/case-file-cases/.md) from its data plus its check file, so the doc and * the data can never drift (cases.test.ts compares the file with this output; `bun scripts/case-file-doc.ts` rewrites it). * Same section layout as the hand-written cases 1~3 in case-file-cases.md. Test/doc only: never imported by the game. */ import { CASE_LIST, type CaseData } from '../types'; /** Per-case check data (checks/.ts): the doc number, the tight path tested by cases.test.ts and the timeline. */ export interface CaseCheck { /** Section number in the docs ("사건 4"). */ n: number; /** "빠듯한 길": leads read per day with 6 hours a day, no overtime, no magnifier, no hint. */ tight: string[][]; /** Markdown for "앞뒤 맞추기 점검표": timeline table + checks (no heading). */ timeline: string; } const NUM = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩']; const short = (id: string) => id.replace(/^c\d+-/, ''); export function caseStats(c: CaseData) { const max = c.questions.reduce((n, q) => n + q.points, 0); const hours = c.leads.reduce((n, l) => n + l.hours, 0); return { max, hours, leads: c.leads.length, questions: c.questions.length }; } export function renderCaseDoc(c: CaseData, check: CaseCheck): string { const n = check.n; const s = caseStats(c); const out: string[] = []; const zoneName = (z: string) => c.zones.find((x) => x.id === z)?.name ?? z; const placeName = (p: string) => c.places.find((x) => x.id === p)?.name ?? p; const leadRef = (ids: string[]) => (ids.length === 0 ? '처음부터' : ids.map((x) => `\`${x}\``).join(' 또는 ')); out.push(`# 사건 ${n}. ${c.title} (\`${c.id}\`)`, ''); out.push( '> 이 파일은 `bun scripts/case-file-doc.ts`가 사건 데이터(`packages/games/src/case-file/cases/' + c.id + '.ts`)와 점검 파일(`checks/' + c.id + '.ts`)로 만든다. 직접 고치지 말고 데이터를 고친 뒤 다시 만들 것. **스포일러 주의**: 정답이 있다.', '', ); out.push( `> 난이도 ${c.level} · ${c.days}일 · 단서 ${s.leads}개(합계 ${s.hours}시간) · 문제 ${s.questions}개 · 만점 ${s.max}점 · 해결 기준 ${c.pass}점(범인 문제 정답 필수) · S ${c.gradeS}점 / A ${c.gradeA}점`, '', ); out.push(`한 줄 소개(방 설정에 보이는 글): ${CASE_LIST.find((x) => x.id === c.id)?.pitch ?? ''}`, ''); out.push(`## ${n}.1 의뢰 (briefing)`, c.briefing, ''); out.push(`## ${n}.2 구역·장소·이동`, '| 구역 | 장소(id) |', '|---|---|'); for (const z of c.zones) { const ps = c.places.filter((p) => p.zone === z.id).map((p) => `${p.name} \`${p.id}\``); out.push(`| ${z.name} \`${z.id}\` | ${ps.join(', ')} |`); } out.push('', `| 이동 시간 | ${c.zones.map((z) => z.name).join(' | ')} |`, `|---|${c.zones.map(() => '---').join('|')}|`); for (const a of c.zones) out.push(`| ${a.name} | ${c.zones.map((b) => (a.id === b.id ? '–' : String(c.travel[a.id]?.[b.id]))).join(' | ')} |`); out.push(''); out.push(`## ${n}.3 인물 (자료실 카드)`, '| id | 이름 | 한 줄 | 처음 알려 주는 단서 |', '|---|---|---|---|'); for (const p of c.people) out.push(`| \`${p.id}\` | ${p.name} | ${p.line} | ${p.from.length ? p.from.map((x) => `\`${x}\``).join(', ') : '의뢰'} |`); out.push(''); out.push(`## ${n}.4 단서 목록`, '| id | 장소 | 제목 | 시간 | 열리는 조건 | 깊이 보기 |', '|---|---|---|---|---|---|'); for (const l of c.leads) { const deep = l.deep ? (l.deepOpens?.length ? `🔍 → ${l.deepOpens.map((x) => `\`${x}\``).join(', ')}` : '🔍') : ''; out.push(`| \`${l.id}\` | ${placeName(l.place)} (${zoneName(c.places.find((p) => p.id === l.place)?.zone ?? '')}) | ${l.title} | ${l.hours} | ${leadRef(l.from)} | ${deep} |`); } out.push(''); out.push(`## ${n}.5 단서 본문`, ''); for (const l of c.leads) { out.push(`### \`${l.id}\` ${l.title}`, l.text, ''); if (l.deep) out.push(`- **깊이 보기**: ${l.deep}`, ''); } out.push(`## ${n}.6 아침 소식`); if (c.news.length === 0) out.push('- 없음'); for (const x of c.news) out.push(`- ${x.day}일째 아침: ${x.text}`); out.push(''); out.push(`## ${n}.7 조언 (쓸 때마다 −2점)`); c.hints.forEach((h, i) => out.push(`${i + 1}. ${h}`)); out.push(''); out.push(`## ${n}.8 보고서 문제`, '| id | 문제 | 보기 | 정답 | 점수 | 근거 단서 |', '|---|---|---|---|---|---|'); for (const q of c.questions) { out.push( `| \`${q.id}\`${q.culprit ? ' (범인)' : ''} | ${q.text} | ${q.choices.map((x, i) => `${NUM[i]} ${x}`).join(' ')} | ${NUM[q.answer]} | ${q.points} | ${q.evidence.map(short).join(', ')} |`, ); } out.push(''); out.push(`## ${n}.9 정답과 풀이 (끝난 뒤 공개)`, c.solution, ''); out.push(`## ${n}.10 앞뒤 맞추기 점검표`, check.timeline.trim(), ''); out.push( `- 빠듯한 길(하루 6시간, 야근·돋보기·조언 없이, \`cases.test.ts\`가 실제 엔진으로 따라감): ${check.tight.map((d, i) => `${i + 1}일 ${d.map(short).join('·')}`).join(' / ')}`, '', ); return out.join('\n'); }