added morse code to the funbox (#4451) epicjoanna

* added morse code mode to funbox

* actioned changes
This commit is contained in:
joanna 2023-07-17 12:41:04 +01:00 committed by GitHub
parent 06ca56bfc8
commit 6d88c4f4e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 0 deletions

View file

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

View file

@ -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[] {

View file

@ -723,3 +723,9 @@ export async function rememberSettings(): Promise<void> {
if (funbox.functions?.rememberSettings) funbox.functions.rememberSettings();
});
}
FunboxList.setFunboxFunctions("morse", {
alterText(word: string): string {
return Misc.convertToMorse(word);
},
});

View file

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

View file

@ -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
}
]