From 470a54ee021de895ea222490f9313e118cac02dd Mon Sep 17 00:00:00 2001 From: Spax <83354374+SpiritAxolotl@users.noreply.github.com> Date: Mon, 27 Mar 2023 14:21:11 -0600 Subject: [PATCH] "Arrows" funbox starts with left/right only (#4122) SpritAxolotl * Arrows start with left/right part 1 * Arrows start with left/right part 2 * refactor * passing in wordindex instead of trying to use wordset * removed console log --------- Co-authored-by: Miodec --- frontend/src/ts/test/funbox/funbox.ts | 4 ++-- frontend/src/ts/test/test-logic.ts | 20 +++++++++++++++----- frontend/src/ts/types/types.d.ts | 2 +- frontend/src/ts/utils/misc.ts | 11 ++++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox.ts b/frontend/src/ts/test/funbox/funbox.ts index 5fba7880d..02c73fe86 100644 --- a/frontend/src/ts/test/funbox/funbox.ts +++ b/frontend/src/ts/test/funbox/funbox.ts @@ -159,8 +159,8 @@ FunboxList.setFunboxFunctions("choo_choo", { }); FunboxList.setFunboxFunctions("arrows", { - getWord(): string { - return Misc.chart2Word(); + getWord(_wordset, wordIndex): string { + return Misc.chart2Word(wordIndex === 0); }, applyConfig(): void { $("#words").addClass("arrows"); diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index e9cf6744e..bd829011b 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -687,12 +687,16 @@ function getFunboxWordsFrequency(): return undefined; } -function getFunboxWord(word: string, wordset?: Misc.Wordset): string { +function getFunboxWord( + word: string, + wordIndex: number, + wordset?: Misc.Wordset +): string { const wordFunbox = FunboxList.get(Config.funbox).find( (f) => f.functions?.getWord ); if (wordFunbox?.functions?.getWord) { - word = wordFunbox.functions.getWord(wordset); + word = wordFunbox.functions.getWord(wordset, wordIndex); } return word; } @@ -725,6 +729,7 @@ function applyLazyModeToWord( async function getNextWord( wordset: Misc.Wordset, + wordIndex: number, language: MonkeyTypes.LanguageObject, wordsBound: number ): Promise { @@ -789,7 +794,7 @@ async function getNextWord( randomWord = randomWord.replace(/ +/gm, " "); randomWord = randomWord.replace(/(^ )|( $)/gm, ""); randomWord = applyLazyModeToWord(randomWord, language); - randomWord = getFunboxWord(randomWord, wordset); + randomWord = getFunboxWord(randomWord, wordIndex, wordset); randomWord = await applyBritishEnglishToWord(randomWord); if (Config.punctuation) { @@ -1029,7 +1034,7 @@ export async function init(): Promise { if (wordCount == 0) { for (let i = 0; i < wordsBound; i++) { - const randomWord = await getNextWord(wordset, language, wordsBound); + const randomWord = await getNextWord(wordset, i, language, wordsBound); if (/\t/g.test(randomWord)) { TestWords.setHasTab(true); @@ -1273,7 +1278,12 @@ export async function addWord(): Promise { }; const wordset = await Wordset.withWords(language.words); - const randomWord = await getNextWord(wordset, language, bound); + const randomWord = await getNextWord( + wordset, + TestWords.words.length, + language, + bound + ); const split = randomWord.split(" "); if (split.length > 1) { diff --git a/frontend/src/ts/types/types.d.ts b/frontend/src/ts/types/types.d.ts index e911620db..560a8ede0 100644 --- a/frontend/src/ts/types/types.d.ts +++ b/frontend/src/ts/types/types.d.ts @@ -214,7 +214,7 @@ declare namespace MonkeyTypes { | "changesWordsFrequency"; interface FunboxFunctions { - getWord?: (wordset?: Misc.Wordset) => string; + getWord?: (wordset?: Misc.Wordset, wordIndex?: number) => string; punctuateWord?: (word: string) => string; withWords?: (words?: string[]) => Promise; alterText?: (word: string) => string; diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index 92dd02af0..a7330f30b 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -725,7 +725,6 @@ export function getASCII(): string { // code for "generateStep" is from Mirin's "Queue" modfile, // converted from lua to typescript by Spax // lineout: https://youtu.be/LnnArS9yrSs -let first = true; let footTrack = false; let currFacing = 0; let facingCount = 0; @@ -733,12 +732,11 @@ let lastLeftStep = 0, lastRightStep = 3, leftStepCount = 0, rightStepCount = 0; -function generateStep(): number { +function generateStep(leftRightOverride: boolean): number { facingCount--; let randomStep = Math.round(Math.random()); let stepValue = Math.round(Math.random() * 5 - 0.5); - if (first) { - first = !first; + if (leftRightOverride) { footTrack = Boolean(Math.round(Math.random())); if (footTrack) stepValue = 3; else stepValue = 0; @@ -776,12 +774,11 @@ function generateStep(): number { return stepValue; } -export function chart2Word(): string { +export function chart2Word(first: boolean): string { const arrowArray = ["←", "↓", "↑", "→"]; - let measure = ""; for (let i = 0; i < 4; i++) { - measure += arrowArray[generateStep()]; + measure += arrowArray[generateStep(i === 0 && first)]; } return measure;