quotes now use the words bound system, fixes plus one and two funboxes not working for quotes

This commit is contained in:
Jack 2021-09-27 00:55:16 +01:00
parent c00dfc2385
commit cd77779475
3 changed files with 92 additions and 97 deletions

View file

@ -447,7 +447,8 @@ function handleSpace(event, isEnter) {
if (
Config.mode == "time" ||
Config.mode == "words" ||
Config.mode == "custom"
Config.mode == "custom" ||
Config.mode == "quote"
) {
TestLogic.addWord();
}

View file

@ -477,71 +477,74 @@ export async function init() {
UpdateConfig.setLazyMode(false);
}
let wordsBound = 100;
if (Config.showAllLines) {
if (Config.mode === "quote") {
wordsBound = 100;
} else if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
wordsBound = CustomText.word;
} else if (CustomText.isTimeRandom) {
wordsBound = 100;
} else {
wordsBound = CustomText.text.length;
}
} else if (Config.mode != "time") {
wordsBound = Config.words;
}
} else {
if (Config.mode === "words" && Config.words < wordsBound) {
wordsBound = Config.words;
}
if (
Config.mode == "custom" &&
CustomText.isWordRandom &&
CustomText.word < wordsBound
) {
wordsBound = CustomText.word;
}
if (
Config.mode == "custom" &&
CustomText.isTimeRandom &&
CustomText.time < wordsBound
) {
wordsBound = 100;
}
if (
Config.mode == "custom" &&
!CustomText.isWordRandom &&
CustomText.text.length < wordsBound
) {
wordsBound = CustomText.text.length;
}
}
if (
(Config.mode === "custom" &&
CustomText.isWordRandom &&
CustomText.word == 0) ||
(Config.mode === "custom" &&
CustomText.isTimeRandom &&
CustomText.time == 0)
) {
wordsBound = 100;
}
if (Config.mode === "words" && Config.words === 0) {
wordsBound = 100;
}
if (Config.funbox === "plus_one") {
wordsBound = 2;
}
if (Config.funbox === "plus_two") {
wordsBound = 3;
}
if (
Config.mode == "time" ||
Config.mode == "words" ||
Config.mode == "custom"
) {
let wordsBound = 100;
if (Config.showAllLines) {
if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
wordsBound = CustomText.word;
} else if (CustomText.isTimeRandom) {
wordsBound = 100;
} else {
wordsBound = CustomText.text.length;
}
} else if (Config.mode != "time") {
wordsBound = Config.words;
}
} else {
if (Config.mode === "words" && Config.words < wordsBound) {
wordsBound = Config.words;
}
if (
Config.mode == "custom" &&
CustomText.isWordRandom &&
CustomText.word < wordsBound
) {
wordsBound = CustomText.word;
}
if (
Config.mode == "custom" &&
CustomText.isTimeRandom &&
CustomText.time < wordsBound
) {
wordsBound = 100;
}
if (
Config.mode == "custom" &&
!CustomText.isWordRandom &&
CustomText.text.length < wordsBound
) {
wordsBound = CustomText.text.length;
}
}
if (
(Config.mode === "custom" &&
CustomText.isWordRandom &&
CustomText.word == 0) ||
(Config.mode === "custom" &&
CustomText.isTimeRandom &&
CustomText.time == 0)
) {
wordsBound = 100;
}
if (Config.mode === "words" && Config.words === 0) {
wordsBound = 100;
}
if (Config.funbox === "plus_one") {
wordsBound = 2;
}
if (Config.funbox === "plus_two") {
wordsBound = 3;
}
let wordList = language.words;
if (Config.mode == "custom") {
wordList = CustomText.text;
@ -743,12 +746,18 @@ export async function init() {
rq.text = rq.text.replace(/( *(\r\n|\r|\n) *)/g, "\n ");
rq.text = rq.text.replace(/…/g, "...");
rq.text = rq.text.trim();
rq.textSplit = rq.text.split(" ");
rq.language = Config.language.replace(/_\d*k$/g, "");
setRandomQuote(rq);
let w = randomQuote.text.trim().split(" ");
for (let i = 0; i < w.length; i++) {
let w = randomQuote.textSplit;
if (Config.showAllLines) {
wordsBound = Math.min(wordsBound, w.length);
}
for (let i = 0; i < wordsBound; i++) {
if (/\t/g.test(w[i])) {
setHasTab(true);
}
@ -1095,7 +1104,8 @@ export async function addWord() {
CustomText.word != 0) ||
(Config.mode === "custom" &&
!CustomText.isWordRandom &&
words.length >= CustomText.text.length)
words.length >= CustomText.text.length) ||
(Config.mode === "quote" && words.length >= randomQuote.textSplit.length)
)
return;
const language =
@ -1129,6 +1139,9 @@ export async function addWord() {
!CustomText.isTimeRandom
) {
randomWord = CustomText.text[words.length];
}
if (Config.mode === "quote") {
randomWord = randomQuote.textSplit[words.length];
} else {
while (
previousWordStripped == randomWord ||

View file

@ -124,18 +124,21 @@ export function update() {
Config.mode === "custom" ||
Config.mode === "quote"
) {
let outof = TestLogic.words.length;
if (Config.mode === "words") {
outof = Config.words;
}
if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
outof = CustomText.word;
} else {
outof = CustomText.text.length;
}
}
if (Config.mode === "quote") {
outof = TestLogic.randomQuote.textSplit.length;
}
if (Config.timerStyle === "bar") {
let outof = TestLogic.words.length;
if (Config.mode === "words") {
outof = Config.words;
}
if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
outof = CustomText.word;
} else {
outof = CustomText.text.length;
}
}
let percent = Math.floor(
((TestLogic.words.currentIndex + 1) / outof) * 100
);
@ -148,17 +151,6 @@ export function update() {
250
);
} else if (Config.timerStyle === "text") {
let outof = TestLogic.words.length;
if (Config.mode === "words") {
outof = Config.words;
}
if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
outof = CustomText.word;
} else {
outof = CustomText.text.length;
}
}
if (outof === 0) {
$("#timerNumber").html(
"<div>" + `${TestLogic.input.history.length}` + "</div>"
@ -169,17 +161,6 @@ export function update() {
);
}
} else if (Config.timerStyle === "mini") {
let outof = TestLogic.words.length;
if (Config.mode === "words") {
outof = Config.words;
}
if (Config.mode === "custom") {
if (CustomText.isWordRandom) {
outof = CustomText.word;
} else {
outof = CustomText.text.length;
}
}
if (Config.words === 0) {
$("#miniTimerAndLiveWpm .time").html(
`${TestLogic.input.history.length}`