Skip to content

Commit

Permalink
impr(funbox): rework backwards funbox
Browse files Browse the repository at this point in the history
closes #4711
  • Loading branch information
Miodec committed Oct 9, 2023
1 parent 2fabadd commit 0c3b6e4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
6 changes: 5 additions & 1 deletion backend/src/constants/funbox-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ const FunboxList: MonkeyTypes.FunboxMetadata[] = [
},
{
name: "backwards",
properties: ["noLigatures", "conflictsWithSymmetricChars"],
properties: [
"noLigatures",
"conflictsWithSymmetricChars",
"wordOrder:reverse",
],
frontendFunctions: ["applyCSS"],
canGetPb: true,
difficultyLevel: 3,
Expand Down
7 changes: 6 additions & 1 deletion backend/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export function areFunboxesCompatible(funboxesString: string): boolean {
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "nospace" || fp.startsWith("toPush"))
).length <= 1;
const oneWordOrderMax =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp.startsWith("wordOrder"))
).length <= 1;
const oneChangesWordsVisibilityMax =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "changesWordsVisibility")
Expand Down Expand Up @@ -229,6 +233,7 @@ export function areFunboxesCompatible(funboxesString: string): boolean {
onePunctuateWordMax &&
oneCharCheckerMax &&
oneCharReplacerMax &&
noConfigConflicts
noConfigConflicts &&
oneWordOrderMax
);
}
7 changes: 5 additions & 2 deletions frontend/src/ts/test/funbox/funbox-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ const list: MonkeyTypes.FunboxMetadata[] = [
{
name: "backwards",
info: "...sdrawkcab epyt ot yrt woN",
properties: ["noLigatures", "conflictsWithSymmetricChars"],
hasCSS: true,
properties: [
"noLigatures",
"conflictsWithSymmetricChars",
"wordOrder:reverse",
],
},
];

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/ts/test/funbox/funbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ FunboxList.setFunboxFunctions("rAnDoMcAsE", {
},
});

FunboxList.setFunboxFunctions("backwards", {
alterText(word: string): string {
return word.split("").reverse().join("");
},
});

FunboxList.setFunboxFunctions("capitals", {
alterText(word: string): string {
return Misc.capitalizeFirstLetterOfEachWord(word);
Expand Down
28 changes: 26 additions & 2 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ function applyLazyModeToWord(
return word;
}

export function getQuoteOrCustomModeWordOrder(): MonkeyTypes.FunboxWordOrder {
const wordOrder = FunboxList.get(Config.funbox)
.find((f) => f.properties?.find((fp) => fp.startsWith("wordOrder")))
?.properties?.find((fp) => fp.startsWith("wordOrder"));

if (!wordOrder) {
return "normal";
} else {
return wordOrder.split(":")[1] as MonkeyTypes.FunboxWordOrder;
}
}

export function getWordsLimit(): number {
let limit = 100;

Expand Down Expand Up @@ -432,14 +444,26 @@ export async function generateWords(
};
const limit = getWordsLimit();

const wordOrder = getQuoteOrCustomModeWordOrder();
console.debug("Word order", wordOrder);

let wordList = language.words;
if (Config.mode === "custom") {
wordList = CustomText.text;
if (wordOrder === "reverse") {
wordList = CustomText.text.reverse();
} else {
wordList = CustomText.text;
}
}
const wordset = await Wordset.withWords(wordList);

if (Config.mode === "quote") {
return await generateQuoteWords(language, wordset, limit);
const quoteWords = await generateQuoteWords(language, wordset, limit);
if (wordOrder === "reverse") {
quoteWords.words.reverse();
quoteWords.sectionIndexes.reverse();
}
return quoteWords;
}

if (
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/ts/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ declare namespace MonkeyTypes {

type FunboxWordsFrequency = "normal" | "zipf";

type FunboxWordOrder = "normal" | "reverse";

type FunboxProperty =
| "symmetricChars"
| "conflictsWithSymmetricChars"
Expand All @@ -244,7 +246,8 @@ declare namespace MonkeyTypes {
| "nospace"
| `toPush:${number}`
| "noInfiniteDuration"
| "changesWordsFrequency";
| "changesWordsFrequency"
| `wordOrder:${FunboxWordOrder}`;

interface FunboxFunctions {
getWord?: (wordset?: Misc.Wordset, wordIndex?: number) => string;
Expand Down

0 comments on commit 0c3b6e4

Please sign in to comment.