Skip to content

Commit

Permalink
Add installed mods list to Credits page
Browse files Browse the repository at this point in the history
  • Loading branch information
DJDavid98 committed Dec 17, 2023
1 parent f35184a commit 2480579
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/js/beat-saber/InstalledMods.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { FC, useMemo } from 'react';
import { useFailsafeWebsocket } from '../hooks/use-failsafe-websocket';
import { bsdpDataSource } from '../utils/constants';
import { validateBsdpModData } from '../validators/validate-bsdp-mod-data';
import { ExternalLink } from '../ExternalLink';
import * as styles from '../../scss/modules/InstalledMods.module.scss';
import { ReadyState } from 'react-use-websocket';
import { Loading } from '../Loading';

const simplifyLink = (href: string) => href.replace(/^https?:\/\//, '');

export const InstalledMods: FC = () => {
const {
message: modData,
readyState
} = useFailsafeWebsocket(`${bsdpDataSource}/ModData`, validateBsdpModData);

const enabledModes = modData?.EnabledPlugins;
const sortedModsList = useMemo(() => enabledModes?.slice().sort(({ Name: NameA },
{ Name: NameB }) => NameA.localeCompare(NameB)) ?? [], [enabledModes]);

let modsJsx: JSX.Element;
if (readyState === ReadyState.CONNECTING) {
modsJsx = <Loading name="connection" />;
} else if (sortedModsList.length === 0) {
modsJsx = <p>Installed mods could not be loaded.</p>;
} else {
modsJsx =
<ul>
{sortedModsList.map((mod) => <li key={mod.Name}>
<h4 className={styles['mod-title']}>
<span className={styles['mod-name']}>{mod.Name}</span>
{' '}<span className={styles['mod-version']}>v{mod.Version}</span>
</h4>
{mod.Author && <p className={styles['mod-info']}>Developed by: {mod.Author}</p>}
{mod.HomeLink && <p className={styles['mod-info']}>
Home
page: <ExternalLink href={mod.HomeLink}>{simplifyLink(mod.HomeLink)}</ExternalLink>
</p>}
{mod.SourceLink && <p className={styles['mod-info']}>
Source
code: <ExternalLink href={mod.SourceLink}>{simplifyLink(mod.SourceLink)}</ExternalLink>
</p>}
{mod.DonateLink && <p className={styles['mod-info']}>
Donations: <ExternalLink href={mod.DonateLink}>{simplifyLink(mod.DonateLink)}</ExternalLink>
</p>}
</li>)}
</ul>;
}

return <div className={styles['installed-mods']}>
<h3>Installed Mods</h3>
{modsJsx}
</div>;
};
14 changes: 14 additions & 0 deletions src/js/model/bsdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ export interface BsdpMapData {
CoverImage: string | null;
Modifiers: BsdpModifiers;
}

export interface BsdpModData {
EnabledPlugins: BsdpPluginMetadata[];
}

export interface BsdpPluginMetadata {
Name: string;
Version: string;
Author: string;
Description: string;
HomeLink: string;
SourceLink: string;
DonateLink: string;
}
3 changes: 3 additions & 0 deletions src/js/settings/pages/SettingsPageCredits.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC } from 'react';
import { ExternalLink } from '../../ExternalLink';
import { InstalledMods } from '../../beat-saber/InstalledMods';

const bluetoothLogoLink = 'https://commons.wikimedia.org/wiki/File:Bluetooth.svg';

Expand Down Expand Up @@ -39,5 +40,7 @@ export const SettingsPageCredits: FC = () => {
<ExternalLink href="https://www.twitch.tv/minniefoxx">MinnieFoxx</ExternalLink>
</li>
</ul>

<InstalledMods />
</>;
};
17 changes: 17 additions & 0 deletions src/js/validators/validate-bsdp-mod-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Joi from 'joi';
import { dataValidatorFactory } from '../utils/data-validator-factory';
import { BsdpModData, BsdpPluginMetadata } from '../model/bsdp';

const schema = Joi.object<BsdpModData>({
EnabledPlugins: Joi.array<BsdpPluginMetadata[]>().items({
Name: Joi.string().allow(''),
Version: Joi.string().allow(''),
Author: Joi.string().allow(''),
Description: Joi.string().allow(''),
HomeLink: Joi.string().allow(''),
SourceLink: Joi.string().allow(''),
DonateLink: Joi.string().allow(''),
}),
});

export const validateBsdpModData = dataValidatorFactory(schema);
38 changes: 38 additions & 0 deletions src/scss/modules/InstalledMods.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.installed-mods {
.mod-title {
font-size: 1em;
font-weight: bold;
margin: 0 0 .25em;

.mod-name {
font-size: 1em;
}

.mod-version {
font-size: .8em;
}
}

.mod-info {
font-size: .8em;
}

ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
width: 100%;
flex-flow: row wrap;
text-align: center;
gap: .75em;
justify-content: space-around;

li {
box-sizing: border-box;
padding: .5em;
border: .125em solid;
border-radius: .3em;
}
}
}
2 changes: 2 additions & 0 deletions src/scss/modules/SettingsDialog.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
width: 0;

.close-button {
position: absolute;
border: 0;
padding: .25em;
margin: 0;
Expand Down Expand Up @@ -61,6 +62,7 @@
overflow: auto;
flex: 1 1 auto;
padding-right: 1em;
box-sizing: border-box;
}

.settings-header {
Expand Down

0 comments on commit 2480579

Please sign in to comment.