milwright commited on
Commit
a1fb0b6
·
1 Parent(s): 39f4470

improve progress tracking with user-visible helpers

Browse files
Files changed (1) hide show
  1. src/clozeGameEngine.js +55 -14
src/clozeGameEngine.js CHANGED
@@ -31,6 +31,43 @@ class ClozeGame {
31
  console.log('🎮 GAME ENGINE INITIALIZED - Starting at Level 1, Passages passed: 0');
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  async initialize() {
35
  try {
36
  await bookDataService.loadDataset();
@@ -58,15 +95,8 @@ class ClozeGame {
58
  this.currentPassageIndex = 0;
59
 
60
  // Calculate blanks per passage based on level
61
- // Levels 1-5: 1 blank, Levels 6-10: 2 blanks, Level 11+: 3 blanks
62
- let blanksPerPassage;
63
- if (this.currentLevel <= 5) {
64
- blanksPerPassage = 1;
65
- } else if (this.currentLevel <= 10) {
66
- blanksPerPassage = 2;
67
- } else {
68
- blanksPerPassage = 3;
69
- }
70
 
71
  // Process both passages in a single API call
72
  try {
@@ -98,6 +128,7 @@ class ClozeGame {
98
  await this.generateContextualization();
99
  }
100
 
 
101
  return {
102
  title: this.currentBook.title,
103
  author: this.currentBook.author,
@@ -106,7 +137,8 @@ class ClozeGame {
106
  contextualization: this.contextualization,
107
  hints: this.hints,
108
  passageNumber: 1,
109
- totalPassages: 2
 
110
  };
111
  } catch (error) {
112
  console.error('Error starting new round:', error);
@@ -803,7 +835,8 @@ class ClozeGame {
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,
@@ -815,7 +848,13 @@ class ClozeGame {
815
  requiredCorrect: requiredCorrect,
816
  currentLevel: this.currentLevel,
817
  passagesPassedAtCurrentLevel: this.passagesPassedAtCurrentLevel,
818
- justAdvancedLevel: justAdvancedLevel
 
 
 
 
 
 
819
  };
820
 
821
  // Store results for potential answer revelation
@@ -874,6 +913,7 @@ class ClozeGame {
874
  await this.generateContextualization();
875
  }
876
 
 
877
  return {
878
  title: this.currentBook.title,
879
  author: this.currentBook.author,
@@ -882,7 +922,8 @@ class ClozeGame {
882
  contextualization: this.contextualization,
883
  hints: this.hints,
884
  passageNumber: 2,
885
- totalPassages: 2
 
886
  };
887
  } else {
888
  // If we're already on the second passage, move to next round
@@ -1002,4 +1043,4 @@ class ClozeGame {
1002
  }
1003
  }
1004
 
1005
- export default ClozeGame;
 
31
  console.log('🎮 GAME ENGINE INITIALIZED - Starting at Level 1, Passages passed: 0');
32
  }
33
 
34
+ // --- User-visible framing helpers ---
35
+ getBlanksPerPassage(level = this.currentLevel) {
36
+ if (level <= 5) return 1;
37
+ if (level <= 10) return 2;
38
+ return 3;
39
+ }
40
+
41
+ getProgressSnapshot() {
42
+ return {
43
+ round: this.currentRound,
44
+ level: this.currentLevel,
45
+ passageNumber: this.currentPassageIndex + 1,
46
+ totalPassages: 2,
47
+ blanksPerPassage: this.getBlanksPerPassage(),
48
+ passagesPassedAtCurrentLevel: this.passagesPassedAtCurrentLevel
49
+ };
50
+ }
51
+
52
+ formatProgressText(snapshot = this.getProgressSnapshot()) {
53
+ const blanksLabel = `${snapshot.blanksPerPassage} blank${snapshot.blanksPerPassage > 1 ? 's' : ''}`;
54
+ return `Level ${snapshot.level} • Passage ${snapshot.passageNumber}/${snapshot.totalPassages} • ${blanksLabel}`;
55
+ }
56
+
57
+ formatAdvancementText({ passed, correctCount, requiredCorrect, justAdvancedLevel }) {
58
+ if (passed) {
59
+ if (justAdvancedLevel) {
60
+ return `✓ Passed • Level up! Welcome to Level ${this.currentLevel}`;
61
+ }
62
+ const needed = Math.max(0, 2 - this.passagesPassedAtCurrentLevel);
63
+ if (needed === 0) {
64
+ return `✓ Passed`;
65
+ }
66
+ return `✓ Passed • ${needed} more passage${needed > 1 ? 's' : ''} to reach Level ${this.currentLevel + 1}`;
67
+ }
68
+ return `Try again • Need ${requiredCorrect}/${this.blanks.length} correct (you got ${correctCount})`;
69
+ }
70
+
71
  async initialize() {
72
  try {
73
  await bookDataService.loadDataset();
 
95
  this.currentPassageIndex = 0;
96
 
97
  // Calculate blanks per passage based on level
98
+ // Levels 1-5: 1 blank, 6-10: 2 blanks, 11+: 3 blanks
99
+ const blanksPerPassage = this.getBlanksPerPassage();
 
 
 
 
 
 
 
100
 
101
  // Process both passages in a single API call
102
  try {
 
128
  await this.generateContextualization();
129
  }
130
 
131
+ const snapshot = this.getProgressSnapshot();
132
  return {
133
  title: this.currentBook.title,
134
  author: this.currentBook.author,
 
137
  contextualization: this.contextualization,
138
  hints: this.hints,
139
  passageNumber: 1,
140
+ totalPassages: 2,
141
+ progressText: this.formatProgressText(snapshot)
142
  };
143
  } catch (error) {
144
  console.error('Error starting new round:', error);
 
835
 
836
  // Track if we just advanced levels
837
  const justAdvancedLevel = passed && this.passagesPassedAtCurrentLevel === 0 && this.currentLevel > 1;
838
+
839
+ const snapshot = this.getProgressSnapshot();
840
  const resultsData = {
841
  correct: correctCount,
842
  total: this.blanks.length,
 
848
  requiredCorrect: requiredCorrect,
849
  currentLevel: this.currentLevel,
850
  passagesPassedAtCurrentLevel: this.passagesPassedAtCurrentLevel,
851
+ justAdvancedLevel: justAdvancedLevel,
852
+ round: snapshot.round,
853
+ passageNumber: snapshot.passageNumber,
854
+ totalPassages: snapshot.totalPassages,
855
+ progressText: this.formatProgressText(snapshot),
856
+ feedbackText: this.formatAdvancementText({ passed, correctCount, requiredCorrect, justAdvancedLevel }),
857
+ nextActionText: snapshot.passageNumber === snapshot.totalPassages ? 'Next round' : 'Next passage'
858
  };
859
 
860
  // Store results for potential answer revelation
 
913
  await this.generateContextualization();
914
  }
915
 
916
+ const snapshot = this.getProgressSnapshot();
917
  return {
918
  title: this.currentBook.title,
919
  author: this.currentBook.author,
 
922
  contextualization: this.contextualization,
923
  hints: this.hints,
924
  passageNumber: 2,
925
+ totalPassages: 2,
926
+ progressText: this.formatProgressText(snapshot)
927
  };
928
  } else {
929
  // If we're already on the second passage, move to next round
 
1043
  }
1044
  }
1045
 
1046
+ export default ClozeGame;