From 6d88c4f4e325fc89eba64bda3b4f78dd8d410e74 Mon Sep 17 00:00:00 2001 From: joanna <127295327+epicjoanna@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:41:04 +0100 Subject: [PATCH] added morse code to the funbox (#4451) epicjoanna * added morse code mode to funbox * actioned changes --- backend/src/constants/funbox-list.ts | 7 +++ frontend/src/ts/test/funbox/funbox-list.ts | 5 ++ frontend/src/ts/test/funbox/funbox.ts | 6 ++ frontend/src/ts/utils/misc.ts | 66 ++++++++++++++++++++++ frontend/static/funbox/_list.json | 5 ++ 5 files changed, 89 insertions(+) diff --git a/backend/src/constants/funbox-list.ts b/backend/src/constants/funbox-list.ts index 5debcaff3..eb0479687 100644 --- a/backend/src/constants/funbox-list.ts +++ b/backend/src/constants/funbox-list.ts @@ -307,6 +307,13 @@ const FunboxList: MonkeyTypes.FunboxMetadata[] = [ frontendFunctions: ["getWordsFrequencyMode"], name: "zipf", }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "ignoresLayout", "noLetters", "noSpace"], + frontendFunctions: ["alterText"], + name: "morse", + }, ]; export default FunboxList; diff --git a/frontend/src/ts/test/funbox/funbox-list.ts b/frontend/src/ts/test/funbox/funbox-list.ts index c0b5c8301..866dca361 100644 --- a/frontend/src/ts/test/funbox/funbox-list.ts +++ b/frontend/src/ts/test/funbox/funbox-list.ts @@ -224,6 +224,11 @@ const list: MonkeyTypes.FunboxMetadata[] = [ info: "Words are generated according to Zipf's law. (not all languages will produce Zipfy results, use with caution)", properties: ["changesWordsFrequency"], }, + { + name: "morse", + info: "-.../././.--./ -.../---/---/.--./-.-.--/ ", + properties: ["ignoresLanguage", "ignoresLayout", "noLetters", "nospace"], + }, ]; export function getAll(): MonkeyTypes.FunboxMetadata[] { diff --git a/frontend/src/ts/test/funbox/funbox.ts b/frontend/src/ts/test/funbox/funbox.ts index 2777ff5e1..1fe00cb86 100644 --- a/frontend/src/ts/test/funbox/funbox.ts +++ b/frontend/src/ts/test/funbox/funbox.ts @@ -723,3 +723,9 @@ export async function rememberSettings(): Promise { if (funbox.functions?.rememberSettings) funbox.functions.rememberSettings(); }); } + +FunboxList.setFunboxFunctions("morse", { + alterText(word: string): string { + return Misc.convertToMorse(word); + }, +}); diff --git a/frontend/src/ts/utils/misc.ts b/frontend/src/ts/utils/misc.ts index 8c495f746..c5fa68019 100644 --- a/frontend/src/ts/utils/misc.ts +++ b/frontend/src/ts/utils/misc.ts @@ -1539,3 +1539,69 @@ export function isToday(timestamp: number): boolean { return today === date; } + +export function convertToMorse(word: string): string { + const morseCode: { [id: string]: string } = { + a: ".-", + b: "-...", + c: "-.-.", + d: "-..", + e: ".", + f: "..-.", + g: "--.", + h: "....", + i: "..", + j: ".---", + k: "-.-", + l: ".-..", + m: "--", + n: "-.", + o: "---", + p: ".--.", + q: "--.-", + r: ".-.", + s: "...", + t: "-", + u: "..-", + v: "...-", + w: ".--", + x: "-..-", + y: "-.--", + z: "--..", + "0": "-----", + "1": ".----", + "2": "..---", + "3": "...--", + "4": "....-", + "5": ".....", + "6": "-....", + "7": "--...", + "8": "---..", + "9": "----.", + ".": ".-.-.-", + ",": "--..--", + "?": "..--..", + "'": ".----.", + "/": "-..-.", + "(": "-.--.", + ")": "-.--.-", + "&": ".-...", + ":": "---...", + ";": "-.-.-.", + "=": "-...-", + "+": ".-.-.", + "-": "-....-", + _: "..--.-", + '"': ".-..-.", + $: "...-..-", + "!": "-.-.--", + "@": ".--.-.", + }; + + let morseWord = ""; + + for (let i = 0; i < word.length; i++) { + morseWord += morseCode[word.toLowerCase()[i]] + "/"; + } + return morseWord; +} diff --git a/frontend/static/funbox/_list.json b/frontend/static/funbox/_list.json index b974db04c..3c30446c4 100644 --- a/frontend/static/funbox/_list.json +++ b/frontend/static/funbox/_list.json @@ -165,5 +165,10 @@ "name": "zipf", "info": "Words are generated according to Zipf's law. (not all languages will produce Zipfy results, use with caution)", "canGetPb": false + }, + { + "name": "morse", + "info": "-.../././.--./ -.../---/---/.--./-.-.--/ ", + "canGetPb": false } ]