Merge pull request #1184 from Saint-dev/master

Made it so funbox gets temporarily disabled when not taking a test
This commit is contained in:
Jack 2021-04-08 19:08:10 +01:00 committed by GitHub
commit ab975b1a35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 14 deletions

View file

@ -126,7 +126,7 @@ let commandsFunbox = {
id: "changeFunboxNone",
display: "none",
exec: () => {
if (Funbox.activate("none", null)) {
if (Funbox.setFunbox("none", null)) {
TestLogic.restart();
}
},
@ -140,7 +140,7 @@ Misc.getFunboxList().then((funboxes) => {
id: "changeFunbox" + funbox.name,
display: funbox.name.replace(/_/g, " "),
exec: () => {
if (Funbox.activate(funbox.name, funbox.type)) {
if (Funbox.setFunbox(funbox.name, funbox.type)) {
TestLogic.restart();
}
},

View file

@ -428,7 +428,7 @@ export function updateDiscordSection() {
function setActiveFunboxButton() {
$(`.pageSettings .section.funbox .button`).removeClass("active");
$(
`.pageSettings .section.funbox .button[funbox='${Funbox.active}']`
`.pageSettings .section.funbox .button[funbox='${Funbox.funboxSaved}']`
).addClass("active");
}
@ -624,7 +624,7 @@ $(".pageSettings .section.discordIntegration #unlinkDiscordButton").click(
$(document).on("click", ".pageSettings .section.funbox .button", (e) => {
let funbox = $(e.currentTarget).attr("funbox");
let type = $(e.currentTarget).attr("type");
Funbox.activate(funbox, type);
Funbox.setFunbox(funbox, type);
setActiveFunboxButton();
});

View file

@ -7,6 +7,8 @@ import Config, * as UpdateConfig from "./config";
import * as Settings from "./settings";
export let active = "none";
export let funboxSaved = "none";
export let modeSaved = null;
let memoryTimer = null;
let memoryInterval = null;
@ -71,12 +73,8 @@ export function toggleScript(...params) {
}
export async function activate(funbox, mode) {
if (TestLogic.active || TestUI.resultVisible) {
Notifications.add(
"You can only change the funbox before starting a test.",
0
);
return false;
if (funbox === undefined || funbox === null) {
funbox = funboxSaved;
}
if (Misc.getCurrentLanguage().ligatures) {
if (funbox == "choo_choo" || funbox == "earthquake") {
@ -96,8 +94,12 @@ export async function activate(funbox, mode) {
$("#wordsWrapper").removeClass("hidden");
// }
if (mode === null || mode === undefined) {
if (funbox === "none" && mode === undefined) {
mode = null;
} else if (
(funbox !== "none" && mode === undefined) ||
(funbox !== "none" && mode === null)
) {
let list = await Misc.getFunboxList();
mode = list.filter((f) => f.name === funbox)[0].type;
}
@ -162,3 +164,16 @@ export async function activate(funbox, mode) {
TestUI.updateModesNotice();
return true;
}
export function setFunbox(funbox, mode) {
if (TestLogic.active || TestUI.resultVisible) {
Notifications.add(
"You can only change the funbox before starting a test.",
0
);
return false;
}
funboxSaved = funbox;
modeSaved = mode;
active = funbox;
return true;
}

View file

@ -576,6 +576,9 @@ export async function init() {
// } else {
TestUI.showWords();
// }
if ($(".pageTest").hasClass("active")) {
Funbox.activate();
}
}
export function restart(withSameWordset = false, nosave = false, event) {
@ -697,6 +700,7 @@ export function restart(withSameWordset = false, nosave = false, event) {
input.reset();
PaceCaret.init();
TestUI.showWords();
Funbox.activate();
}
if (Config.mode === "quote") {
setRepeated(false);
@ -924,6 +928,7 @@ export function finish(difficultyFailed = false) {
LiveAcc.hide();
TimerProgress.hide();
Keymap.hide();
Funbox.activate("none", null);
let stats = TestStats.calculateStats();
if (stats === undefined) {
stats = {
@ -1653,8 +1658,8 @@ export function finish(difficultyFailed = false) {
if (Config.blindMode) {
testType += "<br>blind";
}
if (Funbox.active !== "none") {
testType += "<br>" + Funbox.active.replace(/_/g, " ");
if (Funbox.funboxSaved !== "none") {
testType += "<br>" + Funbox.funboxSaved.replace(/_/g, " ");
}
if (Config.difficulty == "expert") {
testType += "<br>expert";

View file

@ -14,6 +14,7 @@ import * as ManualRestart from "./manual-restart-tracker";
import * as Settings from "./settings";
import * as Account from "./account";
import * as Leaderboards from "./leaderboards";
import * as Funbox from "./funbox";
export let pageTransition = false;
@ -136,6 +137,7 @@ export function changePage(page) {
TestStats.resetIncomplete();
ManualRestart.set();
TestLogic.restart();
Funbox.activate(Funbox.funboxSaved, Funbox.modeSaved);
} else if (page == "about") {
setPageTransition(true);
TestLogic.restart();
@ -144,6 +146,7 @@ export function changePage(page) {
history.pushState("about", null, "about");
$(".page.pageAbout").addClass("active");
});
Funbox.activate("none", null);
TestConfig.hide();
SignOutButton.hide();
} else if (page == "settings") {
@ -154,6 +157,7 @@ export function changePage(page) {
history.pushState("settings", null, "settings");
$(".page.pageSettings").addClass("active");
});
Funbox.activate("none", null);
Settings.update();
TestConfig.hide();
SignOutButton.hide();
@ -176,6 +180,7 @@ export function changePage(page) {
SignOutButton.show();
}
);
Funbox.activate("none", null);
Account.update();
TestConfig.hide();
}
@ -190,6 +195,7 @@ export function changePage(page) {
history.pushState("login", null, "login");
$(".page.pageLogin").addClass("active");
});
Funbox.activate("none", null);
TestConfig.hide();
SignOutButton.hide();
}