ballcoman commited on
Commit
5f10a09
·
verified ·
1 Parent(s): c57817b

Upload 20 files

Browse files
Files changed (6) hide show
  1. index.html +1 -1
  2. js/app.js +64 -102
  3. js/config.js +1 -1
  4. js/engine.js +2 -0
  5. js/talleres/taller4.js +3 -3
  6. js/teacherUI.js +1 -1
index.html CHANGED
@@ -111,7 +111,7 @@
111
 
112
  <div id="planet-4" class="planet-item locked" onclick="app.launchWorkshop(4)">
113
  <div class="planet-icon p-battle" style="background: radial-gradient(circle, #ff9f43, #ee5253); box-shadow: 0 0 20px #ee5253; font-size:1.8rem;">⚔️</div>
114
- <span>Misión Final: La Gran Batalla</span>
115
  </div>
116
 
117
  <div id="planet-5" class="planet-item locked" onclick="app.launchWorkshop(5)">
 
111
 
112
  <div id="planet-4" class="planet-item locked" onclick="app.launchWorkshop(4)">
113
  <div class="planet-icon p-battle" style="background: radial-gradient(circle, #ff9f43, #ee5253); box-shadow: 0 0 20px #ee5253; font-size:1.8rem;">⚔️</div>
114
+ <span>Misión 4: La Gran Batalla del Cristal</span>
115
  </div>
116
 
117
  <div id="planet-5" class="planet-item locked" onclick="app.launchWorkshop(5)">
js/app.js CHANGED
@@ -1,7 +1,7 @@
1
  import { supabase } from './config.js';
2
  import { gameEngine } from './engine.js';
3
  import { teacherUI } from './teacherUI.js';
4
- import { ui } from './ui.js'; // Importamos el objeto UI
5
 
6
  // Importación de los 6 Talleres
7
  import { taller1Data } from './talleres/taller1.js';
@@ -23,84 +23,33 @@ export const app = {
23
 
24
  if (session) {
25
  app.user = session.user;
26
-
27
- const canEnter = await app.checkSessionAvailability(session.user.id);
28
-
29
- if (canEnter) {
30
- app.loadUserProfile();
31
- } else {
32
- console.warn("Sesión activa en otro dispositivo. Cerrando...");
33
- await supabase.auth.signOut();
34
- alert("⛔ ACCESO DENEGADO\nEsta cuenta ya está activa en otro dispositivo.\nIntenta de nuevo en 2 minutos.");
35
- app.showScreen('view-login');
36
- }
37
  } else {
38
  app.showScreen('view-login');
39
  }
40
 
41
  supabase.auth.onAuthStateChange(async (event, session) => {
42
  if (event === 'SIGNED_IN' && session) {
43
- const canEnter = await app.checkSessionAvailability(session.user.id);
44
- if (canEnter) {
45
- app.user = session.user;
46
- app.loadUserProfile();
47
- } else {
48
- await supabase.auth.signOut();
49
- alert("⛔ ACCESO DENEGADO\nCuenta activa en otro lugar.");
50
- location.reload();
51
- }
52
  }
53
  if (event === 'SIGNED_OUT') {
54
  app.stopHeartbeat();
55
  app.showScreen('view-login');
 
56
  }
57
  });
58
  },
59
 
60
  finishIntro: () => {
61
- app.startHeartbeat();
62
  app.showScreen('view-map');
63
  },
64
 
65
- checkSessionAvailability: async (userId) => {
66
- const { data, error } = await supabase
67
- .from('estudiantes')
68
- .select('ultima_actividad')
69
- .eq('id', userId)
70
- .single();
71
-
72
- if (error || !data) return true;
73
-
74
- const lastActive = data.ultima_actividad ? new Date(data.ultima_actividad) : null;
75
- if (!lastActive) return true;
76
-
77
- const now = new Date();
78
- const diffMinutes = (now - lastActive) / 1000 / 60;
79
-
80
- if (diffMinutes < 2) {
81
- return false;
82
- }
83
- return true;
84
- },
85
-
86
- startHeartbeat: () => {
87
- app.sendPulse();
88
- app.heartbeatInterval = setInterval(() => {
89
- app.sendPulse();
90
- }, 60000);
91
- },
92
-
93
- sendPulse: async () => {
94
- if (!app.user || app.role !== 'student') return;
95
- await supabase
96
- .from('estudiantes')
97
- .update({ ultima_actividad: new Date().toISOString() })
98
- .eq('id', app.user.id);
99
- },
100
-
101
- stopHeartbeat: () => {
102
- if (app.heartbeatInterval) clearInterval(app.heartbeatInterval);
103
- },
104
 
