Skip to content

Commit

Permalink
add list of mods in marne servers
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Dec 1, 2023
1 parent 482c59d commit 3a6fa85
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/api/ReturnTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Mutator, PlaygroundMutator } from "./MutatorType";
import { ModListReturn } from "./marneApi";

export type PlatoonPlayer = {
id: string;
Expand Down Expand Up @@ -434,7 +435,7 @@ export type DetailedServerInfo = {
inQue?: number;
maxPlayers?: number;
noBotsPlayerAmount?: number;

modList?: ModListReturn[];
// older games
mapImage?: string;
map?: string;
Expand Down
1 change: 1 addition & 0 deletions src/api/marneApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export class ApiProvider extends JsonClient {
settings: result?.settings,
description: result?.description,
map: internalMapName,
modList: result?.modList || [],
rotation:
result?.rotation === ""
? []
Expand Down
65 changes: 65 additions & 0 deletions src/components/routes/Servers/Detailed/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ 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}
line-height: 1.2;
margin: 0.5rem 0.5rem 0.5rem 0;
`;

const ModInfo = styled.p`
${AltText}
margin: 0;
line-height: 1.2;
`;

interface IServerImage {
background: string;
}
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -530,6 +550,51 @@ export function Results(props: Views): React.ReactElement {
)}
</PageRow>
</PageColumn>
{props.game === "bf1marne" && (
<>
<h2 style={{ marginBottom: 0 }}>{t("servers.modList.main")}</h2>
{Object.keys(modCategories).length > 0 ? (
<AlignT>
{Object.entries(sortedModCategories).map(
([category, modList], index) => (
<div key={index} style={{ marginRight: "1rem" }}>
<h3>{category}</h3>
{modList.map((current, index) => (
<div key={index} style={{ marginBottom: "0.5rem" }}>
<h4 style={{ margin: 0, marginTop: "0.2rem" }}>
{current?.name || t("notApplicable")}
</h4>
<ModInfo>
{t("servers.modList.file")}
{current?.file_name || t("notApplicable")}
</ModInfo>
<ModInfo>
{t("servers.modList.version")}
{current?.version || t("notApplicable")}
</ModInfo>
<ModInfo>
{current?.link ? (
<a
href={current?.link}
style={{ color: "inherit" }}
>
{current?.link}
</a>
) : (
t("servers.modList.noURl")
)}
</ModInfo>
</div>
))}
</div>
),
)}
</AlignT>
) : (
<Description>{t("servers.modList.noMods")}</Description>
)}
</>
)}
<h2 style={{ marginBottom: 0 }}>{t("servers.iframe.main")}</h2>
<Description style={{ margin: 0, marginTop: "0.2rem" }}>
{t("servers.iframe.info")}
Expand Down
7 changes: 7 additions & 0 deletions src/locales/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 3a6fa85

Please sign in to comment.