Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -94,6 +96,12 @@ addToGlobal({
qs: qs,
qsa: qsa,
qsr: qsr,
lastEventLog: () => {
console.log(lastEventLog);
},
currentEventLog: () => {
console.log(buildEventLog());
},
});

mountComponents();
61 changes: 40 additions & 21 deletions frontend/src/ts/input/handlers/insert-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -44,6 +45,10 @@ const charOverrides = new Map<string, string>([
// ["æ", "ae"],
]);

const languageCharOverrides = new Map<string, [string, string][]>([
["dutch", [["ij", "ij"]]],
]);

type OnInsertTextParams = {
// might need later?
// inputType: SupportedInputType;
Expand Down Expand Up @@ -95,6 +100,29 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
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();
Expand Down Expand Up @@ -129,20 +157,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
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 =
Expand All @@ -155,13 +175,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
// 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
Expand Down
37 changes: 0 additions & 37 deletions frontend/src/ts/test/funbox/funbox-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export type FunboxFunctions = {
pullSection?: (language?: Language) => Promise<JSONData.Section | false>;
handleSpace?: () => void;
getEmulatedChar?: (event: KeyboardEvent) => string | null;
isCharCorrect?: (char: string, originalChar: string) => boolean;
handleKeydown?: (event: KeyboardEvent) => Promise<void>;
getResultContent?: () => string;
start?: () => void;
Expand Down Expand Up @@ -261,42 +260,6 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
}
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 === "↑") {
Expand Down
1 change: 0 additions & 1 deletion packages/funbox/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const list: Record<FunboxName, FunboxMetadata> = {
"getWord",
"rememberSettings",
"getEmulatedChar",
"isCharCorrect",
"getWordHtml",
],
name: "arrows",
Expand Down
5 changes: 0 additions & 5 deletions packages/funbox/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -240,7 +236,6 @@ export function checkCompatibility(
oneToPushOrPullSectionMax &&
onePunctuateWordMax &&
oneGetEmulatedCharMax &&
oneCharCheckerMax &&
oneCharReplacerMax &&
oneChangesCapitalisationMax &&
oneCssModificationPerElement &&
Expand Down
Loading