Merge branch 'master' into newads

This commit is contained in:
Miodec 2023-04-17 16:45:07 +02:00
commit efef1bce85
4 changed files with 16 additions and 11 deletions

View file

@ -238,7 +238,6 @@ function handleSpace(): void {
Caret.updatePosition();
TestInput.incrementKeypressCount();
TestInput.pushKeypressWord(TestWords.words.currentIndex);
TestInput.updateLastKeypress();
if (Config.difficulty == "expert" || Config.difficulty == "master") {
TestLogic.fail("difficulty");
return;
@ -249,6 +248,7 @@ function handleSpace(): void {
}
Replay.addReplayEvent("submitErrorWord");
}
TestInput.updateLastKeypress();
let wordLength: number;
if (Config.mode === "zen") {
@ -885,7 +885,7 @@ $(document).keydown(async (event) => {
0,
{
important: true,
duration: 5000,
duration: 5,
}
);
}

View file

@ -1555,6 +1555,11 @@ export async function finish(difficultyFailed = false): Promise<void> {
TestInput.forceKeyup(now); //this ensures that the last keypress(es) are registered
const endAfkSeconds = (now - TestInput.keypressTimings.spacing.last) / 1000;
if ((Config.mode == "zen" || TestInput.bailout) && endAfkSeconds < 7) {
TestStats.setEnd(TestInput.keypressTimings.spacing.last);
}
TestUI.setResultCalculating(true);
TestUI.setResultVisible(true);
TestState.setActive(false);

View file

@ -4,6 +4,7 @@ import * as Misc from "../utils/misc";
import * as TestInput from "./test-input";
import * as TestWords from "./test-words";
import * as FunboxList from "./funbox/funbox-list";
import * as TestState from "./test-state";
interface CharCount {
spaces: number;
@ -186,16 +187,12 @@ export function setInvalid(): void {
export function calculateTestSeconds(now?: number): number {
if (now === undefined) {
const endAfkSeconds = (end - TestInput.lastKeypress) / 1000;
if ((Config.mode == "zen" || TestInput.bailout) && endAfkSeconds < 7) {
return (TestInput.lastKeypress - start) / 1000;
} else {
return (end - start) / 1000;
}
return (end - start) / 1000;
} else {
return (now - start) / 1000;
}
}
let avg = 0;
export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw {
const start = performance.now();
@ -279,13 +276,15 @@ export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw {
spaces = 0;
}
chars += currTestInput.length;
const testSeconds = calculateTestSeconds(performance.now());
const testSeconds = calculateTestSeconds(
TestState.isActive ? performance.now() : end
);
const wpm = Math.round(
((correctWordChars + spaces) * (60 / testSeconds)) / 5
);
const raw = Math.round(((chars + spaces) * (60 / testSeconds)) / 5);
const end = performance.now();
avg = (end - start + avg) / 2;
const endPerf = performance.now();
avg = (endPerf - start + avg) / 2;
return {
wpm: wpm,
raw: raw,

View file

@ -80,6 +80,7 @@
"John",
"Moanatari",
"Gregory",
"Yen Cheng",
"Hopeless Love",
"Kalen",
"Ben",