-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-renderer.js
More file actions
227 lines (201 loc) · 6.4 KB
/
ui-renderer.js
File metadata and controls
227 lines (201 loc) · 6.4 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
* ui-renderer.js
* DOM manipulation and UI rendering
*
* Handles rendering of game phases, modals, and dynamic UI updates.
*/
import { generateFeedbackBoxesHTML, generateClueInputBoxesHTML } from './game-engine.js';
/**
* Show welcome screen
*/
export function showWelcomeScreen() {
try {
const welcomeScreen = document.getElementById('welcomeScreen');
const gameContainer = document.getElementById('initialGuessContainer');
const cluePhase = document.getElementById('cluePhaseContainer');
const gameComplete = document.getElementById('gameCompleteContainer');
if (welcomeScreen) welcomeScreen.style.display = 'flex';
if (gameContainer) gameContainer.style.display = 'none';
if (cluePhase) cluePhase.style.display = 'none';
if (gameComplete) gameComplete.style.display = 'none';
console.log('[UI] Welcome screen displayed');
} catch (error) {
console.error('[UI] Failed to show welcome screen:', error);
}
}
/**
* Show game screen (initial guess phase)
*/
export function showGameScreen() {
try {
const welcomeScreen = document.getElementById('welcomeScreen');
const gameContainer = document.getElementById('initialGuessContainer');
const audioControls = document.getElementById('audioControls');
const progressCounter = document.getElementById('progressCounter');
if (welcomeScreen) welcomeScreen.style.display = 'none';
if (gameContainer) gameContainer.style.display = 'flex';
if (audioControls) audioControls.style.display = 'flex';
if (progressCounter) progressCounter.style.display = 'block';
// Focus input
const guessInput = document.getElementById('guessInput');
if (guessInput) {
guessInput.focus();
guessInput.value = '';
}
console.log('[UI] Game screen displayed');
} catch (error) {
console.error('[UI] Failed to show game screen:', error);
}
}
/**
* Show clue phase
*/
export function showCluePhase(feedbackHTML, clueHTML) {
try {
const cluePhase = document.getElementById('cluePhaseContainer');
const gameContainer = document.getElementById('initialGuessContainer');
if (gameContainer) gameContainer.style.display = 'none';
if (cluePhase) {
cluePhase.innerHTML = feedbackHTML + clueHTML;
cluePhase.style.display = 'flex';
}
console.log('[UI] Clue phase displayed');
} catch (error) {
console.error('[UI] Failed to show clue phase:', error);
}
}
/**
* Show game complete screen
*/
export function showGameComplete() {
try {
const gameComplete = document.getElementById('gameCompleteContainer');
const gameContainer = document.getElementById('initialGuessContainer');
const cluePhase = document.getElementById('cluePhaseContainer');
const progressCounter = document.getElementById('progressCounter');
if (gameContainer) gameContainer.style.display = 'none';
if (cluePhase) cluePhase.style.display = 'none';
if (progressCounter) progressCounter.style.display = 'none';
if (gameComplete) gameComplete.style.display = 'flex';
console.log('[UI] Game complete screen displayed');
} catch (error) {
console.error('[UI] Failed to show game complete:', error);
}
}
/**
* Show modal
* @param {string} modalId - Modal element ID
*/
export function showModal(modalId) {
try {
const modal = document.getElementById(modalId);
if (modal) {
modal.style.display = 'flex';
console.log(`[UI] Modal ${modalId} displayed`);
}
} catch (error) {
console.error(`[UI] Failed to show modal ${modalId}:`, error);
}
}
/**
* Hide modal
* @param {string} modalId - Modal element ID
*/
export function hideModal(modalId) {
try {
const modal = document.getElementById(modalId);
if (modal) {
modal.style.display = 'none';
console.log(`[UI] Modal ${modalId} hidden`);
}
} catch (error) {
console.error(`[UI] Failed to hide modal ${modalId}:`, error);
}
}
/**
* Update progress counter
* @param {number} current - Current word index (1-based)
* @param {number} total - Total words in lesson
*/
export function updateProgressCounter(current, total) {
try {
const counter = document.getElementById('progressCounter');
if (counter) {
counter.textContent = `Word ${current} of ${total}`;
console.log(`[UI] Progress updated: ${current}/${total}`);
}
} catch (error) {
console.error('[UI] Failed to update progress counter:', error);
}
}
/**
* Display feedback boxes
* @param {Object} feedbackData - Feedback from game-engine
*/
export function displayFeedback(feedbackData) {
try {
const feedbackHTML = generateFeedbackBoxesHTML(feedbackData);
const cluePhase = document.getElementById('cluePhaseContainer');
if (cluePhase) {
cluePhase.innerHTML = feedbackHTML;
cluePhase.style.display = 'flex';
}
console.log('[UI] Feedback displayed');
} catch (error) {
console.error('[UI] Failed to display feedback:', error);
}
}
/**
* Display clue input boxes
* @param {string} word - Target word
*/
export function displayClueInputs(word) {
try {
const clueHTML = generateClueInputBoxesHTML(word);
const cluePhase = document.getElementById('cluePhaseContainer');
if (cluePhase) {
cluePhase.innerHTML += clueHTML;
}
console.log('[UI] Clue inputs displayed');
} catch (error) {
console.error('[UI] Failed to display clue inputs:', error);
}
}
/**
* Update lesson stats modal
* @param {Object} stats - Stats object
*/
export function updateLessonStats(stats) {
try {
const statsDisplay = document.getElementById('lessonStats');
if (statsDisplay) {
let html = '';
if (stats.accuracy !== undefined) {
html += `<div><strong>Accuracy:</strong> ${stats.accuracy}%</div>`;
}
if (stats.duration !== undefined) {
const mins = Math.floor(stats.duration / 60);
const secs = stats.duration % 60;
html += `<div><strong>Time:</strong> ${mins}:${secs.toString().padStart(2, '0')}</div>`;
}
if (stats.correctGuesses !== undefined) {
html += `<div><strong>Correct Guesses:</strong> ${stats.correctGuesses}</div>`;
}
statsDisplay.innerHTML = html;
}
} catch (error) {
console.error('[UI] Failed to update lesson stats:', error);
}
}
export default {
showWelcomeScreen,
showGameScreen,
showCluePhase,
showGameComplete,
showModal,
hideModal,
updateProgressCounter,
displayFeedback,
displayClueInputs,
updateLessonStats
};