제작된 퀴즈 1~3단계: 관리자 → 퀴즈(목록·추가·곡 목록: 서버 DB/유튜브 검색·주소로 추가, 끌어서·▲▼·번호로 순서, 복수정답은 연결된 DB 곡 별칭에도, 영상 바꾸기 / 설정: 설명·공개방식(비공개·일부공개·전체공개)·문제 순서·재생위치 기본·방 규칙). 저장은 버튼·Ctrl+S로만, 안 저장 시 탭 제목·표시·나가기 확인. 곡마다 처음·하이라이트 위치 편집기(영상+큰 재생바, 끌기·지금 위치로·여기서 듣기·±1초, 자동=0초+DB 하이라이트, 연령제한은 받아 둔 음원). 방 설정 '직접 선택 / 제작된 퀴즈'(검색·비공개/일부공개 먼저), 고르면 퀴즈 설정이 방 설정으로, 듣고맞추기·곡 전부, 곡별 위치로 재생, 플레이 수. 퀴즈당 곡 수·계정당 퀴즈 수 제한(사이트 설정, 기본 무제한). '퀴즈 저장·불러오기'는 '진행 저장·불러오기'로 이름 변경

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-22 08:36:40 +09:00
parent e3cb623773
commit b56d1a8d0e
29 changed files with 2366 additions and 111 deletions

View File

@@ -0,0 +1,46 @@
import { z } from 'zod';
import { RoomConfigSchema } from './room-config-schema';
import { DEFAULT_QUIZ_SETTINGS, QUIZ_ROOM_KEYS, type QuizSettings } from './custom-quiz';
const roomPart = RoomConfigSchema.pick(Object.fromEntries(QUIZ_ROOM_KEYS.map((k) => [k, true])) as { [K in (typeof QUIZ_ROOM_KEYS)[number]]: true });
export const QuizSettingsSchema = roomPart.extend({ order: z.enum(['ordered', 'random']) });
const answers = z.array(z.string().trim().min(1).max(200)).max(30);
const sec = z.number().min(0).max(36000).nullable();
export const QuizItemSchema = z.object({
id: z.number().int().positive().optional(),
songId: z.number().int().positive().nullable(),
videoId: z.string().regex(/^[\w-]{11}$/),
title: z.string().trim().min(1).max(200),
artist: z.string().trim().min(1).max(200),
titleAnswers: answers,
artistAnswers: answers,
durationSec: z.number().int().min(0).max(36000).nullable(),
auto: z.boolean(),
startSec: sec,
highlightSec: sec,
});
export const QuizSaveSchema = z.object({
name: z.string().trim().min(1).max(60),
description: z.string().trim().max(500),
visibility: z.enum(['private', 'partial', 'public']),
settings: QuizSettingsSchema,
items: z.array(QuizItemSchema).max(5000),
});
export type QuizSave = z.infer<typeof QuizSaveSchema>;
/** Settings saved by an older version: unknown or invalid keys fall back to the defaults. */
export function parseQuizSettings(json: unknown): QuizSettings {
const merged = { ...DEFAULT_QUIZ_SETTINGS, ...(json && typeof json === 'object' ? json : {}) };
const r = QuizSettingsSchema.safeParse(merged);
if (r.success) return r.data as QuizSettings;
const out: Record<string, unknown> = { ...DEFAULT_QUIZ_SETTINGS };
for (const [k, v] of Object.entries(merged)) {
const one = QuizSettingsSchema.shape[k as keyof typeof QuizSettingsSchema.shape]?.safeParse(v);
if (one?.success) out[k] = one.data;
}
return out as unknown as QuizSettings;
}

View File

