/** * Room settings (docs/04, docs/12). One schema for server validation, defaults and the web form. * Plain data so lite.ts can share the constants with the browser; the zod schema lives in room-config-schema.ts. */ export const MODES = [ { id: 'listen', label: '듣고맞추기', icon: '🎧' }, { id: 'artist', label: '가수노래 맞추기', icon: '🎤' }, { id: 'lyrics', label: '가사보고 맞추기', icon: '📜' }, { id: 'duel', label: '이지선다', icon: '🆚' }, ] as const; export type Mode = (typeof MODES)[number]['id']; /** 듣고맞출시간: seconds, 0 = 끝까지. */ export const LISTEN_SECS = [1, 3, 5, 10, 30, 60, 0] as const; /** 보고맞출시간: seconds, 0 = 무제한. */ export const LYRICS_SECS = [30, 60, 90, 120, 150, 0] as const; export const HINT_TIMES = [15, 30, 45, 60] as const; /** 스킵·힌트·다시듣기 인원(이상). 'none' = 불가. */ export const VOTE_RULES = ['none', '1', '2', '1/3', '1/2', '2/3', 'all'] as const; export type VoteRule = (typeof VOTE_RULES)[number]; /** 문제 수, 0 = 무제한(조건에 맞는 곡 전부). */ export const COUNTS = [10, 20, 30, 50, 100, 0] as const; /** 다음 문제까지: seconds the answer stays on screen (the music goes on) before the next question. */ export const REVEAL_SECS = [5, 10, 15, 30] as const; /** 이지선다 제한 시간: seconds to pick a card. */ export const DUEL_SECS = [10, 15, 20, 30, 45, 60, 90] as const; /** 이지선다 진행: pairs = 매번 새 두 곡, chain = 조회수가 더 높은 곡이 남고 새 곡과 다시 비교. */ export const DUEL_FLOWS = [ { id: 'pairs', label: '매번 새 두 곡' }, { id: 'chain', label: '이긴 곡이 남기 (연속)' }, ] as const; export type DuelFlow = (typeof DUEL_FLOWS)[number]['id']; export interface RoomConfig { title: string; mode: Mode; listenSec: (typeof LISTEN_SECS)[number]; startAt: 'start' | 'highlight'; artistIds: number[]; lyricsSec: (typeof LYRICS_SECS)[number]; /** Empty = 전체. Same group "또는", different groups "그리고" (docs/04, Q9). */ genres: string[]; yearFrom: number | null; yearTo: number | null; /** Exactly this level (docs/12 Q7). */ level: number; answer: 'title' | 'artist' | 'both'; /** 정답인식: true = must match that element too (docs/12 Q2). Default: spaces ignored, digits and symbols must match. */ strict: { space: boolean; number: boolean; symbol: boolean }; /** 'none' | seconds | 'manual' (직접선택). */ hint: 'none' | (typeof HINT_TIMES)[number] | 'manual'; hintVotes: Exclude; skipVotes: VoteRule; replayVotes: VoteRule; revealSec: (typeof REVEAL_SECS)[number]; /** 다음문제인원: votes during the answer reveal that move on at once. */ nextVotes: VoteRule; count: (typeof COUNTS)[number]; visibility: 'public' | 'private' | 'password'; /** 이지선다: seconds to pick (the cards can be changed until then). */ duelSec: (typeof DUEL_SECS)[number]; duelFlow: DuelFlow; /** 제작된 퀴즈: the chosen quiz (일반 퀴즈 = listen mode, 이지선다 퀴즈 = duel mode); null = 직접 선택 (장르·연도·난이도). */ quizId: number | null; /** Name of that quiz, filled in by the server for room cards. */ quizName: string; } export const DEFAULT_ROOM_CONFIG: RoomConfig = { title: '', mode: 'listen', listenSec: 0, startAt: 'start', artistIds: [], lyricsSec: 0, genres: [], yearFrom: null, yearTo: null, level: 3, answer: 'title', strict: { space: false, number: true, symbol: true }, hint: 'none', hintVotes: '1/3', skipVotes: '1/3', replayVotes: '1/3', revealSec: 5, nextVotes: '1/3', count: 30, visibility: 'public', duelSec: 30, duelFlow: 'pairs', quizId: null, quizName: '', }; /** Level names (docs/04 난이도). */ export const LEVELS = [ ['누구나 아는 대표곡', '장르를 전혀 안 듣는 사람도 후렴을 따라 부를 수 있는 곡'], ['길거리 단골 노래', '방송, 매장, 길거리에서 워낙 자주 나와서 귀에 익은 곡'], ['한 번쯤 들어본 히트곡', '차트 상위권에 올라서 제목은 몰라도 대부분 들어본 곡'], ['가끔 들어도 아는 곡', '장르를 자주 안 들어도 차트에서 한 번쯤 접해본 곡'], ['장르 팬 필수곡', '크게 뜨진 않았지만 장르 팬이라면 다 아는 곡'], ['뒤늦게 알려진 곡', '입소문이나 역주행으로 뒤늦게 조금 알려진 곡'], ['고인물이 아끼는 숨은 명곡', '차트 성적은 없지만 고인물들 사이에서 명곡으로 꼽히는 곡'], ['찾아 들어야 아는 곡', '어디서도 들을 일이 없어서 직접 찾아 들은 사람만 아는 곡'], ['골수 리스너 인증곡', '고인물 중에서도 극소수만 들어본 곡'], ['인간 샤잠만 가능', '들어본 사람 자체가 거의 없는 곡'], ] as const; /** How many votes pass a rule with `n` connected players (rounded up, docs/05 스킵). null = voting off. */ export function voteThreshold(rule: VoteRule, n: number): number | null { if (rule === 'none') return null; if (n <= 0) return 1; const need = rule === '1' ? 1 : rule === '2' ? 2 : rule === 'all' ? n : Math.ceil((n * Number(rule[0])) / Number(rule[2])); return Math.max(1, Math.min(n, need)); } export function voteLabel(rule: VoteRule): string { return { none: '없음', '1': '1명', '2': '2명', '1/3': '1/3명', '1/2': '1/2명', '2/3': '2/3명', all: '전체' }[rule]; } export function listenLabel(s: number): string { return s === 0 ? '끝까지' : s >= 60 ? `${s / 60}분` : `${s}초`; } /** One-line summary for room cards (docs/03 열린 방 목록). */ export function configSummary(c: RoomConfig, genreName: (id: string) => string = (x) => x): string[] { const out: string[] = []; if (c.mode === 'duel') { out.push(`🆚 이지선다 · ${c.duelSec}초`, c.duelFlow === 'chain' ? '이긴 곡이 남기' : '매번 새 두 곡'); if (c.quizId) out.unshift(`📋 ${c.quizName || '이지선다 퀴즈'}`); return out; } if (c.quizId) { out.push(`📋 ${c.quizName || '제작된 퀴즈'}`, `🎧 ${listenLabel(c.listenSec)}${c.startAt === 'highlight' ? ' · 하이라이트' : ''}`); if (c.answer !== 'title') out.push(c.answer === 'both' ? '제목+가수' : '가수만'); out.push(`공개 ${c.revealSec}초`); return out; } if (c.mode === 'lyrics') out.push(`📜 가사 ${c.lyricsSec ? `${c.lyricsSec}초` : '무제한'}`); else out.push(`${c.mode === 'artist' ? '🎤' : '🎧'} ${listenLabel(c.listenSec)}${c.startAt === 'highlight' ? ' · 하이라이트' : ''}`); out.push(c.yearFrom || c.yearTo ? `${c.yearFrom ?? '처음'}~${c.yearTo ?? '지금'}` : '전체 연도'); out.push(c.genres.length ? c.genres.map(genreName).join(' · ') : '전체 장르'); out.push(`★${c.level}`); if (c.answer !== 'title') out.push(c.answer === 'both' ? '제목+가수' : '가수만'); out.push(`공개 ${c.revealSec}초`); return out; } /** 조회수 for people: 1.2억 · 3,456만 · 9,999 (exact numbers go in a tooltip). */ export function viewsLabel(n: number): string { if (n >= 1e8) return `${(Math.floor(n / 1e7) / 10).toLocaleString('ko-KR')}억`; if (n >= 1e4) return `${Math.floor(n / 1e4).toLocaleString('ko-KR')}만`; return n.toLocaleString('ko-KR'); }