refactor: move test finish/fail logic, add all words generated check

This commit is contained in:
Miodec 2024-06-11 12:06:47 +02:00
parent 148fa1e519
commit faf7efa043

View file

@ -234,11 +234,6 @@ function handleSpace(): void {
void Sound.playClick();
}
Replay.addReplayEvent("submitCorrectWord");
if (TestWords.words.currentIndex === TestWords.words.length) {
//submitted last word (checking this in case the test doesnt stop automatically on correct last keypress)
void TestLogic.finish();
return;
}
} else {
if (!nospace) {
if (Config.playSoundOnError === "off" || Config.blindMode) {
@ -284,17 +279,24 @@ function handleSpace(): void {
void Caret.updatePosition();
TestInput.incrementKeypressCount();
TestInput.pushKeypressWord(TestWords.words.currentIndex);
if (Config.difficulty === "expert" || Config.difficulty === "master") {
TestLogic.fail("difficulty");
return;
} else if (TestWords.words.currentIndex === TestWords.words.length) {
//submitted last word that is incorrect
void TestLogic.finish();
return;
}
Replay.addReplayEvent("submitErrorWord");
}
if (
TestLogic.areAllTestWordsGenerated() &&
TestWords.words.currentIndex === TestWords.words.length
) {
if (
!isWordCorrect &&
(Config.difficulty === "expert" || Config.difficulty === "master")
) {
TestLogic.fail("difficulty");
} else {
void TestLogic.finish();
}
return;
}
let wordLength: number;
if (Config.mode === "zen") {
wordLength = TestInput.input.current.length;