Skip to content

Commit

Permalink
fix for load order handling of imported mods (from Share Mods)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazbot committed Nov 13, 2023
1 parent 1845080 commit 50c8dd7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
31 changes: 24 additions & 7 deletions src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ const appSlice = createSlice({
console.log("ordering imported mods");
for (let i = 0; i < state.importedMods.length; i++) {
const importedMod = state.importedMods[i];
if (importedMod.loadOrder != undefined) {
const currentMod = state.currentPreset.mods.find(
(mod) => mod.workshopId == state.importedMods[i].workshopId
);
if (!currentMod) continue;
console.log("imported mod:", importedMod.workshopId, importedMod.loadOrder);

const currentMod = state.currentPreset.mods.find(
(mod) => mod.workshopId == state.importedMods[i].workshopId
);
if (!currentMod) continue;

if (importedMod.loadOrder == undefined) {
const currentModIndex = currentMod && state.currentPreset.mods.indexOf(currentMod);
if (currentModIndex == -1) continue;

Expand All @@ -110,9 +112,15 @@ const appSlice = createSlice({
if (previousSiblingModIndex != -1) {
// put the mod with the load order after the previous sibling
state.currentPreset.mods.splice(currentModIndex, 1);
state.currentPreset.mods.splice(0, 0, currentMod);
state.currentPreset.mods.splice(previousSiblingModIndex, 0, currentMod);
}
}
} else {
const currentModIndex = currentMod && state.currentPreset.mods.indexOf(currentMod);
if (currentModIndex == -1) continue;
state.currentPreset.mods.splice(currentModIndex, 1);
state.currentPreset.mods.splice(importedMod.loadOrder, 0, currentMod);
currentMod.loadOrder = importedMod.loadOrder;
}
}

Expand Down Expand Up @@ -207,7 +215,16 @@ const appSlice = createSlice({

const alreadyExistsByName = state.currentPreset.mods.find((iterMod) => iterMod.name === mod.name);
if (!alreadyExistsByName) {
state.currentPreset.mods.push(mod);
for (const iterMod of state.currentPreset.mods.filter((mod) => mod.loadOrder == undefined)) {
if (compareModNames(mod.name, iterMod.name) < 1) {
state.currentPreset.mods.splice(state.currentPreset.mods.indexOf(mod), 1);
state.currentPreset.mods.splice(state.currentPreset.mods.indexOf(iterMod), 0, mod);
break;
}
}

// if we couldn't find a place for it
if (!state.currentPreset.mods.find((iterMod) => iterMod == mod)) state.currentPreset.mods.push(mod);
} else if (mod.isInData) {
const previousIndex = state.currentPreset.mods.indexOf(alreadyExistsByName);
state.currentPreset.mods.splice(previousIndex, 1, mod);
Expand Down
3 changes: 2 additions & 1 deletion src/components/ShareMods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const ShareMods = memo((props: ShareModsProps) => {
return { workshopId: idAndOrder, loadOrder: undefined };
});

console.log("imported mods:", imported);
dispatch(setImportedMods(imported));

const onlyIds = imported.map((idAndOrder) => idAndOrder.workshopId);
Expand Down Expand Up @@ -89,7 +90,7 @@ const ShareMods = memo((props: ShareModsProps) => {
dispatch(setSharedMod(newMods));
}, 100);
return () => clearInterval(interval);
}, [subbedModIdsToWaitFor, mods]);
}, [importedMods, subbedModIdsToWaitFor, mods]);

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ if (!gotTheLock) {
try {
if (!mainWindow) return;
const dialogReturnValue = await dialog.showOpenDialog(mainWindow, {
properties: ["openDirectory"],
properties: ["openDirectory", "showHiddenFiles"],
});

if (!dialogReturnValue.canceled) {
Expand All @@ -716,7 +716,7 @@ if (!gotTheLock) {
try {
if (!mainWindow) return;
const dialogReturnValue = await dialog.showOpenDialog(mainWindow, {
properties: ["openDirectory"],
properties: ["openDirectory", "showHiddenFiles"],
});

if (!dialogReturnValue.canceled) {
Expand Down

0 comments on commit 50c8dd7

Please sign in to comment.