users fix
This commit is contained in:
parent
5cabdba72f
commit
560f016b08
3 changed files with 53 additions and 14 deletions
|
|
@ -322,7 +322,26 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect, On
|
||||||
|
|
||||||
if (!room) return;
|
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 если не установлен или невалиден
|
// Инициализация currentQuestionId если не установлен или невалиден
|
||||||
let currentQuestionId = (room.currentQuestionId as string | null) || null;
|
let currentQuestionId = (room.currentQuestionId as string | null) || null;
|
||||||
|
|
@ -383,16 +402,23 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect, On
|
||||||
role: p.role,
|
role: p.role,
|
||||||
score: p.score
|
score: p.score
|
||||||
})),
|
})),
|
||||||
questions: questions.map((q) => ({
|
questions: questions.map((q: any) => {
|
||||||
id: q.id,
|
// Убеждаемся, что у вопроса есть 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 || '',
|
text: q.text || q.question || '',
|
||||||
answers: (q.answers || []).map((a) => ({
|
answers: (q.answers || []).map((a: any) => ({
|
||||||
id: a.id,
|
id: a.id || `answer-${Math.random()}`,
|
||||||
text: a.text,
|
text: a.text || '',
|
||||||
points: a.points
|
points: a.points || 0
|
||||||
}))
|
|
||||||
}))
|
}))
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
this.server.to(roomCode).emit('gameStateUpdated', fullState);
|
this.server.to(roomCode).emit('gameStateUpdated', fullState);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const Game = forwardRef(({
|
||||||
const handleAnswerClick = (answerId, points) => {
|
const handleAnswerClick = (answerId, points) => {
|
||||||
if (!currentQuestion) return;
|
if (!currentQuestion) return;
|
||||||
if (revealedAnswers.includes(answerId)) return; // Проверка по UUID
|
if (revealedAnswers.includes(answerId)) return; // Проверка по UUID
|
||||||
if (!currentPlayerId) return;
|
// Убираем проверку currentPlayerId - хост может открывать ответы вручную
|
||||||
if (!onAnswerClick) return;
|
if (!onAnswerClick) return;
|
||||||
|
|
||||||
onAnswerClick(answerId, points); // Передаем UUID
|
onAnswerClick(answerId, points); // Передаем UUID
|
||||||
|
|
@ -48,7 +48,7 @@ const Game = forwardRef(({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{players.length > 0 && currentPlayerId ? (
|
{players.length > 0 ? (
|
||||||
<div className="game-content">
|
<div className="game-content">
|
||||||
{currentQuestion ? (
|
{currentQuestion ? (
|
||||||
<Question
|
<Question
|
||||||
|
|
|
||||||
|
|
@ -115,8 +115,8 @@ const GamePage = () => {
|
||||||
const myParticipant = gameState.participants.find(p => p.userId === user.id);
|
const myParticipant = gameState.participants.find(p => p.userId === user.id);
|
||||||
if (!myParticipant) return;
|
if (!myParticipant) return;
|
||||||
|
|
||||||
// Проверка очереди
|
// Проверка очереди (только для не-хостов)
|
||||||
if (gameState.currentPlayerId !== myParticipant.id) {
|
if (!isHost && gameState.currentPlayerId !== myParticipant.id) {
|
||||||
alert('Сейчас не ваша очередь!');
|
alert('Сейчас не ваша очередь!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -271,6 +271,19 @@ const GamePage = () => {
|
||||||
q => q.id === gameState.currentQuestionId
|
q => q.id === gameState.currentQuestionId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Отладочная информация
|
||||||
|
useEffect(() => {
|
||||||
|
if (gameState.questions.length > 0) {
|
||||||
|
console.log('📋 Questions loaded:', gameState.questions.length);
|
||||||
|
console.log('🔍 Current question ID:', gameState.currentQuestionId);
|
||||||
|
console.log('✅ Current question found:', !!currentQuestion);
|
||||||
|
if (!currentQuestion && gameState.currentQuestionId) {
|
||||||
|
console.warn('⚠️ Question ID not found in questions list:', gameState.currentQuestionId);
|
||||||
|
console.log('📝 Available question IDs:', gameState.questions.map(q => q.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [gameState.questions, gameState.currentQuestionId, currentQuestion]);
|
||||||
|
|
||||||
const revealedForCurrentQ = gameState.revealedAnswers[gameState.currentQuestionId] || [];
|
const revealedForCurrentQ = gameState.revealedAnswers[gameState.currentQuestionId] || [];
|
||||||
|
|
||||||
const playerScores = gameState.participants.reduce(
|
const playerScores = gameState.participants.reduce(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue