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;
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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(({
|
|||
)}
|
||||
</div>
|
||||
|
||||
{players.length > 0 && currentPlayerId ? (
|
||||
{players.length > 0 ? (
|
||||
<div className="game-content">
|
||||
{currentQuestion ? (
|
||||
<Question
|
||||
|
|
|
|||
|
|
@ -115,8 +115,8 @@ const GamePage = () => {
|
|||
const myParticipant = gameState.participants.find(p => p.userId === user.id);
|
||||
if (!myParticipant) return;
|
||||
|
||||
// Проверка очереди
|
||||
if (gameState.currentPlayerId !== myParticipant.id) {
|
||||
// Проверка очереди (только для не-хостов)
|
||||
if (!isHost && gameState.currentPlayerId !== myParticipant.id) {
|
||||
alert('Сейчас не ваша очередь!');
|
||||
return;
|
||||
}
|
||||
|
|
@ -271,6 +271,19 @@ const GamePage = () => {
|
|||
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 playerScores = gameState.participants.reduce(
|
||||
|
|
|
|||
Loading…
Reference in a new issue