diff --git a/backend/src/game/game.gateway.ts b/backend/src/game/game.gateway.ts index c920ee9..5045f3e 100644 --- a/backend/src/game/game.gateway.ts +++ b/backend/src/game/game.gateway.ts @@ -322,7 +322,26 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect, On if (!room) return; - const questions = ((room.roomPack as unknown as { questions?: Question[] } | null)?.questions || []) as Question[]; + // Извлекаем вопросы из roomPack.questions (JSON поле) + const roomPackQuestions = (room.roomPack as unknown as { questions?: any } | null)?.questions; + let questions: Question[] = []; + + if (roomPackQuestions) { + // Если это уже массив, используем как есть + if (Array.isArray(roomPackQuestions)) { + questions = roomPackQuestions as Question[]; + } else if (typeof roomPackQuestions === 'string') { + // Если это строка, парсим JSON + try { + questions = JSON.parse(roomPackQuestions) as Question[]; + } catch (e) { + console.error('Error parsing roomPack.questions:', e); + questions = []; + } + } + } + + console.log(`📋 Room ${roomCode}: Found ${questions.length} questions`); // Инициализация currentQuestionId если не установлен или невалиден let currentQuestionId = (room.currentQuestionId as string | null) || null; @@ -383,15 +402,22 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect, On role: p.role, score: p.score })), - questions: questions.map((q) => ({ - id: q.id, - text: q.text || q.question || '', - answers: (q.answers || []).map((a) => ({ - id: a.id, - text: a.text, - points: a.points - })) - })) + questions: questions.map((q: any) => { + // Убеждаемся, что у вопроса есть id + const questionId = q.id || (typeof q === 'object' && 'id' in q ? q.id : null); + if (!questionId) { + console.warn('⚠️ Question without ID:', q); + } + return { + id: questionId || `temp-${Math.random()}`, + text: q.text || q.question || '', + answers: (q.answers || []).map((a: any) => ({ + id: a.id || `answer-${Math.random()}`, + text: a.text || '', + points: a.points || 0 + })) + }; + }) }; this.server.to(roomCode).emit('gameStateUpdated', fullState); diff --git a/src/components/Game.jsx b/src/components/Game.jsx index 3c5d0c1..02306b0 100644 --- a/src/components/Game.jsx +++ b/src/components/Game.jsx @@ -24,7 +24,7 @@ const Game = forwardRef(({ const handleAnswerClick = (answerId, points) => { if (!currentQuestion) return; if (revealedAnswers.includes(answerId)) return; // Проверка по UUID - if (!currentPlayerId) return; + // Убираем проверку currentPlayerId - хост может открывать ответы вручную if (!onAnswerClick) return; onAnswerClick(answerId, points); // Передаем UUID @@ -48,7 +48,7 @@ const Game = forwardRef(({ )} - {players.length > 0 && currentPlayerId ? ( + {players.length > 0 ? (