105
  setupAutoLogout: () => {
106
  let timer;
@@ -140,23 +89,20 @@ export const app = {
140
  },
141
 
142
  logout: async () => {
143
- app.stopHeartbeat();
144
- if (app.user && app.role === 'student') {
145
- await supabase.from('estudiantes').update({ ultima_actividad: null }).eq('id', app.user.id);
146
- }
147
  await supabase.auth.signOut();
148
- location.reload();
149
  },
150
 
151
  loadUserProfile: async () => {
152
- app.setupAutoLogout();
153
 
154
- let { data: docente } = await supabase
 
155
  .from('docentes')
156
  .select('*')
157
  .eq('id', app.user.id)
158
  .single();
159
 
 
160
  if (docente) {
161
  app.profile = docente;
162
  app.role = 'teacher';
@@ -167,24 +113,30 @@ export const app = {
167
  if(document.querySelector('.energy-display')) document.querySelector('.energy-display').style.display = 'none';
168
  if(document.getElementById('btn-teacher-panel')) document.getElementById('btn-teacher-panel').classList.remove('hidden');
169
 
170
- alert("Bienvenido Profesor. Cargando Centro de Comando.");
171
-
172
- setTimeout(() => {
173
- for (let i = 2; i <= 6; i++) {
174
- const planet = document.getElementById(`planet-${i}`);
175
- if (planet) {
176
- planet.classList.remove('locked');
177
- planet.classList.add('unlocked');
178
- }
179
  }
180
- }, 500);
181
 
182
- teacherUI.renderDashboard();
183
- app.showScreen('view-teacher');
184
- return;
 
 
 
 
 
 
 
 
185
  }
186
 
187
- let { data: estudiante } = await supabase
 
188
  .from('estudiantes')
189
  .select('*')
190
  .eq('id', app.user.id)
@@ -196,11 +148,20 @@ export const app = {
196
 
197
  await app.loadProgress();
198
  app.updateHUD();
199
-
200
  app.showScreen('view-intro-story');
201
- } else {
202
- app.loadAvatarScreen();
 
 
 
 
 
 
 
203
  }
 
 
 
204
  },
205
 
206
  loadProgress: async () => {
@@ -211,7 +172,8 @@ export const app = {
211
  .eq('acceso_desbloqueado', true);
212
 
213
  if (error) console.error("Error cargando progreso:", error);
214
- app.unlockedWorkshops = progresos ? progresos.map(p => parseInt(p.id_taller)) : [];
 
215
  },
216
 
217
  loadAvatarScreen: () => {
@@ -247,6 +209,7 @@ export const app = {
247
  return;
248
  }
249
 
 
250
  await supabase.from('progreso_acceso').insert({
251
  id_estudiante: app.user.id,
252
  id_taller: 1,
@@ -269,12 +232,19 @@ export const app = {
269
  const seed = app.profile.avatar_config || "Default";
270
  document.querySelector('.avatar-img').src = `https://api.dicebear.com/7.x/bottts/svg?seed=${seed}`;
271
 
 
 
 
 
272
  for (let i = 2; i <= 6; i++) {
273
- if(app.unlockedWorkshops.includes(i)) {
274
- const planetEl = document.getElementById(`planet-${i}`);
275
- if(planetEl) {
276
  planetEl.classList.remove('locked');
277
  planetEl.classList.add('unlocked');
 
 
 
278
  }
279
  }
280
  }
@@ -296,6 +266,9 @@ export const app = {
296
  },
297
 
298
  goBackFromGame: () => {
 
 
 
299
  if (app.role === 'teacher') {
300
  teacherUI.renderDashboard();
301
  app.showScreen('view-teacher');
@@ -310,13 +283,7 @@ export const app = {
310
  4: taller4Data, 5: taller5Data, 6: taller6Data
311
  };
312
 
313
- if (app.role === 'teacher') {
314
- app.showScreen('view-game');
315
- if(dataMap[id]) gameEngine.start(dataMap[id]);
316
- return;
317
- }
318
-
319
- if (app.unlockedWorkshops.includes(parseInt(id))) {
320
  app.showScreen('view-game');
321
  if(dataMap[id]) gameEngine.start(dataMap[id]);
322
  } else {
@@ -327,12 +294,10 @@ export const app = {
327
  finishWorkshop: async (resultados) => {
328
  if (app.role === 'teacher') {
329
  alert("Modo Profesor: Revisión completada. No se guardan datos.");
330
- teacherUI.renderDashboard();
331
- app.showScreen('view-teacher');
332
  return;
333
  }
334
 
335
- // --- PROCESO DE GUARDADO Y ACTUALIZACIÓN ---
336
  const rubricaData = {
337
  id_estudiante: app.user.id,
338
  id_taller: resultados.taller_id,
@@ -363,12 +328,9 @@ export const app = {
363
  await app.loadProgress();
364
  app.updateHUD();
365
 
366
- // --- ¡LÓGICA DE CELEBRACIÓN! ---
367
  if (currentLevel === 6) {
368
- // Si es el Taller 6, lanzamos la animación final
369
  ui.showGrandFinale(resultados);
370
  } else {
371
- // Para cualquier otro taller, mostramos el mensaje normal
372
  alert(`¡Misión Cumplida! Energía ganada: ${resultados.puntaje}\nNivel ${nextLevel} Desbloqueado.`);
373
  app.showScreen('view-map');
374
  }
 
1
  import { supabase } from './config.js';
2
  import { gameEngine } from './engine.js';
3
  import { teacherUI } from './teacherUI.js';
4
+ import { ui } from './ui.js';
5
 
6
  // Importación de los 6 Talleres
7
  import { taller1Data } from './talleres/taller1.js';
 
23
 
24
  if (session) {
25
  app.user = session.user;
26
+ app.loadUserProfile();
 
 
 
 
 
 
 
 
 
 
27
  } else {
28
  app.showScreen('view-login');
29
  }
30
 
31
  supabase.auth.onAuthStateChange(async (event, session) => {
32
  if (event === 'SIGNED_IN' && session) {
33
+ app.user = session.user;
34
+ app.loadUserProfile();
 
 
 
 
 
 
 
35
  }
36
  if (event === 'SIGNED_OUT') {
37
  app.stopHeartbeat();
38
  app.showScreen('view-login');
39
+ location.reload();
40
  }
41
  });
42
  },
43
 
44
  finishIntro: () => {
 
45
  app.showScreen('view-map');
46
  },
47
 
48
+ // Deprecated: La gestión de sesión única se elimina para simplificar
49
+ checkSessionAvailability: async (userId) => { return true; },
50
+ startHeartbeat: () => {},
51
+ sendPulse: async () => {},
52
+ stopHeartbeat: () => {},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  setupAutoLogout: () => {
55
  let timer;
 
89
  },
90
 
91
  logout: async () => {
 
 
 
 
92
  await supabase.auth.signOut();
 
93
  },
94
 
95
  loadUserProfile: async () => {
96
+ app.setupAutoLogout();
97
 
98
+ // 1. VERIFICAR SI ES DOCENTE
99
+ const { data: docente, error: docenteError } = await supabase
100
  .from('docentes')
101
  .select('*')
102
  .eq('id', app.user.id)
103
  .single();
104
 
105
+ // Si se encuentra el perfil de docente, configurar y terminar
106
  if (docente) {
107
  app.profile = docente;
108
  app.role = 'teacher';
 
113
  if(document.querySelector('.energy-display')) document.querySelector('.energy-display').style.display = 'none';
114
  if(document.getElementById('btn-teacher-panel')) document.getElementById('btn-teacher-panel').classList.remove('hidden');
115
 
116
+ // Desbloquear todos los planetas para el docente
117
+ for (let i = 1; i <= 6; i++) {
118
+ const planet = document.getElementById(`planet-${i}`);
119
+ if (planet) {
120
+ planet.classList.remove('locked');
121
+ planet.classList.add('unlocked');
 
 
 
122
  }
123
+ }
124
 
125
+ teacherUI.renderDashboard();
126
+ app.showScreen('view-teacher');
127
+ return; // ¡IMPORTANTE! Salir de la función aquí
128
+ }
129
+
130
+ // Si hubo un error al buscar al docente (y no fue que simplemente no lo encontró)
131
+ if (docenteError && docenteError.code !== 'PGRST116') {
132
+ console.error("Error al buscar perfil de docente:", docenteError);
133
+ alert("Error al verificar el perfil. Inténtalo de nuevo.");
134
+ app.logout();
135
+ return;
136
  }
137
 
138
+ // 2. SI NO ES DOCENTE, VERIFICAR SI ES ESTUDIANTE
139
+ const { data: estudiante, error: estudianteError } = await supabase
140
  .from('estudiantes')
141
  .select('*')
142
  .eq('id', app.user.id)
 
148
 
149
  await app.loadProgress();
150
  app.updateHUD();
 
151
  app.showScreen('view-intro-story');
152
+ return;
153
+ }
154
+
155
+ // Si hubo un error al buscar al estudiante
156
+ if (estudianteError && estudianteError.code !== 'PGRST116') {
157
+ console.error("Error al buscar perfil de estudiante:", estudianteError);
158
+ alert("Error al verificar el perfil. Inténtalo de nuevo.");
159
+ app.logout();
160
+ return;
161
  }
162
+
163
+ // 3. SI NO ES NINGUNO, ES UN NUEVO ESTUDIANTE
164
+ app.loadAvatarScreen();
165
  },
166
 
167
  loadProgress: async () => {
 
172
  .eq('acceso_desbloqueado', true);
173
 
174
  if (error) console.error("Error cargando progreso:", error);
175
+ app.unlockedWorkshops = progresos ? progresos.map(p => parseInt(p.id_taller)) : [1]; // Desbloquear taller 1 por defecto
176
+ if (!app.unlockedWorkshops.includes(1)) app.unlockedWorkshops.push(1);
177
  },
178
 
179
  loadAvatarScreen: () => {
 
209
  return;
210
  }
211
 
212
+ // Asegurarse de que el primer taller está desbloqueado
213
  await supabase.from('progreso_acceso').insert({
214
  id_estudiante: app.user.id,
215
  id_taller: 1,
 
232
  const seed = app.profile.avatar_config || "Default";
233
  document.querySelector('.avatar-img').src = `https://api.dicebear.com/7.x/bottts/svg?seed=${seed}`;
234
 
235
+ // Asegurar que el planeta 1 esté siempre desbloqueado visualmente
236
+ document.getElementById('planet-1').classList.remove('locked');
237
+ document.getElementById('planet-1').classList.add('unlocked');
238
+
239
  for (let i = 2; i <= 6; i++) {
240
+ const planetEl = document.getElementById(`planet-${i}`);
241
+ if(planetEl) {
242
+ if(app.unlockedWorkshops.includes(i)) {
243
  planetEl.classList.remove('locked');
244
  planetEl.classList.add('unlocked');
245
+ } else {
246
+ planetEl.classList.add('locked');
247
+ planetEl.classList.remove('unlocked');
248
  }
249
  }
250
  }
 
266
  },
267
 
268
  goBackFromGame: () => {
269
+ document.getElementById('timer-display').innerText = "";
270
+ const timerBar = document.getElementById('timer-bar');
271
+ if(timerBar) timerBar.style.width = '100%';
272
  if (app.role === 'teacher') {
273
  teacherUI.renderDashboard();
274
  app.showScreen('view-teacher');
 
283
  4: taller4Data, 5: taller5Data, 6: taller6Data
284
  };
285
 
286
+ if (app.role === 'teacher' || app.unlockedWorkshops.includes(parseInt(id))) {
 
 
 
 
 
 
287
  app.showScreen('view-game');
288
  if(dataMap[id]) gameEngine.start(dataMap[id]);
289
  } else {
 
294
  finishWorkshop: async (resultados) => {
295
  if (app.role === 'teacher') {
296
  alert("Modo Profesor: Revisión completada. No se guardan datos.");
297
+ app.goBackFromGame();
 
298
  return;
299
  }
300
 
 
301
  const rubricaData = {
302
  id_estudiante: app.user.id,
303
  id_taller: resultados.taller_id,
 
328
  await app.loadProgress();
329
  app.updateHUD();
330
 
 
331
  if (currentLevel === 6) {
 
332
  ui.showGrandFinale(resultados);
333
  } else {
 
334
  alert(`¡Misión Cumplida! Energía ganada: ${resultados.puntaje}\nNivel ${nextLevel} Desbloqueado.`);
335
  app.showScreen('view-map');
336
  }
js/config.js CHANGED
@@ -1,6 +1,6 @@
1
  // --- CONFIGURACIÓN DE SUPABASE ---
2
  const SUPABASE_URL = 'https://uejhacdzgbgscyyiifoi.supabase.co';
3
- const SUPABASE_KEY = 'sb_publishable_AElzwJPwqZMpK3lh8Hlbow_Y9YBcLUa';
4
 
5
  // Inicializar y exportar el cliente
6
  export const supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
 
1
  // --- CONFIGURACIÓN DE SUPABASE ---
2
  const SUPABASE_URL = 'https://uejhacdzgbgscyyiifoi.supabase.co';
3
+ const SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVlamhhY2R6Z2Jnc2N5eWlpZm9pIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjUxMTQwMDcsImV4cCI6MjA4MDY5MDAwN30.WmVf_RXneAT-rDG-pRvznbVZzdU2aCW1n-7ZGL_0wmY';
4
 
5
  // Inicializar y exportar el cliente
6
  export const supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
js/engine.js CHANGED
@@ -12,6 +12,7 @@ export const gameEngine = {
12
  timerInterval: null,
13
 
14
  start: (tallerData) => {
 
15
  gameEngine.data = tallerData;
16
  gameEngine.score = 0;
17
  gameEngine.errors = 0;
@@ -161,6 +162,7 @@ export const gameEngine = {
161
  },
162
 
163
  finish: () => {
 
164
  const duration = Math.floor((Date.now() - gameEngine.startTime) / 1000);
165
  const totalActivities = gameEngine.data.niveles.reduce((acc, nivel) => acc + nivel.actividades.length, 0);
166
  const aciertos = totalActivities - gameEngine.errors;
 
12
  timerInterval: null,
13
 
14
  start: (tallerData) => {
15
+ clearInterval(gameEngine.timerInterval);
16
  gameEngine.data = tallerData;
17
  gameEngine.score = 0;
18
  gameEngine.errors = 0;
 
162
  },
163
 
164
  finish: () => {
165
+ clearInterval(gameEngine.timerInterval);
166
  const duration = Math.floor((Date.now() - gameEngine.startTime) / 1000);
167
  const totalActivities = gameEngine.data.niveles.reduce((acc, nivel) => acc + nivel.actividades.length, 0);
168
  const aciertos = totalActivities - gameEngine.errors;
js/talleres/taller4.js CHANGED
@@ -1,7 +1,7 @@
1
  export const taller4Data = {
2
  id: 4,
3
  titulo: "Misión 4: La Gran Batalla del Cristal", // [cite: 29]
4
- descripcion: "Supera la prueba final del Consejo de los Números Eternos.", // [cite: 29]
5
 
6
  // --- INTRODUCCIÓN ---
7
  intro_contenido: {
@@ -80,13 +80,13 @@ export const taller4Data = {
80
  },
81
 
82
  // ---------------------------------------------------------
83
- // MISIÓN 3: DESAFÍO GALÁCTICO (FINAL)
84
  // Objetivo: Pensamiento crítico y operaciones combinadas.
85
  // ---------------------------------------------------------
86
  {
87
  id_nivel: "N3",
88
  nombre_planeta: "Núcleo del Saber",
89
- descripcion: "La prueba final. Combina tu lógica y cálculo.", //
90
  es_bonus: true, // Gran final
91
  actividades: [
92
  {
 
1
  export const taller4Data = {
2
  id: 4,
3
  titulo: "Misión 4: La Gran Batalla del Cristal", // [cite: 29]
4
+ descripcion: "Supera la prueba del Consejo de los Números Eternos.", // [cite: 29]
5
 
6
  // --- INTRODUCCIÓN ---
7
  intro_contenido: {
 
80
  },
81
 
82
  // ---------------------------------------------------------
83
+ // MISIÓN 3: DESAFÍO GALÁCTICO
84
  // Objetivo: Pensamiento crítico y operaciones combinadas.
85
  // ---------------------------------------------------------
86
  {
87
  id_nivel: "N3",
88
  nombre_planeta: "Núcleo del Saber",
89
+ descripcion: "Combina tu lógica y cálculo.", //
90
  es_bonus: true, // Gran final
91
  actividades: [
92
  {
js/teacherUI.js CHANGED
@@ -171,7 +171,7 @@ export const teacherUI = {
171
  .from('rubricas_evaluacion')
172
  .select(`
173
  id, fecha_evaluacion, id_estudiante, id_taller, nota_final, criterio_coop, criterio_math, feedback,
174
- estudiantes!fk_estudiante ( nombre_completo )
175
  `)
176
  .order('fecha_evaluacion', { ascending: true });
177
 
 
171
  .from('rubricas_evaluacion')
172
  .select(`
173
  id, fecha_evaluacion, id_estudiante, id_taller, nota_final, criterio_coop, criterio_math, feedback,
174
+ estudiantes ( nombre_completo )
175
  `)
176
  .order('fecha_evaluacion', { ascending: true });
177