fix: Photo session completion causing game to end prematurely
CRITICAL BUG FIXES: 1. DOM ELEMENT SAFETY CHECKS: Added null checks for scenario UI elements in displayScenarioStep() Prevents 'Cannot set properties of null' errors Graceful handling when scenario interface is cleaned up Automatic task completion for ending steps when UI is gone 2. DUPLICATE COMPLETION PREVENTION: Fixed webcam manager calling resumeFromCamera() for scenario sessions Added detection for scenario-based photo sessions vs regular sessions Prevents double completion that was ending games prematurely Scenario sessions now handled only by scenario system 3. IMPROVED SESSION DETECTION: Check if photo session has taskData.task.scenarioState Scenario sessions skip resumeFromCamera() call Non-scenario sessions still use resumeFromCamera() as before Clear logging for debugging session types 4. SEQUENCE FIX: Before: Photo complete handlePhotoSessionCompletion() + resumeFromCamera() game ends After: Photo complete handlePhotoSessionCompletion() scenario continues RESULT: - Photo sessions in scenarios now continue the story properly - No more premature game endings after photo completion - Eliminates JavaScript errors from missing DOM elements - Clean separation between scenario and non-scenario photo handling Photo sessions should now seamlessly integrate with scenario progression!
This commit is contained in:
parent
a34482ae38
commit
3820b23c26
|
|
@ -472,10 +472,26 @@ class InteractiveTaskManager {
|
|||
return;
|
||||
}
|
||||
|
||||
// Check if scenario interface elements exist (safety check)
|
||||
const storyEl = document.getElementById('scenario-story');
|
||||
const choicesEl = document.getElementById('scenario-choices');
|
||||
const stepEl = document.getElementById('scenario-step');
|
||||
|
||||
if (!storyEl || !choicesEl || !stepEl) {
|
||||
console.warn('Scenario interface not available - cannot display step:', stepId);
|
||||
console.log('Available elements:', { storyEl: !!storyEl, choicesEl: !!choicesEl, stepEl: !!stepEl });
|
||||
|
||||
// If this is an ending step and interface is gone, complete the task instead
|
||||
if (step.type === 'ending') {
|
||||
console.log('🎭 Ending step reached with no UI - completing task');
|
||||
if (this.game && this.game.gameState && this.game.gameState.isRunning) {
|
||||
this.cleanupInteractiveTask();
|
||||
this.game.completeTask();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Update step counter
|
||||
stepEl.textContent = task.scenarioState.stepNumber;
|
||||
|
||||
|
|
|
|||
|
|
@ -945,12 +945,22 @@ class WebcamManager {
|
|||
// Clear current session
|
||||
if (this.currentPhotoSession) {
|
||||
console.log(`📊 Session ended: ${this.currentPhotoSession.photos.length} photos taken`);
|
||||
|
||||
// Check if this was a scenario-based photo session
|
||||
const isScenarioSession = this.currentPhotoSession.taskData &&
|
||||
this.currentPhotoSession.taskData.task &&
|
||||
this.currentPhotoSession.taskData.task.scenarioState;
|
||||
|
||||
this.currentPhotoSession = null;
|
||||
}
|
||||
|
||||
// Return to task
|
||||
if (this.game && this.game.interactiveTaskManager) {
|
||||
this.game.interactiveTaskManager.resumeFromCamera();
|
||||
|
||||
// Only call resumeFromCamera for non-scenario sessions
|
||||
// Scenario sessions are handled by handlePhotoSessionCompletion
|
||||
if (!isScenarioSession && this.game && this.game.interactiveTaskManager) {
|
||||
console.log('📱 Non-scenario session - resuming to task interface');
|
||||
this.game.interactiveTaskManager.resumeFromCamera();
|
||||
} else if (isScenarioSession) {
|
||||
console.log('🎭 Scenario session - completion handled by scenario system');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue