diff --git a/backend/src/constants/funbox-list.ts b/backend/src/constants/funbox-list.ts new file mode 100644 index 000000000..5debcaff3 --- /dev/null +++ b/backend/src/constants/funbox-list.ts @@ -0,0 +1,312 @@ +const FunboxList: MonkeyTypes.FunboxMetadata[] = [ + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "ignoresLayout", "noLetters"], + frontendForcedConfig: { + numbers: [false], + }, + frontendFunctions: [ + "getWord", + "punctuateWord", + "rememberSettings", + "handleChar", + ], + name: "58008", + }, + { + canGetPb: true, + difficultyLevel: 2, + frontendFunctions: ["applyCSS"], + name: "nausea", + }, + { + canGetPb: true, + difficultyLevel: 3, + frontendFunctions: ["applyCSS"], + name: "round_round_baby", + }, + { + canGetPb: true, + difficultyLevel: 1, + properties: ["changesWordsVisibility", "usesLayout"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: ["applyCSS", "applyConfig", "rememberSettings"], + name: "simon_says", + }, + { + canGetPb: true, + difficultyLevel: 3, + frontendFunctions: ["applyCSS"], + name: "mirror", + }, + { + canGetPb: true, + difficultyLevel: 3, + frontendFunctions: ["applyCSS"], + name: "upside_down", + }, + { + canGetPb: true, + difficultyLevel: 1, + properties: ["changesWordsVisibility", "speaks"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: [ + "applyCSS", + "applyConfig", + "rememberSettings", + "toggleScript", + ], + name: "tts", + }, + { + canGetPb: true, + difficultyLevel: 2, + properties: ["noLigatures", "conflictsWithSymmetricChars"], + frontendFunctions: ["applyCSS"], + name: "choo_choo", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: [ + "ignoresLanguage", + "ignoresLayout", + "nospace", + "noLetters", + "symmetricChars", + ], + frontendForcedConfig: { + punctuation: [false], + numbers: [false], + highlightMode: ["letter", "off"], + }, + frontendFunctions: [ + "getWord", + "applyConfig", + "rememberSettings", + "handleChar", + "isCharCorrect", + "preventDefaultEvent", + "getWordHtml", + ], + name: "arrows", + }, + { + canGetPb: false, + difficultyLevel: 2, + properties: ["changesCapitalisation"], + frontendFunctions: ["alterText"], + name: "rAnDoMcAsE", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["changesCapitalisation"], + frontendFunctions: ["alterText"], + name: "capitals", + }, + { + canGetPb: true, + difficultyLevel: 1, + properties: ["changesLayout", "noInfiniteDuration"], + frontendFunctions: [ + "applyConfig", + "rememberSettings", + "handleSpace", + "getResultContent", + "restart", + ], + name: "layoutfluid", + }, + { + canGetPb: true, + difficultyLevel: 1, + properties: ["noLigatures"], + frontendFunctions: ["applyCSS"], + name: "earthquake", + }, + { + canGetPb: true, + difficultyLevel: 0, + frontendFunctions: ["applyCSS"], + name: "space_balls", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "unspeakable"], + frontendFunctions: ["getWord"], + name: "gibberish", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "noLetters", "unspeakable"], + frontendForcedConfig: { + punctuation: [false], + numbers: [false], + }, + frontendFunctions: ["getWord"], + name: "ascii", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "noLetters", "unspeakable"], + frontendForcedConfig: { + punctuation: [false], + numbers: [false], + }, + frontendFunctions: ["getWord"], + name: "specials", + }, + { + canGetPb: true, + difficultyLevel: 0, + properties: ["changesWordsVisibility", "toPush:2", "noInfiniteDuration"], + name: "plus_one", + }, + { + canGetPb: true, + difficultyLevel: 0, + properties: ["changesWordsVisibility", "toPush:3", "noInfiniteDuration"], + name: "plus_two", + }, + { + canGetPb: true, + difficultyLevel: 0, + properties: ["changesWordsVisibility", "toPush:4", "noInfiniteDuration"], + name: "plus_three", + }, + { + canGetPb: true, + difficultyLevel: 1, + properties: ["changesWordsVisibility"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: ["applyCSS", "rememberSettings"], + name: "read_ahead_easy", + }, + { + canGetPb: true, + difficultyLevel: 2, + properties: ["changesWordsVisibility"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: ["applyCSS", "rememberSettings"], + name: "read_ahead", + }, + { + canGetPb: true, + difficultyLevel: 3, + properties: ["changesWordsVisibility"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: ["applyCSS", "rememberSettings"], + name: "read_ahead_hard", + }, + { + canGetPb: true, + difficultyLevel: 3, + properties: ["changesWordsVisibility", "noInfiniteDuration"], + frontendForcedConfig: { + mode: ["words", "quote", "custom"], + }, + frontendFunctions: ["applyConfig", "rememberSettings", "start", "restart"], + name: "memory", + }, + { + canGetPb: false, + difficultyLevel: 0, + properties: ["nospace"], + frontendForcedConfig: { + highlightMode: ["letter", "off"], + }, + frontendFunctions: ["applyConfig", "rememberSettings"], + name: "nospace", + }, + { + canGetPb: false, + difficultyLevel: 0, + properties: ["noInfiniteDuration", "ignoresLanguage"], + frontendForcedConfig: { + punctuation: [false], + numbers: [false], + }, + frontendFunctions: ["pullSection"], + name: "poetry", + }, + { + canGetPb: false, + difficultyLevel: 0, + properties: ["noInfiniteDuration", "ignoresLanguage"], + frontendForcedConfig: { + punctuation: [false], + numbers: [false], + }, + frontendFunctions: ["pullSection"], + name: "wikipedia", + }, + { + canGetPb: false, + difficultyLevel: 0, + properties: ["changesWordsFrequency"], + frontendFunctions: ["getWord"], + name: "weakspot", + }, + { + canGetPb: false, + difficultyLevel: 0, + properties: ["unspeakable", "ignoresLanguage"], + frontendFunctions: ["withWords"], + name: "pseudolang", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "ignoresLayout", "noLetters"], + frontendForcedConfig: { + numbers: [false], + }, + frontendFunctions: ["getWord", "punctuateWord", "rememberSettings"], + name: "IPv4", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "ignoresLayout", "noLetters"], + frontendForcedConfig: { + numbers: [false], + }, + frontendFunctions: ["getWord", "punctuateWord", "rememberSettings"], + name: "IPv6", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["ignoresLanguage", "ignoresLayout", "noLetters"], + frontendForcedConfig: { + numbers: [false], + punctuation: [false], + }, + frontendFunctions: ["getWord"], + name: "binary", + }, + { + canGetPb: false, + difficultyLevel: 1, + properties: ["changesWordsFrequency"], + frontendFunctions: ["getWordsFrequencyMode"], + name: "zipf", + }, +]; + +export default FunboxList; diff --git a/backend/src/constants/funbox.ts b/backend/src/constants/funbox.ts deleted file mode 100644 index 88b1e9948..000000000 --- a/backend/src/constants/funbox.ts +++ /dev/null @@ -1,136 +0,0 @@ -const Funboxes: Record = { - nausea: { - canGetPb: true, - difficultyLevel: 2, - }, - round_round_baby: { - canGetPb: true, - difficultyLevel: 3, - }, - simon_says: { - canGetPb: true, - difficultyLevel: 1, - }, - mirror: { - canGetPb: true, - difficultyLevel: 3, - }, - upside_down: { - canGetPb: true, - difficultyLevel: 3, - }, - tts: { - canGetPb: true, - difficultyLevel: 1, - }, - choo_choo: { - canGetPb: true, - difficultyLevel: 2, - }, - arrows: { - canGetPb: false, - difficultyLevel: 1, - }, - rAnDoMcAsE: { - canGetPb: false, - difficultyLevel: 2, - }, - capitals: { - canGetPb: false, - difficultyLevel: 1, - }, - layoutfluid: { - canGetPb: true, - difficultyLevel: 1, - }, - earthquake: { - canGetPb: true, - difficultyLevel: 1, - }, - space_balls: { - canGetPb: true, - difficultyLevel: 0, - }, - gibberish: { - canGetPb: false, - difficultyLevel: 1, - }, - "58008": { - canGetPb: false, - difficultyLevel: 1, - }, - ascii: { - canGetPb: false, - difficultyLevel: 1, - }, - specials: { - canGetPb: false, - difficultyLevel: 1, - }, - plus_one: { - canGetPb: true, - difficultyLevel: 0, - }, - plus_two: { - canGetPb: true, - difficultyLevel: 0, - }, - plus_three: { - canGetPb: true, - difficultyLevel: 0, - }, - read_ahead_easy: { - canGetPb: true, - difficultyLevel: 1, - }, - read_ahead: { - canGetPb: true, - difficultyLevel: 2, - }, - read_ahead_hard: { - canGetPb: true, - difficultyLevel: 3, - }, - memory: { - canGetPb: true, - difficultyLevel: 3, - }, - nospace: { - canGetPb: false, - difficultyLevel: 0, - }, - poetry: { - canGetPb: false, - difficultyLevel: 0, - }, - wikipedia: { - canGetPb: false, - difficultyLevel: 0, - }, - weakspot: { - canGetPb: false, - difficultyLevel: 0, - }, - pseudolang: { - canGetPb: false, - difficultyLevel: 0, - }, - IPv4: { - canGetPb: false, - difficultyLevel: 1, - }, - IPv6: { - canGetPb: false, - difficultyLevel: 1, - }, - binary: { - canGetPb: false, - difficultyLevel: 1, - }, - zipf: { - canGetPb: false, - difficultyLevel: 1, - }, -}; - -export default Funboxes; diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts index c603d2bdb..3d52e27bd 100644 --- a/backend/src/types/types.d.ts +++ b/backend/src/types/types.d.ts @@ -475,7 +475,11 @@ declare namespace MonkeyTypes { } interface FunboxMetadata { + name: string; canGetPb: boolean; difficultyLevel: number; + properties?: string[]; + frontendForcedConfig?: Record; + frontendFunctions?: string[]; } } diff --git a/backend/src/utils/misc.ts b/backend/src/utils/misc.ts index a27ad1647..936db64d0 100644 --- a/backend/src/utils/misc.ts +++ b/backend/src/utils/misc.ts @@ -270,3 +270,12 @@ export function formatSeconds( return `${normalized} ${unit}${normalized > 1 ? "s" : ""}`; } + +export function intersect(a: T[], b: T[], removeDuplicates = false): T[] { + let t; + if (b.length > a.length) (t = b), (b = a), (a = t); // indexOf to loop over shorter + const filtered = a.filter(function (e) { + return b.indexOf(e) > -1; + }); + return removeDuplicates ? [...new Set(filtered)] : filtered; +} diff --git a/backend/src/utils/pb.ts b/backend/src/utils/pb.ts index 3446162e1..92649c572 100644 --- a/backend/src/utils/pb.ts +++ b/backend/src/utils/pb.ts @@ -1,5 +1,5 @@ import _ from "lodash"; -import FunboxesMetadata from "../constants/funbox"; +import FunboxesMetadata from "../constants/funbox-list"; interface CheckAndUpdatePbResult { isPb: boolean;