diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index fdce7542d..476b96794 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -415,7 +415,7 @@ let languageBeforeQuoteMode: string | undefined; export async function init(): Promise { console.debug("Initializing test"); testReinitCount++; - if (testReinitCount >= 5) { + if (testReinitCount >= 4) { TestUI.setTestRestarting(false); Notifications.add( "Too many test reinitialization attempts. Something is going very wrong. Please contact support.", diff --git a/frontend/src/ts/test/words-generator.ts b/frontend/src/ts/test/words-generator.ts index aa9bcf7ab..f69b20ad7 100644 --- a/frontend/src/ts/test/words-generator.ts +++ b/frontend/src/ts/test/words-generator.ts @@ -271,30 +271,24 @@ function getFunboxWordsFrequency(): return undefined; } -async function getFunboxSection(limit: number): Promise { +async function getFunboxSection(): Promise { const ret = []; const sectionFunbox = FunboxList.get(Config.funbox).find( (f) => f.functions?.pullSection ); if (sectionFunbox?.functions?.pullSection) { - while (ret.length < limit) { - const section = await sectionFunbox.functions.pullSection( - Config.language - ); + const section = await sectionFunbox.functions.pullSection(Config.language); - if (section === false) { - UpdateConfig.toggleFunbox(sectionFunbox.name); - throw new Error("Failed to pull section"); - } - - if (section === undefined) continue; - - for (const word of section.words) { - if (ret.length >= Config.words && Config.mode === "words") { - break; - } - ret.push(word); + if (section === false || section === undefined) { + UpdateConfig.toggleFunbox(sectionFunbox.name); + throw new Error("Failed to pull section"); + } + + for (const word of section.words) { + if (ret.length >= Config.words && Config.mode === "words") { + break; } + ret.push(word); } } return ret; @@ -442,6 +436,8 @@ export class WordGenError extends Error { let currentQuote: string[] = []; +let isCurrentlyUsingFunboxSection = false; + export async function generateWords( language: MonkeyTypes.LanguageObject ): Promise<{ @@ -459,6 +455,13 @@ export async function generateWords( words: [], sectionIndexes: [], }; + + const sectionFunbox = FunboxList.get(Config.funbox).find( + (f) => f.functions?.pullSection + ); + isCurrentlyUsingFunboxSection = + sectionFunbox?.functions?.pullSection !== undefined; + const limit = getWordsLimit(); const wordOrder = getQuoteOrCustomModeWordOrder(); @@ -488,22 +491,6 @@ export async function generateWords( Config.mode === "words" || Config.mode === "custom" ) { - const funboxSection = await getFunboxSection(limit); - if (funboxSection.length > 0) { - const indexes = []; - for (let i = 0; i < funboxSection.length; i++) { - indexes.push(i); - } - const ret = []; - for (const word of funboxSection) { - ret.push(applyLazyModeToWord(applyFunboxesToWord(word), language)); - } - return { - words: ret, - sectionIndexes: indexes, - }; - } - let stop = false; let i = 0; while (stop === false) { @@ -672,7 +659,10 @@ export async function getNextWord( const previousWord2Raw = previousWord2 .replace(/[.?!":\-,']/g, "") .toLowerCase(); + if (currentSection.length === 0) { + const funboxSection = await getFunboxSection(); + if (Config.mode === "quote") { randomWord = currentQuote[wordIndex]; } else if ( @@ -704,6 +694,8 @@ export async function getNextWord( regenerationCount++; randomWord = wordset.randomWord(funboxFrequency); } + } else if (isCurrentlyUsingFunboxSection) { + randomWord = funboxSection.join(" "); } else { let regenarationCount = 0; //infinite loop emergency stop button let firstAfterSplit = randomWord.split(" ")[0].toLowerCase(); @@ -759,7 +751,8 @@ export async function getNextWord( !Config.punctuation && !Config.language.startsWith("german") && !Config.language.startsWith("swiss_german") && - !Config.language.startsWith("code") + !Config.language.startsWith("code") && + !isCurrentlyUsingFunboxSection ) { randomWord = randomWord.toLowerCase(); } @@ -773,7 +766,11 @@ export async function getNextWord( randomWord = randomWord.replace(/ß/g, "ss"); } - if (Config.punctuation && !language.originalPunctuation === true) { + if ( + Config.punctuation && + !language.originalPunctuation === true && + !isCurrentlyUsingFunboxSection + ) { randomWord = await punctuateWord( previousWord, randomWord,