@@ -0,0 +1,62 @@
/**
* 제작된 퀴즈 (admin-made quizzes): a list of songs with their own answers and start/highlight positions,
* plus the room settings a room takes over when it picks the quiz. Plain data for the browser; zod in custom-quiz-schema.ts.
*/
import { DEFAULT_ROOM_CONFIG, type RoomConfig } from './room-config';
/** 비공개: only the maker's rooms · 일부공개: the maker's and admins' rooms · 전체공개: everyone. */
export const QUIZ_VISIBILITIES = [
{ id: 'private', label: '비공개', help: '내 계정으로 방을 만들 때만 고를 수 있어요.' },
{ id: 'partial', label: '일부공개', help: '나와 관리자 계정으로 방을 만들 때만 고를 수 있어요.' },
{ id: 'public', label: '전체공개', help: '누구나 고를 수 있어요. 곡은 관리자 검토를 거쳐 서버 노래 DB에도 들어가요.' },
] as const;
export type QuizVisibility = (typeof QUIZ_VISIBILITIES)[number]['id'];
/** Room settings a quiz carries as its defaults (the host may still change them in the room). */
export const QUIZ_ROOM_KEYS = ['listenSec', 'startAt', 'answer', 'strict', 'hint', 'hintVotes', 'skipVotes', 'replayVotes', 'revealSec', 'nextVotes'] as const;
export type QuizRoomDefaults = Pick<RoomConfig, (typeof QUIZ_ROOM_KEYS)[number]>;
export interface QuizSettings extends QuizRoomDefaults {
/** 문제 순서: as listed or shuffled each game. */
order: 'ordered' | 'random';
}
export const DEFAULT_QUIZ_SETTINGS: QuizSettings = {
...(Object.fromEntries(QUIZ_ROOM_KEYS.map((k) => [k, DEFAULT_ROOM_CONFIG[k]])) as QuizRoomDefaults),
order: 'ordered',
};
export interface QuizItem {
/** Stable id once saved; absent for a song added since the last save. */
id?: number;
/** The server DB song this item is (its aliases also count as answers), null when it is not in the DB. */
songId: number | null;
videoId: string;
title: string;
artist: string;
/** Extra accepted answers for this quiz (also added to the DB song's aliases on save). */
titleAnswers: string[];
artistAnswers: string[];
durationSec: number | null;
/** 자동: start at 0 and the DB highlight; off = startSec/highlightSec below. */
auto: boolean;
startSec: number | null;
highlightSec: number | null;
}
export interface QuizSummary {
id: number;
name: string;
description: string;
visibility: QuizVisibility;
songs: number;
plays: number;
ownerId: string;
ownerName: string;
updatedAt: number;
}
export interface QuizDetail extends QuizSummary {
settings: QuizSettings;
items: QuizItem[];
}

View File

@@ -5,3 +5,5 @@ export * from './match-key';
export * from './room-config';
export * from './room-config-schema';
export * from './answer';
export * from './custom-quiz';
export * from './custom-quiz-schema';

View File

@@ -3,3 +3,4 @@ export * from './nickname';
export * from './types';
export * from './room-config';
export type { ChatLine, RoomView, RoomPlayerView, ServerMessage, GameView, GameScore, GameHistoryItem, GamePhase } from './protocol';
export * from './custom-quiz';

View File

@@ -24,6 +24,8 @@ export const RoomConfigSchema = z.object({
nextVotes: z.enum(VOTE_RULES),
count: lit(COUNTS),
visibility: z.enum(['public', 'private', 'password']),
quizId: z.number().int().positive().nullable(),
quizName: z.string().max(60),
});
/** Partial update from the host; returns the merged config or an error message. */
@@ -34,6 +36,7 @@ export function applyConfigPatch(cur: RoomConfig, patch: unknown): RoomConfig |
if (!r.success) return `설정 값이 올바르지 않아요: ${r.error.issues.map((i) => i.path.join('.')).join(', ')}`;
const c = r.data as RoomConfig;
if (c.yearFrom && c.yearTo && c.yearFrom > c.yearTo) return '시작 연도가 끝 연도보다 늦어요.';
if (c.quizId && c.mode !== 'listen') return '제작된 퀴즈는 듣고맞추기에서만 할 수 있어요.';
return c;
}

View File

@@ -49,6 +49,10 @@ export interface RoomConfig {
nextVotes: VoteRule;
count: (typeof COUNTS)[number];
visibility: 'public' | 'private' | 'password';
/** 제작된 퀴즈: the chosen quiz (listen mode only, every song of it); null = 직접 선택 (장르·연도·난이도). */
quizId: number | null;
/** Name of that quiz, filled in by the server for room cards. */
quizName: string;
}
export const DEFAULT_ROOM_CONFIG: RoomConfig = {
@@ -72,6 +76,8 @@ export const DEFAULT_ROOM_CONFIG: RoomConfig = {
nextVotes: '1/3',
count: 30,
visibility: 'public',
quizId: null,
quizName: '',
};
/** Level names (docs/04 난이도). */
@@ -107,6 +113,12 @@ export function listenLabel(s: number): string {
/** 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.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 ?? '지금'}` : '전체 연도');