Skip to content

Commit

Permalink
fixed configuration mod not applied when smapi installed manually
Browse files Browse the repository at this point in the history
  • Loading branch information
IDCs committed Jan 28, 2025
1 parent 7288ecd commit e065b9c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 26 deletions.
12 changes: 10 additions & 2 deletions game-stardewvalley/SMAPI.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions game-stardewvalley/SMAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { GAME_ID } from './common';
import { gte } from 'semver';
import { SMAPI_MOD_ID, SMAPI_URL } from './constants';

export function findSMAPITool(api: types.IExtensionApi): types.IDiscoveredTool | undefined {
const state = api.getState();
const discovery = selectors.discoveryByGame(state, GAME_ID);
const tool = discovery?.tools?.['smapi'];
return !!tool?.path ? tool : undefined;
}

export function findSMAPIMod(api: types.IExtensionApi): types.IMod {
const state = api.getState();
const profileId = selectors.lastActiveProfileForGame(state, GAME_ID);
Expand Down
33 changes: 22 additions & 11 deletions game-stardewvalley/configMod.js

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions game-stardewvalley/configMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setMergeConfigs } from './actions';
import { IFileEntry } from './types';
import { walkPath, defaultModsRelPath, deleteFolder } from './util';

import { findSMAPIMod } from './SMAPI';
import { findSMAPIMod, findSMAPITool } from './SMAPI';
import { IEntry } from 'turbowalk';

const syncWrapper = (api: types.IExtensionApi) => {
Expand All @@ -26,8 +26,12 @@ export function registerConfigMod(context: types.IExtensionContext) {
async function onSyncModConfigurations(api: types.IExtensionApi, silent?: boolean): Promise<void> {
const state = api.getState();
const profile = selectors.activeProfile(state);
const smapi = findSMAPIMod(api);
if (profile?.gameId !== GAME_ID || smapi === undefined) {
if (profile?.gameId !== GAME_ID) {
return;
}
const smapiTool: types.IDiscoveredTool = findSMAPITool(api);
if (!smapiTool?.path) {
api.showErrorNotification('SMAPI is not installed/configured', 'This feature requires Vortex to know the location of SMAPI. Please ensure that SMAPI is at least configured as a tool in Vortex.', { allowReport: false });
return;
}
const mergeConfigs = util.getSafe(state, ['settings', 'SDV', 'mergeConfigs', profile.id], false);
Expand Down Expand Up @@ -138,22 +142,24 @@ export async function addModConfig(api: types.IExtensionApi, files: IFileEntry[]
const discovery = selectors.discoveryByGame(state, GAME_ID);
const isInstallPath = modsPath !== undefined;
modsPath = modsPath ?? path.join(discovery.path, defaultModsRelPath());
const smapi = findSMAPIMod(api);
if (smapi === undefined) {
const smapiTool: types.IDiscoveredTool = findSMAPITool(api);
if (smapiTool === undefined) {
return;
}
const configModAttributes: string[] = extractConfigModAttributes(state, configMod.mod.id);
let newConfigAttributes = Array.from(new Set(configModAttributes));
for (const file of files) {
const segments = file.filePath.toLowerCase().split(path.sep).filter(seg => !!seg);
if (segments.includes('smapi_internal')) {
// Don't touch the internal SMAPI configuration files.
continue;
}
api.sendNotification({
type: 'activity',
id: NOTIF_ACTIVITY_CONFIG_MOD,
title: 'Importing config files...',
message: file.candidates[0],
});
if (file.candidates.includes(smapi?.installationPath)) {
continue;
}

if (!configModAttributes.includes(file.candidates[0])) {
newConfigAttributes.push(file.candidates[0]);
Expand Down Expand Up @@ -330,11 +336,19 @@ export async function onAddedFiles(api: types.IExtensionApi, profileId: string,
return;
}

const mods: { [modId: string]: types.IMod } = util.getSafe(state, ['persistent', 'mods', GAME_ID], {});
const isSMAPI = (file: IFileEntry) => file.candidates.find(candidate => mods[candidate].type === 'SMAPI') !== undefined;
const smapiTool: types.IDiscoveredTool = findSMAPITool(api);
if (smapiTool === undefined) {
// Very important not to add any files if Vortex has no knowledge of SMAPI's location.
// this is to avoid pulling SMAPI configuration files into one of the mods installed by Vortex.
return;
}
const isSMAPIFile = (file: IFileEntry) => {
const segments = file.filePath.toLowerCase().split(path.sep).filter(seg => !!seg);
return segments.includes('smapi_internal');
};
const mergeConfigs = util.getSafe(state, ['settings', 'SDV', 'mergeConfigs', profile.id], false);
const result = files.reduce((accum, file) => {
if (mergeConfigs && !isSMAPI(file) && path.basename(file.filePath).toLowerCase() === MOD_CONFIG) {
if (mergeConfigs && !isSMAPIFile(file) && path.basename(file.filePath).toLowerCase() === MOD_CONFIG) {
accum.configs.push(file);
} else {
accum.regulars.push(file);
Expand Down
2 changes: 1 addition & 1 deletion game-stardewvalley/info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Game: Stardew Valley",
"author": "Nexus Mods",
"version": "0.3.4",
"version": "0.3.5",
"description": "Support for Stardew Valley"
}
3 changes: 2 additions & 1 deletion game-stardewvalley/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions game-stardewvalley/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function walkPath(dirPath: string, walkOptions?: IWalkOptions): Pro
export async function deleteFolder(dirPath: string, walkOptions?: IWalkOptions): Promise<void> {
try {
const entries = await walkPath(dirPath, walkOptions);
entries.sort((a, b) => b.filePath.length - a.filePath.length);
for (const entry of entries) {
await fs.removeAsync(entry.filePath);
}
Expand Down

0 comments on commit e065b9c

Please sign in to comment.