reworked how funbox is applied

removes circular dependency
closes #2462
This commit is contained in:
Miodec 2022-02-11 21:15:43 +01:00
parent 5619f9a5ae
commit a8227b0134
2 changed files with 20 additions and 31 deletions

View file

@ -1,7 +1,5 @@
import * as TestLogic from "./test-logic";
import * as TestWords from "./test-words";
import * as Notifications from "../elements/notifications";
import * as TestUI from "./test-ui";
import * as Misc from "../misc";
import * as ManualRestart from "./manual-restart-tracker";
import Config, * as UpdateConfig from "../config";
@ -121,7 +119,8 @@ export async function activate(funbox) {
"Current language does not support this funbox mode",
0
);
setFunbox("none", null);
UpdateConfig.setFunbox("none", true);
await clear();
return;
}
}
@ -133,14 +132,8 @@ export async function activate(funbox) {
)} mode does not support the ${funbox} funbox`,
0
);
setFunbox("none", null);
if (TestUI.testRestartingPromise) {
TestUI.testRestartingPromise.then(() => {
TestLogic.restart(false, true);
});
} else {
TestLogic.restart(false, true);
}
UpdateConfig.setFunbox("none", true);
await clear();
return;
}
}
@ -167,7 +160,6 @@ export async function activate(funbox) {
if (funbox === "simon_says") {
UpdateConfig.setKeymapMode("next", true);
TestLogic.restart(false, true);
}
if (
@ -176,14 +168,12 @@ export async function activate(funbox) {
funbox === "read_ahead_hard"
) {
UpdateConfig.setHighlightMode("letter", true);
TestLogic.restart(false, true);
}
} else if (mode === "script") {
if (funbox === "tts") {
$("#funBoxTheme").attr("href", `funbox/simon_says.css`);
UpdateConfig.setKeymapMode("off", true);
UpdateConfig.setHighlightMode("letter", true);
TestLogic.restart(false, true);
} else if (funbox === "layoutfluid") {
UpdateConfig.setLayout(
Config.customLayoutfluid
@ -197,22 +187,18 @@ export async function activate(funbox) {
: "qwerty",
true
);
TestLogic.restart(false, true);
} else if (funbox === "memory") {
UpdateConfig.setMode("words", true);
UpdateConfig.setShowAllLines(true, true);
TestLogic.restart(false, true);
if (Config.keymapMode === "next") {
UpdateConfig.setKeymapMode("react", true);
}
} else if (funbox === "nospace") {
$("#words").addClass("nospace");
UpdateConfig.setHighlightMode("letter", true);
TestLogic.restart(false, true);
} else if (funbox === "arrows") {
$("#words").addClass("arrows");
UpdateConfig.setHighlightMode("letter", true);
TestLogic.restart(false, true);
}
}
ModesNotice.update();

View file

@ -438,6 +438,17 @@ export function restart(
UpdateConfig.setPunctuation(false, true);
UpdateConfig.setNumbers(false, true);
}
if (
withSameWordset &&
(Config.funbox === "plus_one" || Config.funbox === "plus_two")
) {
Notifications.add(
"Sorry, this funbox won't work with repeated tests.",
0,
4
);
withSameWordset = false;
}
if (!withSameWordset && !shouldQuoteRepeat) {
TestState.setRepeated(false);
TestState.setPaceRepeat(repeatWithPace);
@ -451,15 +462,6 @@ export function restart(
Replay.stopReplayRecording();
TestWords.words.resetCurrentIndex();
TestInput.input.reset();
if (Config.funbox === "plus_one" || Config.funbox === "plus_two") {
Notifications.add(
"Sorry, this funbox won't work with repeated tests.",
0
);
await Funbox.clear();
} else {
await Funbox.activate();
}
TestUI.showWords();
if (Config.keymapMode === "next" && Config.mode !== "zen") {
Keymap.highlightKey(
@ -681,6 +683,10 @@ export async function init() {
TestInput.input.resetHistory();
TestInput.input.resetCurrent();
if (ActivePage.get() == "test") {
await Funbox.activate();
}
let language = await Misc.getLanguage(Config.language);
if (language && language.name !== Config.language) {
UpdateConfig.setLanguage("english");
@ -951,9 +957,6 @@ export async function init() {
// $("#words").css("height", "auto");
// $("#wordsWrapper").css("height", "auto");
// } else {
if (ActivePage.get() == "test") {
await Funbox.activate();
}
TestUI.showWords();
if (Config.keymapMode === "next" && Config.mode !== "zen") {
Keymap.highlightKey(
@ -1303,7 +1306,7 @@ export async function finish(difficultyFailed = false) {
TimerProgress.hide();
OutOfFocus.hide();
TestTimer.clear();
Funbox.activate("none", null);
Funbox.clear();
//need one more calculation for the last word if test auto ended
if (TestInput.burstHistory.length !== TestInput.input.getHistory().length) {