kaboot/types.ts

99 lines
No EOL
2.3 KiB
TypeScript

export type GameState =
| 'LANDING'
| 'CREATING'
| 'GENERATING'
| 'LOBBY'
| 'COUNTDOWN'
| 'QUESTION'
| 'REVEAL'
| 'SCOREBOARD'
| 'PODIUM';
export type GameRole = 'HOST' | 'CLIENT';
export interface AnswerOption {
text: string;
isCorrect: boolean;
shape: 'triangle' | 'diamond' | 'circle' | 'square';
color: 'red' | 'blue' | 'yellow' | 'green';
reason?: string; // Explanation for why this answer is correct or incorrect
}
export interface Question {
id: string;
text: string;
options: AnswerOption[];
timeLimit: number; // in seconds
}
export interface Quiz {
title: string;
questions: Question[];
}
export type QuizSource = 'manual' | 'ai_generated';
export interface SavedQuiz extends Quiz {
id: string;
source: QuizSource;
aiTopic?: string;
createdAt: string;
updatedAt: string;
}
export interface QuizListItem {
id: string;
title: string;
source: QuizSource;
aiTopic?: string;
questionCount: number;
createdAt: string;
updatedAt: string;
}
export interface ProcessedDocument {
type: 'native' | 'text';
content: string | Buffer;
mimeType?: string;
}
export interface GenerateQuizOptions {
topic?: string;
questionCount?: number;
documents?: ProcessedDocument[];
}
export interface Player {
id: string;
name: string;
score: number;
streak: number;
lastAnswerCorrect: boolean | null;
isBot: boolean;
avatarSeed: number;
color: string;
}
// Network Types
export type NetworkMessage =
| { type: 'JOIN'; payload: { name: string } }
| { type: 'WELCOME'; payload: { playerId: string; quizTitle: string; players: Player[] } }
| { type: 'PLAYER_JOINED'; payload: { player: Player } }
| { type: 'GAME_START'; payload: {} }
| { type: 'START_COUNTDOWN'; payload: { duration: number } }
| {
type: 'QUESTION_START';
payload: {
totalQuestions: number;
currentQuestionIndex: number;
timeLimit: number;
correctShape: string;
questionText: string;
options: AnswerOption[];
}
}
| { type: 'ANSWER'; payload: { playerId: string; isCorrect: boolean } }
| { type: 'RESULT'; payload: { isCorrect: boolean; scoreAdded: number; newScore: number } }
| { type: 'TIME_UP'; payload: {} }
| { type: 'SHOW_SCOREBOARD'; payload: { players: Player[] } }
| { type: 'GAME_OVER'; payload: { players: Player[] } };