Skip to content

Commit aa58a73

Browse files
authored
feat(funbox): add underscore_spaces funbox (@Spurkus) (monkeytypegame#6094)
1 parent 52fda9d commit aa58a73

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

frontend/src/styles/test.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ body.fb-nospace {
13381338
}
13391339
}
13401340

1341+
/* funbox underscore_spaces */
1342+
body.fb-underscore-spaces {
1343+
#words .word {
1344+
margin: 0.5em 0;
1345+
}
1346+
}
1347+
13411348
/* funbox arrows */
13421349
body.fb-arrows {
13431350
#words .word {

frontend/src/ts/pages/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ async function fillSettingsPage(): Promise<void> {
612612
/_/g,
613613
" "
614614
)}</div>`;
615+
} else if (funbox.name === "underscore_spaces") {
616+
// Display as "underscore_spaces". Does not replace underscores with spaces.
617+
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>`;
615618
} else {
616619
funboxElHTML += `<div class="funbox button" data-config-value='${
617620
funbox.name

frontend/src/ts/test/funbox/funbox-functions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type FunboxFunctions = {
2626
getWord?: (wordset?: Wordset, wordIndex?: number) => string;
2727
punctuateWord?: (word: string) => string;
2828
withWords?: (words?: string[]) => Promise<Wordset>;
29-
alterText?: (word: string) => string;
29+
alterText?: (word: string, wordIndex: number, wordsBound: number) => string;
3030
applyConfig?: () => void;
3131
applyGlobalCSS?: () => void;
3232
clearGlobal?: () => void;
@@ -584,6 +584,12 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
584584
return GetText.getMorse(word);
585585
},
586586
},
587+
underscore_spaces: {
588+
alterText(word: string, wordIndex: number, limit: number): string {
589+
if (wordIndex === limit - 1) return word; // don't add underscore to the last word
590+
return word + "_";
591+
},
592+
},
587593
crt: {
588594
applyGlobalCSS(): void {
589595
const isSafari = /^((?!chrome|android).)*safari/i.test(

frontend/src/ts/test/words-generator.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,14 @@ function getFunboxWord(
346346
return word;
347347
}
348348

349-
function applyFunboxesToWord(word: string): string {
349+
function applyFunboxesToWord(
350+
word: string,
351+
wordIndex: number,
352+
wordsBound: number
353+
): string {
350354
for (const fb of getActiveFunboxes()) {
351355
if (fb.functions?.alterText) {
352-
word = fb.functions.alterText(word);
356+
word = fb.functions.alterText(word, wordIndex, wordsBound);
353357
}
354358
}
355359
return word;
@@ -911,7 +915,7 @@ export async function getNextWord(
911915
}
912916
}
913917

914-
randomWord = applyFunboxesToWord(randomWord);
918+
randomWord = applyFunboxesToWord(randomWord, wordIndex, wordsBound);
915919

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

packages/funbox/src/list.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ const list: Record<FunboxName, FunboxMetadata> = {
406406
frontendFunctions: ["alterText"],
407407
name: "instant_messaging",
408408
},
409+
underscore_spaces: {
410+
description: "Underscores_are_better.",
411+
canGetPb: false,
412+
difficultyLevel: 0,
413+
properties: ["ignoresLanguage", "ignoresLayout", "nospace"],
414+
frontendFunctions: ["alterText"],
415+
name: "underscore_spaces",
416+
},
409417
ALL_CAPS: {
410418
description: "WHY ARE WE SHOUTING?",
411419
canGetPb: false,

packages/funbox/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type FunboxName =
3939
| "backwards"
4040
| "ddoouubblleedd"
4141
| "instant_messaging"
42+
| "underscore_spaces"
4243
| "ALL_CAPS";
4344

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

0 commit comments

Comments
 (0)