제작된 퀴즈 1~3단계: 관리자 → 퀴즈(목록·추가·곡 목록: 서버 DB/유튜브 검색·주소로 추가, 끌어서·▲▼·번호로 순서, 복수정답은 연결된 DB 곡 별칭에도, 영상 바꾸기 / 설정: 설명·공개방식(비공개·일부공개·전체공개)·문제 순서·재생위치 기본·방 규칙). 저장은 버튼·Ctrl+S로만, 안 저장 시 탭 제목·표시·나가기 확인. 곡마다 처음·하이라이트 위치 편집기(영상+큰 재생바, 끌기·지금 위치로·여기서 듣기·±1초, 자동=0초+DB 하이라이트, 연령제한은 받아 둔 음원). 방 설정 '직접 선택 / 제작된 퀴즈'(검색·비공개/일부공개 먼저), 고르면 퀴즈 설정이 방 설정으로, 듣고맞추기·곡 전부, 곡별 위치로 재생, 플레이 수. 퀴즈당 곡 수·계정당 퀴즈 수 제한(사이트 설정, 기본 무제한). '퀴즈 저장·불러오기'는 '진행 저장·불러오기'로 이름 변경
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* everyone is paused; it keeps running after the clip ends.
|
||||
*/
|
||||
import { hintText, isCorrect, voteThreshold, type GameHistoryItem, type GamePhase, type GameView, type ServerMessage } from '@mq/shared';
|
||||
import { clipOf, loudnessGain, lyricsCard, mainArtists, markUnplayable, orderSongs, quizSong, type QuizSong } from '../songs/quiz';
|
||||
import { clipOf, loudnessGain, lyricsCard, mainArtists, markUnplayable, orderSongs, type QuizSong } from '../songs/quiz';
|
||||
import { poolIds } from '../songs/pool';
|
||||
import type { Room } from '../rooms/manager';
|
||||
|
||||
@@ -46,6 +46,15 @@ export const newQuiz = (): Quiz => ({ played: [], scores: new Map() });
|
||||
/** Build the song order for a game. Returns an error message when nothing is left. */
|
||||
export function pickSongs(room: Room): number[] | string {
|
||||
const db = room.deps.db;
|
||||
if (room.config.quizId) {
|
||||
// 제작된 퀴즈: every song of it, as listed or shuffled (퀴즈 설정 → 문제 순서)
|
||||
const q = room.deps.quizzes.get(room.config.quizId);
|
||||
if (!q) return '고른 퀴즈를 찾을 수 없어요. 다른 퀴즈를 골라 주세요.';
|
||||
const played = new Set(room.quiz.played);
|
||||
const ids = q.items.map((i) => i.id!).filter((id) => !played.has(id));
|
||||
if (!ids.length) return room.quiz.played.length ? '이 퀴즈의 곡을 모두 풀었어요.' : '이 퀴즈에 곡이 없어요.';
|
||||
return q.settings.order === 'random' ? orderSongs(ids, new Set(), new Map(), false) : ids;
|
||||
}
|
||||
const ids = poolIds(db, room.config, room.quiz.played);
|
||||
if (!ids.length) return room.quiz.played.length ? '조건에 맞는 곡을 모두 풀었어요.' : '조건에 맞는 곡이 없어요. 장르·연도·난이도를 넓혀 보세요.';
|
||||
const recent = new Set(room.recent.flat());
|
||||
@@ -96,7 +105,8 @@ export class Game {
|
||||
private timing: GameTiming,
|
||||
private now: () => number = Date.now,
|
||||
) {
|
||||
const c = room.config.count;
|
||||
// 제작된 퀴즈: every song of it
|
||||
const c = room.config.quizId ? 0 : room.config.count;
|
||||
this.total = c ? Math.min(c, list.length) : list.length;
|
||||
}
|
||||
|
||||
@@ -155,13 +165,14 @@ export class Game {
|
||||
/** Load question `n` (also used when a song is replaced under the same number). */
|
||||
private setup(): void {
|
||||
const c = this.room.config;
|
||||
this.total = c.count ? Math.min(c.count, this.list.length) : this.list.length;
|
||||
const count = c.quizId ? 0 : c.count;
|
||||
this.total = count ? Math.min(count, this.list.length) : this.list.length;
|
||||
let song: QuizSong | null = null;
|
||||
while (this.n <= this.total) {
|
||||
song = quizSong(this.room.deps.db, this.list[this.n - 1]!);
|
||||
song = this.room.loadSong(this.list[this.n - 1]!);
|
||||
if (song && (this.listening ? song.videoId && (!song.ageRestricted || (song.audio && this.room.deps.audio)) : song.lyrics)) break;
|
||||
this.list.splice(this.n - 1, 1);
|
||||
this.total = c.count ? Math.min(c.count, this.list.length) : this.list.length;
|
||||
this.total = count ? Math.min(count, this.list.length) : this.list.length;
|
||||
song = null;
|
||||
}
|
||||
if (!song) return this.finish();
|
||||
@@ -330,9 +341,10 @@ export class Game {
|
||||
this.asked.push(s.id);
|
||||
try {
|
||||
// 통계 (admin): never let a stats write break the game.
|
||||
this.room.deps.db
|
||||
.query('INSERT INTO song_plays (song_id, game_id, played_at, players, winner_id, ms, how) VALUES (?, ?, ?, ?, ?, ?, ?)')
|
||||
.run(s.id, this.gameId, now, Math.max(1, this.active().length), winner, ms, how === 'end' ? 'timeout' : how);
|
||||
if (s.dbSongId !== null)
|
||||
this.room.deps.db
|
||||
.query('INSERT INTO song_plays (song_id, game_id, played_at, players, winner_id, ms, how) VALUES (?, ?, ?, ?, ?, ?, ?)')
|
||||
.run(s.dbSongId, this.gameId, now, Math.max(1, this.active().length), winner, ms, how === 'end' ? 'timeout' : how);
|
||||
} catch {
|
||||
/* stats only */
|
||||
}
|
||||
@@ -425,8 +437,13 @@ export class Game {
|
||||
if (ev === 'error' && (code === 100 || code === 101 || code === 150) && (this.phase === 'prepare' || this.phase === 'play') && this.song) {
|
||||
// The video is gone or may not be embedded: swap the song for everyone, same question number (docs/12 Q1).
|
||||
// 연령제한 곡 also land here (150): the collector checks it and brings the song back with downloaded audio.
|
||||
markUnplayable(this.room.deps.db, this.song.id, code);
|
||||
this.room.deps.onUnplayable?.(this.song.id);
|
||||
// only the DB song's own video is marked (a 제작된 퀴즈 may use another video of it)
|
||||
const db = this.room.deps.db;
|
||||
const dbId = this.song.dbSongId;
|
||||
if (dbId !== null && db.query<{ y: string | null }, [number]>('SELECT youtube_id y FROM songs WHERE id = ?').get(dbId)?.y === this.song.videoId) {
|
||||
markUnplayable(db, dbId, code);
|
||||
this.room.deps.onUnplayable?.(dbId);
|
||||
}
|
||||
this.room.say(null, '이 곡은 재생할 수 없어서 다른 곡으로 바꿨어요');
|
||||
this.toActive({ t: 'pause', code: this.room.code, n: this.n });
|
||||
this.list.splice(this.n - 1, 1);
|
||||
|
||||
@@ -27,7 +27,7 @@ export class SavedQuizzes {
|
||||
|
||||
save(userId: string, name: string, config: RoomConfig, quiz: Quiz, now = Date.now()): number | string {
|
||||
const n = this.db.query<{ n: number }, [string]>('SELECT COUNT(*) n FROM saved_quizzes WHERE user_id = ?').get(userId)!.n;
|
||||
if (n >= SAVE_LIMIT) return `퀴즈는 ${SAVE_LIMIT}개까지 저장할 수 있어요. 안 쓰는 퀴즈를 지워 주세요.`;
|
||||
if (n >= SAVE_LIMIT) return `진행은 ${SAVE_LIMIT}개까지 저장할 수 있어요. 안 쓰는 것을 지워 주세요.`;
|
||||
const scores = [...quiz.scores].map(([id, s]) => ({ id, ...s }));
|
||||
const r = this.db
|
||||
.query<{ id: number }, [string, string, string, string, string, number, number, number]>(
|
||||
|
||||
Reference in New Issue
Block a user