Skip to content

Commit

Permalink
Added detection of additionally installed mods via Steam
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Apr 25, 2024
1 parent ad9a6ea commit a5af979
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"xml2js": "^0.5.0"
},
"dependencies": {
"@butr/vortexextensionnative": "1.0.103",
"@butr/vortexextensionnative": "1.0.108",
"ticks-to-date": "^1.0.3"
},
"resolutions": {
Expand Down
23 changes: 19 additions & 4 deletions src/utils/loadOrder/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class LoadOrderManager implements types.IFBLOGameInfo {
private _api: types.IExtensionApi;
private _manager: VortexLauncherManager;
private _isInitialized = false;
private _allModules: vetypes.ModuleInfoExtendedWithMetadata[] = [];

public gameId: string = GAME_ID;
public toggleableEntries = true;
Expand All @@ -26,11 +27,24 @@ export class LoadOrderManager implements types.IFBLOGameInfo {
constructor(api: types.IExtensionApi, manager: VortexLauncherManager) {
this._api = api;
this._manager = manager;
this.customItemRenderer = ({ className = '', item }) => (
<BannerlordItemRenderer api={api} item={item} className={className} key={item.loEntry.id} />
);
const refresh = () => this.forceRefresh();
this.usageInstructions = () => <LoadOrderInfoPanel refresh={refresh} />;

this.customItemRenderer = ({ className = '', item }) => {
const availableProviders = this._allModules
.filter((x) => x.id === item.loEntry.id)
.map((x) => x.moduleProviderType);

return (
<BannerlordItemRenderer
api={api}
item={item}
className={className}
key={item.loEntry.id}
availableProviders={availableProviders}
/>
);
};
const refresh = () => this.forceRefresh();
}

private forceRefresh = (): void => {
Expand Down Expand Up @@ -116,6 +130,7 @@ export class LoadOrderManager implements types.IFBLOGameInfo {

// Make sure the LauncherManager has the latest module list
this._manager.refreshModules();
this._allModules = this._manager.getAllModulesWithDuplicates();

// Get the saved Load Order
const allModules = this._manager.getAllModules();
Expand Down
8 changes: 8 additions & 0 deletions src/utils/vortexLauncherManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export class VortexLauncherManager {
}, {});
};

/**
* Gets all modules with duplicates - when installed in /Modules and Steam Workshop
* @return
*/
public getAllModulesWithDuplicates = (): vetypes.ModuleInfoExtendedWithMetadata[] => {
return this._launcherManager.getAllModules();
};

/**
* Will sort the available Modules based on the provided LoadOrder
* @param loadOrder
Expand Down
30 changes: 27 additions & 3 deletions src/views/LoadOrderItemRenderer/LoadOrderItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { actions, Icon, selectors, tooltip, types, util } from 'vortex-api';
import { IVortexViewModelData } from '../../types';
import { versionToString } from '../../utils';
import { MODULE_LOGO, STEAM_LOGO, TW_LOGO } from '../../common';
import { Utils } from '@butr/vortexextensionnative';
import { types as vetypes, Utils } from '@butr/vortexextensionnative';
import { TooltipImage } from '../Controls';

interface IBaseProps {
api: types.IExtensionApi;
className?: string;
item: types.IFBLOItemRendererProps;
availableProviders: vetypes.ModuleProviderType[];
}

interface IConnectedProps {
Expand Down Expand Up @@ -72,14 +73,15 @@ export function BannerlordItemRenderer(props: IBaseProps): JSX.Element {
{renderModuleIcon(item.loEntry)}
<p className="load-order-name">{name} ({version})</p>
{renderExternalBanner(item.loEntry)}
{renderModuleDuplicates(props, item.loEntry)}
{renderModuleProviderIcon(item.loEntry)}
{checkBox()}
{lock()}
</ListGroupItem>
);
}

function renderModuleIcon(item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): JSX.Element | null {
function renderModuleIcon(item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): JSX.Element {
const isOfficial = item.data !== undefined && item.data.moduleInfoExtended.isOfficial;
const isCommunity = item.data !== undefined && !item.data.moduleInfoExtended.isOfficial;
const dependencies = item.data !== undefined ? Utils.getDependencyHint(item.data.moduleInfoExtended) : '';
Expand Down Expand Up @@ -136,7 +138,7 @@ function renderExternalBanner(item: types.IFBLOLoadOrderEntry<IVortexViewModelDa
) : null;
}

function renderModuleProviderIcon(item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): JSX.Element | null {
function renderModuleProviderIcon(item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): JSX.Element {
const [t] = useTranslation(['common']);

if (isSteamWorksop(item)) {
Expand All @@ -154,6 +156,28 @@ function renderModuleProviderIcon(item: types.IFBLOLoadOrderEntry<IVortexViewMod
);
}

function renderModuleDuplicates(props: IBaseProps, item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): JSX.Element | null {
const { availableProviders } = props;

if (availableProviders.length <= 1) {
return <div style={{ width: `1.5em`, height: `1.5em`, }} />;
}

if (item.data?.moduleInfoExtended.moduleProviderType) {
const redundantProviders = availableProviders.filter((provider) => provider !== item.data?.moduleInfoExtended.moduleProviderType);
return (
<tooltip.Icon
className="nexus-id-invalid"
name="feedback-warning"
style={{ width: `1.5em`, height: `1.5em`, }}
tooltip={`The mod is also installed via ${redundantProviders.join(', ')}!`}>
</tooltip.Icon>
);
}

return <div style={{ width: `1.5em`, height: `1.5em`, }} />;
}

function isLocked(item: types.IFBLOLoadOrderEntry<IVortexViewModelData>): boolean {
return [true, 'true', 'always'].includes(item.locked as types.FBLOLockState);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
dependencies:
regenerator-runtime "^0.14.0"

"@butr/vortexextensionnative@1.0.103":
version "1.0.103"
resolved "https://registry.yarnpkg.com/@butr/vortexextensionnative/-/vortexextensionnative-1.0.103.tgz#ca468ec5dbc838ad748cd55a249afa7428120e39"
integrity sha512-Gl/ENuWbKJdWZjRYyKPRb2dcFuPOgMBqH8R6/SEkRZpxJEVZy/N3PS+W3z5KBM1m1hEkuxrCGmAjmrnYEnJ6CA==
"@butr/vortexextensionnative@1.0.108":
version "1.0.108"
resolved "https://registry.yarnpkg.com/@butr/vortexextensionnative/-/vortexextensionnative-1.0.108.tgz#6f0cb83657d91ddb789b390fb4bf0c7dbb4d819b"
integrity sha512-cO/+X/68LhCHPfNb2hObUo6rpoRMVpqnYLsg+IOrBoT602nAVoaI8Hooreqd5rBR61gm+OVzebrUeqSs2ZL4ug==

"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
Expand Down

0 comments on commit a5af979

Please sign in to comment.