milwright commited on
Commit
a4e8e99
ยท
1 Parent(s): 37a7438

fix level progression tracking and ui display

Browse files

- add comprehensive debug logging for level advancement
- fix ui logic for detecting level advancement
- track justAdvancedLevel flag to properly show messages
- improve progression messages clarity

Files changed (2) hide show
  1. src/app.js +6 -5
  2. src/clozeGameEngine.js +30 -27
src/app.js CHANGED
@@ -159,12 +159,13 @@ class App {
159
  let message = `Score: ${results.correct}/${results.total}`;
160
 
161
  if (results.passed) {
162
- // Check if this completes the requirements for level advancement
163
- const roundsCompleted = this.game.roundsPassedAtCurrentLevel + 1; // +1 for this round
164
- if (roundsCompleted >= 2) {
165
- message += ` โœ“ Level ${this.game.currentLevel + 1} unlocked!`;
 
166
  } else {
167
- message += ` โœ“ Passed (1 more round needed for next level)`;
168
  }
169
  this.elements.result.className = 'mt-4 text-center font-semibold text-green-600';
170
  } else {
 
159
  let message = `Score: ${results.correct}/${results.total}`;
160
 
161
  if (results.passed) {
162
+ // Check if level was just advanced
163
+ if (results.justAdvancedLevel) {
164
+ message += ` โœ“ Level ${results.currentLevel} unlocked!`;
165
+ } else if (results.passagesPassedAtCurrentLevel === 1) {
166
+ message += ` โœ“ Passed (1 more passage needed for next level)`;
167
  } else {
168
+ message += ` โœ“ Passed`;
169
  }
170
  this.elements.result.className = 'mt-4 text-center font-semibold text-green-600';
171
  } else {
src/clozeGameEngine.js CHANGED
@@ -27,7 +27,8 @@ class ClozeGame {
27
  this.currentPassageIndex = 0; // 0 for first passage, 1 for second
28
 
29
  // Level progression tracking
30
- this.roundsPassedAtCurrentLevel = 0; // Track successful rounds at current level
 
31
  }
32
 
33
  async initialize() {
@@ -42,6 +43,7 @@ class ClozeGame {
42
 
43
  async startNewRound() {
44
  try {
 
45
  // Get two books for this round based on current level criteria
46
  const book1 = await bookDataService.getBookByLevelCriteria(this.currentLevel);
47
  const book2 = await bookDataService.getBookByLevelCriteria(this.currentLevel);
@@ -780,7 +782,28 @@ class ClozeGame {
780
  const totalBlanks = this.blanks.length;
781
  const requiredCorrect = this.calculateRequiredCorrect(totalBlanks);
782
  const passed = correctCount >= requiredCorrect;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
783
 
 
 
 
784
  const resultsData = {
785
  correct: correctCount,
786
  total: this.blanks.length,
@@ -790,7 +813,9 @@ class ClozeGame {
790
  canAdvanceLevel: passed,
791
  shouldRevealAnswers: !passed,
792
  requiredCorrect: requiredCorrect,
793
- currentLevel: this.currentLevel
 
 
794
  };
795
 
796
  // Store results for potential answer revelation
@@ -828,6 +853,7 @@ class ClozeGame {
828
  // Move to the second passage in the current round
829
  if (this.currentPassageIndex === 0 && this.passages && this.passages.length > 1) {
830
  this.currentPassageIndex = 1;
 
831
  this.currentBook = this.currentBooks[1];
832
  this.originalText = this.passages[1];
833
 
@@ -869,34 +895,11 @@ class ClozeGame {
869
  }
870
 
871
  nextRound() {
872
- // Check if user passed the previous round based on overall round performance
873
- let roundPassed = false;
874
- if (this.roundResults.length === 2) {
875
- // Both passages completed - check if user passed at least one passage
876
- roundPassed = this.roundResults.some(result => result && result.passed);
877
- } else if (this.lastResults) {
878
- // Fallback to single passage result
879
- roundPassed = this.lastResults.passed;
880
- }
881
-
882
  // Always increment round counter
883
  this.currentRound++;
 
884
 
885
- // Track successful rounds and advance level after 2 successful rounds
886
- if (roundPassed) {
887
- this.roundsPassedAtCurrentLevel++;
888
- console.log(`Round passed at level ${this.currentLevel}`);
889
-
890
- // Advance level after 2 successful rounds
891
- if (this.roundsPassedAtCurrentLevel >= 2) {
892
- this.currentLevel++;
893
- this.roundsPassedAtCurrentLevel = 0; // Reset counter for new level
894
- console.log(`Advanced to level ${this.currentLevel}`);
895
- }
896
- } else {
897
- // Failed round - do not reset the counter, user must accumulate 2 passes
898
- console.log(`Round not passed. Need ${2 - this.roundsPassedAtCurrentLevel} more round(s) to advance`);
899
- }
900
 
901
  // Clear chat conversations for new round
902
  this.chatService.clearConversations();
 
27
  this.currentPassageIndex = 0; // 0 for first passage, 1 for second
28
 
29
  // Level progression tracking
30
+ this.passagesPassedAtCurrentLevel = 0; // Track successful passages at current level (not rounds)
31
+ console.log('๐ŸŽฎ GAME ENGINE INITIALIZED - Starting at Level 1, Passages passed: 0');
32
  }
33
 
34
  async initialize() {
 
43
 
44
  async startNewRound() {
45
  try {
46
+ console.log(`๐ŸŽฒ STARTING NEW ROUND - Round: ${this.currentRound}, Level: ${this.currentLevel}, Progress: ${this.passagesPassedAtCurrentLevel}/2`);
47
  // Get two books for this round based on current level criteria
48
  const book1 = await bookDataService.getBookByLevelCriteria(this.currentLevel);
49
  const book2 = await bookDataService.getBookByLevelCriteria(this.currentLevel);
 
782
  const totalBlanks = this.blanks.length;
783
  const requiredCorrect = this.calculateRequiredCorrect(totalBlanks);
784
  const passed = correctCount >= requiredCorrect;
785
+
786
+ // Track successful passages for level advancement
787
+ if (passed) {
788
+ this.passagesPassedAtCurrentLevel++;
789
+ console.log(`โœ… PASSAGE PASSED - Level: ${this.currentLevel}, Passages passed at current level: ${this.passagesPassedAtCurrentLevel}/2`);
790
+
791
+ // Advance level after 2 successful passages (not rounds)
792
+ if (this.passagesPassedAtCurrentLevel >= 2) {
793
+ const previousLevel = this.currentLevel;
794
+ this.currentLevel++;
795
+ this.passagesPassedAtCurrentLevel = 0; // Reset counter for new level
796
+ console.log(`๐ŸŽ‰ LEVEL ADVANCEMENT: ${previousLevel} โ†’ ${this.currentLevel} (counter reset to 0)`);
797
+ } else {
798
+ console.log(`๐Ÿ“Š Progress: Need ${2 - this.passagesPassedAtCurrentLevel} more passage(s) to advance from level ${this.currentLevel}`);
799
+ }
800
+ } else {
801
+ console.log(`โŒ PASSAGE FAILED - Level: ${this.currentLevel}, Passages passed remains: ${this.passagesPassedAtCurrentLevel}/2`);
802
+ }
803
 
804
+ // Track if we just advanced levels
805
+ const justAdvancedLevel = passed && this.passagesPassedAtCurrentLevel === 0 && this.currentLevel > 1;
806
+
807
  const resultsData = {
808
  correct: correctCount,
809
  total: this.blanks.length,
 
813
  canAdvanceLevel: passed,
814
  shouldRevealAnswers: !passed,
815
  requiredCorrect: requiredCorrect,
816
+ currentLevel: this.currentLevel,
817
+ passagesPassedAtCurrentLevel: this.passagesPassedAtCurrentLevel,
818
+ justAdvancedLevel: justAdvancedLevel
819
  };
820
 
821
  // Store results for potential answer revelation
 
853
  // Move to the second passage in the current round
854
  if (this.currentPassageIndex === 0 && this.passages && this.passages.length > 1) {
855
  this.currentPassageIndex = 1;
856
+ console.log(`๐Ÿ“– MOVING TO PASSAGE 2/2 in Round ${this.currentRound} - Level: ${this.currentLevel}, Progress: ${this.passagesPassedAtCurrentLevel}/2`);
857
  this.currentBook = this.currentBooks[1];
858
  this.originalText = this.passages[1];
859
 
 
895
  }
896
 
897
  nextRound() {
 
 
 
 
 
 
 
 
 
 
898
  // Always increment round counter
899
  this.currentRound++;
900
+ console.log(`๐Ÿ”„ NEW ROUND ${this.currentRound} - Level: ${this.currentLevel}, Passages passed at current level: ${this.passagesPassedAtCurrentLevel}/2`);
901
 
902
+ // Level advancement is now handled in submitAnswers() based on individual passages
 
 
 
 
 
 
 
 
 
 
 
 
 
 
903
 
904
  // Clear chat conversations for new round
905
  this.chatService.clearConversations();