Skip to content

Commit

Permalink
feat(funbox): add underscore_spaces funbox (@Spurkus) (#6094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spurkus authored Dec 9, 2024
1 parent 52fda9d commit aa58a73
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions frontend/src/styles/test.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,13 @@ body.fb-nospace {
}
}

/* funbox underscore_spaces */
body.fb-underscore-spaces {
#words .word {
margin: 0.5em 0;
}
}

/* funbox arrows */
body.fb-arrows {
#words .word {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/ts/pages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ async function fillSettingsPage(): Promise<void> {
/_/g,
" "
)}</div>`;
} else if (funbox.name === "underscore_spaces") {
// Display as "underscore_spaces". Does not replace underscores with spaces.
funboxElHTML += `<div class="funbox button" data-config-value='${funbox.name}' aria-label="${funbox.description}" data-balloon-pos="up" data-balloon-length="fit">${funbox.name}</div>`;
} else {
funboxElHTML += `<div class="funbox button" data-config-value='${
funbox.name
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/ts/test/funbox/funbox-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type FunboxFunctions = {
getWord?: (wordset?: Wordset, wordIndex?: number) => string;
punctuateWord?: (word: string) => string;
withWords?: (words?: string[]) => Promise<Wordset>;
alterText?: (word: string) => string;
alterText?: (word: string, wordIndex: number, wordsBound: number) => string;
applyConfig?: () => void;
applyGlobalCSS?: () => void;
clearGlobal?: () => void;
Expand Down Expand Up @@ -584,6 +584,12 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
return GetText.getMorse(word);
},
},
underscore_spaces: {
alterText(word: string, wordIndex: number, limit: number): string {
if (wordIndex === limit - 1) return word; // don't add underscore to the last word
return word + "_";
},
},
crt: {
applyGlobalCSS(): void {
const isSafari = /^((?!chrome|android).)*safari/i.test(
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,14 @@ function getFunboxWord(
return word;
}

function applyFunboxesToWord(word: string): string {
function applyFunboxesToWord(
word: string,
wordIndex: number,
wordsBound: number
): string {
for (const fb of getActiveFunboxes()) {
if (fb.functions?.alterText) {
word = fb.functions.alterText(word);
word = fb.functions.alterText(word, wordIndex, wordsBound);
}
}
return word;
Expand Down Expand Up @@ -911,7 +915,7 @@ export async function getNextWord(
}
}

randomWord = applyFunboxesToWord(randomWord);
randomWord = applyFunboxesToWord(randomWord, wordIndex, wordsBound);

console.debug("Word:", randomWord);

Expand Down
8 changes: 8 additions & 0 deletions packages/funbox/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ const list: Record<FunboxName, FunboxMetadata> = {
frontendFunctions: ["alterText"],
name: "instant_messaging",
},
underscore_spaces: {
description: "Underscores_are_better.",
canGetPb: false,
difficultyLevel: 0,
properties: ["ignoresLanguage", "ignoresLayout", "nospace"],
frontendFunctions: ["alterText"],
name: "underscore_spaces",
},
ALL_CAPS: {
description: "WHY ARE WE SHOUTING?",
canGetPb: false,
Expand Down
1 change: 1 addition & 0 deletions packages/funbox/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type FunboxName =
| "backwards"
| "ddoouubblleedd"
| "instant_messaging"
| "underscore_spaces"
| "ALL_CAPS";

export type FunboxForcedConfig = Record<string, string[] | boolean[]>;
Expand Down

0 comments on commit aa58a73

Please sign in to comment.