File size: 1,630 Bytes
5dd5427
0787f2d
 
5dd5427
0787f2d
 
5dd5427
 
 
0787f2d
5dd5427
0787f2d
5dd5427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Main application entry point
import ClozeGameEngine from './clozeGameEngine.js';
import bookDataService from './bookDataService.js';
import { AIService } from './aiService.js';
import ChatInterface from './chatInterface.js';
import ConversationManager from './conversationManager.js';

class ClozeReaderApp {
    constructor() {
        this.bookDataService = bookDataService; // Already instantiated
        this.aiService = new AIService();
        this.gameEngine = new ClozeGameEngine();
        this.chatInterface = new ChatInterface(this.aiService);
        this.conversationManager = new ConversationManager(this.aiService);
        
        this.init();
    }

    async init() {
        try {
            // Initialize services
            await this.bookDataService.initialize();
            
            // Start the game
            await this.gameEngine.initialize();
            
            // Initialize chat interface
            this.chatInterface.initialize();
            
            console.log('Cloze Reader application initialized successfully');
        } catch (error) {
            console.error('Failed to initialize application:', error);
            this.showError('Failed to load the application. Please refresh the page.');
        }
    }

    showError(message) {
        const loadingElement = document.getElementById('loading');
        if (loadingElement) {
            loadingElement.innerHTML = `<p class="text-red-600">${message}</p>`;
        }
    }
}

// Initialize the application when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    new ClozeReaderApp();
});