From 14da1438d9c3af862fc2e4f2ad6280a5b64207cb Mon Sep 17 00:00:00 2001 From: Spax <83354374+SpiritAxolotl@users.noreply.github.com> Date: Mon, 20 Mar 2023 05:06:13 -0600 Subject: [PATCH] Implemented an ITG arrow mode to the funbox (#4084) spiritaxolotl * added arrows ITG to the list * added the implementation for arrows_ITG I also updated "arrows" so it supported ijkl as well as the normal arrowkeys and wasd * the actual implementation of the arrow generation I forgot to commit this one whoops * missed a curly bracket whoops * overwritten the arrows generation Instead of having two similar funboxes, miodec just said to implement the new generation in the existing arrows funbox. removed the arrows_ITG now next commit will remove it from the list as well * removed arrows_ITG and updated arrows * removed arrows' old generation method * updated a mistake * lint, prettier * added the TODO comment back didn't realize I removed it sorry * remove spaces * gave the variable names something more descriptive * remove preivous variables I hate working remotely * small refactor * simplify * simplify * remove export * starts with a left or right * prettier fix * removed "export" the function wasn't getting called outside of the file * parity for a list description * fixed that one character that got overwritten * Revert "fixed that one character that got overwritten" This reverts commit c8a394dc7b5beee4868e7b00523d75fa7d63880b. --------- Co-authored-by: Miodec Co-authored-by: Evan Co-authored-by: Evan <64989416+Ferotiq@users.noreply.github.com> --- frontend/src/ts/test/funbox/funbox-list.ts | 2 +- frontend/src/ts/test/funbox/funbox.ts | 30 ++++++--- frontend/src/ts/utils/misc.ts | 72 ++++++++++++++++++---- frontend/static/funbox/_list.json | 2 +- 4 files changed, 84 insertions(+), 22 deletions(-) diff --git a/frontend/src/ts/test/funbox/funbox-list.ts b/frontend/src/ts/test/funbox/funbox-list.ts index c22536ac9..ff10749bf 100644 --- a/frontend/src/ts/test/funbox/funbox-list.ts +++ b/frontend/src/ts/test/funbox/funbox-list.ts @@ -38,7 +38,7 @@ const list: MonkeyTypes.FunboxMetadata[] = [ }, { name: "arrows", - info: "Eurobeat Intensifies...", + info: "Play it on a pad!", properties: [ "ignoresLanguage", "ignoresLayout", diff --git a/frontend/src/ts/test/funbox/funbox.ts b/frontend/src/ts/test/funbox/funbox.ts index b87568d81..5fba7880d 100644 --- a/frontend/src/ts/test/funbox/funbox.ts +++ b/frontend/src/ts/test/funbox/funbox.ts @@ -160,7 +160,7 @@ FunboxList.setFunboxFunctions("choo_choo", { FunboxList.setFunboxFunctions("arrows", { getWord(): string { - return Misc.getArrows(); + return Misc.chart2Word(); }, applyConfig(): void { $("#words").addClass("arrows"); @@ -169,31 +169,43 @@ FunboxList.setFunboxFunctions("arrows", { save("highlightMode", Config.highlightMode, UpdateConfig.setHighlightMode); }, handleChar(char: string): string { - if (char === "a" || char === "ArrowLeft") { + if (char === "a" || char === "ArrowLeft" || char === "j") { return "←"; } - if (char === "s" || char === "ArrowDown") { + if (char === "s" || char === "ArrowDown" || char === "k") { return "↓"; } - if (char === "w" || char === "ArrowUp") { + if (char === "w" || char === "ArrowUp" || char === "i") { return "↑"; } - if (char === "d" || char === "ArrowRight") { + if (char === "d" || char === "ArrowRight" || char === "l") { return "→"; } return char; }, isCharCorrect(char: string, originalChar: string): boolean { - if ((char === "a" || char === "ArrowLeft") && originalChar === "←") { + if ( + (char === "a" || char === "ArrowLeft" || char === "j") && + originalChar === "←" + ) { return true; } - if ((char === "s" || char === "ArrowDown") && originalChar === "↓") { + if ( + (char === "s" || char === "ArrowDown" || char === "k") && + originalChar === "↓" + ) { return true; } - if ((char === "w" || char === "ArrowUp") && originalChar === "↑") { + if ( + (char === "w" || char === "ArrowUp" || char === "i") && + originalChar === "↑" + ) { return true; } - if ((char === "d" || char === "ArrowRight") && originalChar === "→") { + if ( + (char === "d" || char === "ArrowRight" || char === "l") && + originalChar === "→" + ) { return true; } return false; diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index 68659a226..298621e53 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -722,19 +722,69 @@ export function getASCII(): string { return ret; } -export function getArrows(): string { - const arrowArray = ["←", "↑", "→", "↓"]; - let arrowWord = ""; - let lastchar; - for (let i = 0; i < 5; i++) { - let random = randomElementFromArray(arrowArray); - while (random === lastchar) { - random = randomElementFromArray(arrowArray); +// 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; +let lastLeftStep = 0, + lastRightStep = 3, + leftStepCount = 0, + rightStepCount = 0; +function generateStep(): number { + facingCount--; + let randomStep = Math.round(Math.random()); + let stepValue = Math.round(Math.random() * 5 - 0.5); + if (first) { + first = !first; + footTrack = Boolean(Math.round(Math.random())); + if (footTrack) stepValue = 3; + else stepValue = 0; + } else { + //right foot + if (footTrack) { + if (lastLeftStep === randomStep) leftStepCount++; + else leftStepCount = 0; + if (leftStepCount > 1 || (rightStepCount > 0 && leftStepCount > 0)) { + randomStep = 1 - randomStep; + leftStepCount = 0; + } + lastLeftStep = randomStep; + stepValue = randomStep * (currFacing + 1); + //left foot + } else { + if (lastRightStep === randomStep) rightStepCount++; + else rightStepCount = 0; + if (rightStepCount > 1 || (rightStepCount > 0 && leftStepCount > 0)) { + randomStep = 1 - randomStep; + rightStepCount = 0; + } + lastRightStep = randomStep; + stepValue = 3 - randomStep * (currFacing + 1); + } + //alternation + footTrack = !footTrack; + + if (facingCount < 0 && randomStep === 0) { + currFacing = 1 - currFacing; + facingCount = Math.floor(Math.random() * 3) + 3; } - lastchar = random; - arrowWord += random; } - return arrowWord; + + return stepValue; +} + +export function chart2Word(): string { + const arrowArray = ["←", "↓", "↑", "→"]; + + let measure = ""; + for (let i = 0; i < 4; i++) { + measure += arrowArray[generateStep()]; + } + + return measure; } export function getPositionString(number: number): string { diff --git a/frontend/static/funbox/_list.json b/frontend/static/funbox/_list.json index ce03cacdf..b974db04c 100644 --- a/frontend/static/funbox/_list.json +++ b/frontend/static/funbox/_list.json @@ -35,7 +35,7 @@ }, { "name": "arrows", - "info": "Eurobeat Intensifies...", + "info": "Play it on a pad!", "canGetPb": false }, {