diff --git a/frontend/src/ts/index.ts b/frontend/src/ts/index.ts index a358f76bfdb1..d717e0411a06 100644 --- a/frontend/src/ts/index.ts +++ b/frontend/src/ts/index.ts @@ -43,6 +43,8 @@ import { loadFromLocalStorage } from "./config/lifecycle"; import "./input/hotkeys"; import { showModal } from "./states/modals"; +import { lastEventLog } from "./test/test-state"; +import { buildEventLog } from "./test/events/data"; // Lock Math.random Object.defineProperty(Math, "random", { @@ -94,6 +96,12 @@ addToGlobal({ qs: qs, qsa: qsa, qsr: qsr, + lastEventLog: () => { + console.log(lastEventLog); + }, + currentEventLog: () => { + console.log(buildEventLog()); + }, }); mountComponents(); diff --git a/frontend/src/ts/input/handlers/insert-text.ts b/frontend/src/ts/input/handlers/insert-text.ts index 70ae26173981..b5a9b4f13a0a 100644 --- a/frontend/src/ts/input/handlers/insert-text.ts +++ b/frontend/src/ts/input/handlers/insert-text.ts @@ -11,13 +11,14 @@ import { checkIfFailedDueToMinBurst, checkIfFinished, } from "../helpers/fail-or-finish"; -import { areCharactersVisuallyEqual, isSpace } from "../../utils/strings"; +import { + areCharactersVisuallyEqual, + isSpace, + removeLanguageSize, +} from "../../utils/strings"; import * as TestState from "../../test/test-state"; import * as TestLogic from "../../test/test-logic"; -import { - findSingleActiveFunboxWithFunction, - isFunboxActiveWithProperty, -} from "../../test/funbox/list"; +import { isFunboxActiveWithProperty } from "../../test/funbox/list"; import { Config } from "../../config/store"; import { flash } from "../../events/keymap"; import * as WeakSpot from "../../test/weak-spot"; @@ -44,6 +45,10 @@ const charOverrides = new Map([ // ["æ", "ae"], ]); +const languageCharOverrides = new Map([ + ["dutch", [["ij", "ij"]]], +]); + type OnInsertTextParams = { // might need later? // inputType: SupportedInputType; @@ -95,6 +100,29 @@ export async function onInsertText(options: OnInsertTextParams): Promise { return; } + const languageOverrides = languageCharOverrides.get( + removeLanguageSize(Config.language), + ); + if (languageOverrides !== undefined) { + for (const [targetChar, overrideChar] of languageOverrides) { + if ( + options.data === targetChar && + TestWords.words.getCurrentText()[getCurrentInput().length] !== + options.data + ) { + // replace the data with the override + setInputElementValue( + inputValue.slice(0, -options.data.length) + overrideChar, + ); + await onInsertText({ + ...options, + data: overrideChar, + }); + return; + } + } + } + // input and target word const testInput = getCurrentInput(); const currentWord = TestWords.words.getCurrentText(); @@ -129,20 +157,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise { Config.oppositeShiftMode === "off" ? null : isCorrectShiftUsed(); // is char correct - const funboxCorrect = findSingleActiveFunboxWithFunction( - "isCharCorrect", - )?.functions.isCharCorrect( + const charCorrect = isCharCorrect({ data, - currentWord[(testInput + data).length - 1] ?? "", - ); - const charCorrect = - funboxCorrect ?? - isCharCorrect({ - data, - inputValue: testInput, - targetWord: currentWord, - correctShiftUsed, - }); + inputValue: testInput, + targetWord: currentWord, + correctShiftUsed, + }); // word navigation check const noSpaceForce = @@ -155,13 +175,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise { // when moving to the next word, correctness is word-level (a correct word-completing // space has charCorrect === false, so charCorrect can't be used below) const correct = goingToNextWord - ? (funboxCorrect ?? - isWordCorrect({ + ? isWordCorrect({ data, inputValue: testInput, targetWord: currentWord, correctShiftUsed, - })) + }) : charCorrect; // handing cases where last char needs to be removed diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 28e4f8b834fb..73d6422c6cfb 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -42,7 +42,6 @@ export type FunboxFunctions = { pullSection?: (language?: Language) => Promise; handleSpace?: () => void; getEmulatedChar?: (event: KeyboardEvent) => string | null; - isCharCorrect?: (char: string, originalChar: string) => boolean; handleKeydown?: (event: KeyboardEvent) => Promise; getResultContent?: () => string; start?: () => void; @@ -261,42 +260,6 @@ const list: Partial> = { } return null; }, - isCharCorrect(char: string, originalChar: string): boolean { - if ( - (char === "a" || - char === "ArrowLeft" || - char === "j" || - char === "←") && - originalChar === "←" - ) { - return true; - } - if ( - (char === "s" || - char === "ArrowDown" || - char === "k" || - char === "↓") && - originalChar === "↓" - ) { - return true; - } - if ( - (char === "w" || char === "ArrowUp" || char === "i" || char === "↑") && - originalChar === "↑" - ) { - return true; - } - if ( - (char === "d" || - char === "ArrowRight" || - char === "l" || - char === "→") && - originalChar === "→" - ) { - return true; - } - return false; - }, getWordHtml(char: string, letterTag?: boolean): string { let retval = ""; if (char === "↑") { diff --git a/packages/funbox/src/list.ts b/packages/funbox/src/list.ts index b5cb5a2589d0..866decc7d7e7 100644 --- a/packages/funbox/src/list.ts +++ b/packages/funbox/src/list.ts @@ -108,7 +108,6 @@ const list: Record = { "getWord", "rememberSettings", "getEmulatedChar", - "isCharCorrect", "getWordHtml", ], name: "arrows", diff --git a/packages/funbox/src/validation.ts b/packages/funbox/src/validation.ts index 0ad0335d372b..95374ea1412c 100644 --- a/packages/funbox/src/validation.ts +++ b/packages/funbox/src/validation.ts @@ -178,10 +178,6 @@ export function checkCompatibility( funboxesToCheck.filter((f) => f.frontendFunctions?.includes("getEmulatedChar"), ).length <= 1; - const oneCharCheckerMax = - funboxesToCheck.filter((f) => - f.frontendFunctions?.includes("isCharCorrect"), - ).length <= 1; const oneCharReplacerMax = funboxesToCheck.filter((f) => f.frontendFunctions?.includes("getWordHtml")) .length <= 1; @@ -240,7 +236,6 @@ export function checkCompatibility( oneToPushOrPullSectionMax && onePunctuateWordMax && oneGetEmulatedCharMax && - oneCharCheckerMax && oneCharReplacerMax && oneChangesCapitalisationMax && oneCssModificationPerElement &&