-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add installed mods list to Credits page
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters