"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 <jack@monkeytype.com>
This commit is contained in:
Spax 2023-03-27 14:21:11 -06:00 committed by GitHub
parent 66290637c0
commit 470a54ee02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 15 deletions

View file

@ -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");

View file

@ -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<string> {
@ -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<void> {
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<void> {
};
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) {

View file

@ -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<Misc.Wordset>;
alterText?: (word: string) => string;

View file

@ -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;