Fix null reference errors in showFinalStats
- Added null checks for gameOverTitle and gameOverMessage elements - Added null checks in displayRegularGameStats for all DOM elements - Added null checks in displayScenarioStats for final stats elements - Prevents 'Cannot set properties of null' errors in Quick Play mode - Game ending now handles missing DOM elements gracefully
This commit is contained in:
parent
6701a8e7bf
commit
931e6aac97
109
src/core/game.js
109
src/core/game.js
|
|
@ -5893,34 +5893,39 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
|||
const gameOverTitle = document.querySelector('#game-over-screen h2');
|
||||
const gameOverMessage = document.querySelector('#game-over-screen p');
|
||||
|
||||
// Use game mode manager for completion message if available
|
||||
if (window.gameModeManager && window.gameModeManager.isScenarioMode()) {
|
||||
if (reason === 'scenario-complete') {
|
||||
gameOverTitle.textContent = '🎭 Scenario Complete!';
|
||||
gameOverMessage.textContent = window.gameModeManager.getCompletionMessage();
|
||||
} else if (reason === 'scenario-quit') {
|
||||
gameOverTitle.textContent = '😞 Scenario Abandoned';
|
||||
gameOverMessage.textContent = 'You gave up on the scenario. Your progress was not saved.';
|
||||
// Only update elements if they exist (might not exist in Quick Play mode)
|
||||
if (gameOverTitle && gameOverMessage) {
|
||||
// Use game mode manager for completion message if available
|
||||
if (window.gameModeManager && window.gameModeManager.isScenarioMode()) {
|
||||
if (reason === 'scenario-complete') {
|
||||
gameOverTitle.textContent = '🎭 Scenario Complete!';
|
||||
gameOverMessage.textContent = window.gameModeManager.getCompletionMessage();
|
||||
} else if (reason === 'scenario-quit') {
|
||||
gameOverTitle.textContent = '😞 Scenario Abandoned';
|
||||
gameOverMessage.textContent = 'You gave up on the scenario. Your progress was not saved.';
|
||||
} else {
|
||||
gameOverTitle.textContent = '🎉 Mode Complete!';
|
||||
gameOverMessage.textContent = window.gameModeManager.getCompletionMessage();
|
||||
}
|
||||
} else {
|
||||
gameOverTitle.textContent = '🎉 Mode Complete!';
|
||||
gameOverMessage.textContent = window.gameModeManager.getCompletionMessage();
|
||||
switch (reason) {
|
||||
case 'time':
|
||||
gameOverTitle.textContent = '⏰ Time\'s Up!';
|
||||
gameOverMessage.textContent = 'You ran out of time! See how many tasks you completed.';
|
||||
break;
|
||||
case 'target-reached':
|
||||
gameOverTitle.textContent = '⭐ XP Target Reached!';
|
||||
gameOverMessage.textContent = `Congratulations! You reached the target of ${this.gameState.xpTarget} XP!`;
|
||||
break;
|
||||
case 'complete-all':
|
||||
default:
|
||||
gameOverTitle.textContent = '🎉 All Tasks Complete!';
|
||||
gameOverMessage.textContent = 'Congratulations! You\'ve completed all available tasks!';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (reason) {
|
||||
case 'time':
|
||||
gameOverTitle.textContent = '⏰ Time\'s Up!';
|
||||
gameOverMessage.textContent = 'You ran out of time! See how many tasks you completed.';
|
||||
break;
|
||||
case 'target-reached':
|
||||
gameOverTitle.textContent = '⭐ XP Target Reached!';
|
||||
gameOverMessage.textContent = `Congratulations! You reached the target of ${this.gameState.xpTarget} XP!`;
|
||||
break;
|
||||
case 'complete-all':
|
||||
default:
|
||||
gameOverTitle.textContent = '🎉 All Tasks Complete!';
|
||||
gameOverMessage.textContent = 'Congratulations! You\'ve completed all available tasks!';
|
||||
break;
|
||||
}
|
||||
console.log('Game over screen elements not found - likely in Quick Play mode');
|
||||
}
|
||||
|
||||
// Handle scenario vs regular game stats display
|
||||
|
|
@ -5945,18 +5950,27 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
|||
(scenarioXp.photoXp || 0) +
|
||||
(scenarioXp.stepCompletion || 0);
|
||||
|
||||
// Display scenario mode
|
||||
document.getElementById('final-game-mode').textContent = scenarioName;
|
||||
// Display scenario mode with null check
|
||||
const finalGameModeElement = document.getElementById('final-game-mode');
|
||||
if (finalGameModeElement) {
|
||||
finalGameModeElement.textContent = scenarioName;
|
||||
}
|
||||
|
||||
// Display scenario XP (separate from main game XP)
|
||||
document.getElementById('final-xp').textContent = reason === 'scenario-quit' ? 0 : totalScenarioXp;
|
||||
// Display scenario XP (separate from main game XP) with null check
|
||||
const finalXpElement = document.getElementById('final-xp');
|
||||
if (finalXpElement) {
|
||||
finalXpElement.textContent = reason === 'scenario-quit' ? 0 : totalScenarioXp;
|
||||
}
|
||||
|
||||
// Format time properly
|
||||
const totalSeconds = Math.floor(this.gameState.timer);
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
const formattedTime = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
||||
document.getElementById('final-time').textContent = formattedTime;
|
||||
// Format time properly with null check
|
||||
const finalTimeElement = document.getElementById('final-time');
|
||||
if (finalTimeElement) {
|
||||
const totalSeconds = Math.floor(this.gameState.timer);
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
const formattedTime = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
||||
finalTimeElement.textContent = formattedTime;
|
||||
}
|
||||
|
||||
// Hide irrelevant stats for scenarios
|
||||
const statsToHide = ['final-completed', 'final-skipped', 'final-consequences', 'final-best-streak', 'final-streak-bonuses'];
|
||||
|
|
@ -5981,14 +5995,27 @@ ${usagePercent > 85 ? '⚠️ Storage getting full - consider deleting some imag
|
|||
}
|
||||
});
|
||||
|
||||
document.getElementById('final-xp').textContent = this.gameState.xp || 0;
|
||||
// Update XP with null check
|
||||
const finalXpElement = document.getElementById('final-xp');
|
||||
if (finalXpElement) {
|
||||
finalXpElement.textContent = this.gameState.xp || 0;
|
||||
}
|
||||
|
||||
const formattedTime = this.formatTime(this.gameState.timer);
|
||||
document.getElementById('final-time').textContent = formattedTime;
|
||||
// Update time with null check
|
||||
const finalTimeElement = document.getElementById('final-time');
|
||||
if (finalTimeElement) {
|
||||
const formattedTime = this.formatTime(this.gameState.timer);
|
||||
finalTimeElement.textContent = formattedTime;
|
||||
}
|
||||
|
||||
document.getElementById('final-completed').textContent = this.gameState.completedCount;
|
||||
document.getElementById('final-skipped').textContent = this.gameState.skippedCount;
|
||||
document.getElementById('final-consequences').textContent = this.gameState.consequenceCount;
|
||||
// Update stats with null checks
|
||||
const finalCompletedElement = document.getElementById('final-completed');
|
||||
const finalSkippedElement = document.getElementById('final-skipped');
|
||||
const finalConsequencesElement = document.getElementById('final-consequences');
|
||||
|
||||
if (finalCompletedElement) finalCompletedElement.textContent = this.gameState.completedCount;
|
||||
if (finalSkippedElement) finalSkippedElement.textContent = this.gameState.skippedCount;
|
||||
if (finalConsequencesElement) finalConsequencesElement.textContent = this.gameState.consequenceCount;
|
||||
|
||||
// Update streak bonus stats
|
||||
const bestStreakElement = document.getElementById('final-best-streak');
|
||||
|
|
|
|||
Loading…
Reference in New Issue