From cd7777947531e852fe3f3c4661510cfadc8a8ba5 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 27 Sep 2021 00:55:16 +0100 Subject: [PATCH] quotes now use the words bound system, fixes plus one and two funboxes not working for quotes --- src/js/input-controller.js | 3 +- src/js/test/test-logic.js | 139 +++++++++++++++++++--------------- src/js/test/timer-progress.js | 47 ++++-------- 3 files changed, 92 insertions(+), 97 deletions(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index f8892b178..3c6c4d9c2 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -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(); } diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index 3a7a7a470..00dcc4aae 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -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 || diff --git a/src/js/test/timer-progress.js b/src/js/test/timer-progress.js index 08eed76ef..b38a39da6 100644 --- a/src/js/test/timer-progress.js +++ b/src/js/test/timer-progress.js @@ -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( "
" + `${TestLogic.input.history.length}` + "
" @@ -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}`