From 3a6fa85aad073ef2e152135569f17f5c4665b8b5 Mon Sep 17 00:00:00 2001 From: Zefanja Jobse Date: Fri, 1 Dec 2023 21:30:23 +0100 Subject: [PATCH] add list of mods in marne servers --- src/api/ReturnTypes.tsx | 3 +- src/api/marneApi.tsx | 1 + .../routes/Servers/Detailed/Main.tsx | 65 +++++++++++++++++++ src/locales/languages/en-US.json | 7 ++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/api/ReturnTypes.tsx b/src/api/ReturnTypes.tsx index e9b0ad7..03c6e68 100644 --- a/src/api/ReturnTypes.tsx +++ b/src/api/ReturnTypes.tsx @@ -1,4 +1,5 @@ import { Mutator, PlaygroundMutator } from "./MutatorType"; +import { ModListReturn } from "./marneApi"; export type PlatoonPlayer = { id: string; @@ -434,7 +435,7 @@ export type DetailedServerInfo = { inQue?: number; maxPlayers?: number; noBotsPlayerAmount?: number; - + modList?: ModListReturn[]; // older games mapImage?: string; map?: string; diff --git a/src/api/marneApi.tsx b/src/api/marneApi.tsx index 767ad08..14eb3af 100644 --- a/src/api/marneApi.tsx +++ b/src/api/marneApi.tsx @@ -358,6 +358,7 @@ export class ApiProvider extends JsonClient { settings: result?.settings, description: result?.description, map: internalMapName, + modList: result?.modList || [], rotation: result?.rotation === "" ? [] diff --git a/src/components/routes/Servers/Detailed/Main.tsx b/src/components/routes/Servers/Detailed/Main.tsx index 29e4e0f..eb474aa 100644 --- a/src/components/routes/Servers/Detailed/Main.tsx +++ b/src/components/routes/Servers/Detailed/Main.tsx @@ -44,6 +44,7 @@ import { ServerGraphQuery } from "../../../graphing/line"; import { CopyToClipboard } from "../../../functions/CopyToClipboard"; import sslFix from "../../../functions/fixEaAssets"; import { capitalizeFirstLetter } from "../../../functions/capitalizeFirstLetter"; +import { ModListReturn } from "../../../../api/marneApi"; const AltDescription = styled.p` ${AltText} @@ -51,6 +52,12 @@ const AltDescription = styled.p` margin: 0.5rem 0.5rem 0.5rem 0; `; +const ModInfo = styled.p` + ${AltText} + margin: 0; + line-height: 1.2; +`; + interface IServerImage { background: string; } @@ -183,6 +190,19 @@ export function Results(props: Views): React.ReactElement { }); const { t, i18n } = useTranslation(); + const modCategories: { [id: string]: ModListReturn[] } = {}; + stats?.modList.forEach((item) => { + if (Object.keys(modCategories).includes(item?.category)) { + modCategories[item?.category].push(item); + } else { + modCategories[item?.category] = [item]; + } + }); + const sortedModCategories: { [id: string]: ModListReturn[] } = Object.keys( + modCategories, + ) + .sort((a, b) => modCategories[b].length - modCategories[a].length) + .reduce((acc, key) => ((acc[key] = modCategories[key]), acc), {}); if (error) { return ( @@ -530,6 +550,51 @@ export function Results(props: Views): React.ReactElement { )} + {props.game === "bf1marne" && ( + <> +

{t("servers.modList.main")}

+ {Object.keys(modCategories).length > 0 ? ( + + {Object.entries(sortedModCategories).map( + ([category, modList], index) => ( +
+

{category}

+ {modList.map((current, index) => ( +
+

+ {current?.name || t("notApplicable")} +

+ + {t("servers.modList.file")} + {current?.file_name || t("notApplicable")} + + + {t("servers.modList.version")} + {current?.version || t("notApplicable")} + + + {current?.link ? ( + + {current?.link} + + ) : ( + t("servers.modList.noURl") + )} + +
+ ))} +
+ ), + )} +
+ ) : ( + {t("servers.modList.noMods")} + )} + + )}

{t("servers.iframe.main")}

{t("servers.iframe.info")} diff --git a/src/locales/languages/en-US.json b/src/locales/languages/en-US.json index 5c38d15..cea9041 100644 --- a/src/locales/languages/en-US.json +++ b/src/locales/languages/en-US.json @@ -737,6 +737,13 @@ "10+": "10+", "empty": "Empty" } + }, + "modList": { + "main": "Mods", + "noMods": "This server has no mods", + "file": "file: ", + "version": "ver: ", + "noURl": "No link available" } }, "platoon": {