Skip to content

Commit 3302847

Browse files
committed
Better handling of the "multiple versions of the same mod are installed" case
1 parent 2cd5053 commit 3302847

File tree

2 files changed

+60
-33
lines changed

2 files changed

+60
-33
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ and only contains the latest changes.
33
Its purpose is to be shown in Olympus when updating.
44

55
#changelog#
6-
Fixed crash of Manage Installed Mods when a mod with no everest.yaml is present
6+
Better handling of the "multiple versions of the same mod are installed" case

src/scenes/modlist.lua

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local scene = {
1313
name = "Mod Manager",
1414
-- the list of displayed mods, in the order they are displayed (mod object = { info = modinfo, row = uirow, visible = bool })
1515
modlist = {},
16-
-- mod name -> mod object
16+
-- mod name -> list[mod object]
1717
modsByName = {},
1818
-- mod path -> mod object
1919
modsByPath = {},
@@ -183,16 +183,26 @@ local function getLabelTextFor(info)
183183
if info.IsFavorite then
184184
color = themeColors.favoriteColor
185185
else
186+
local isDependencyOfFavorite = false
187+
local isDependency = false
188+
186189
for _, dep in ipairs(scene.modDependents[info.Name] or {}) do
187190
if scene.modsByName[dep] then
188-
if scene.modsByName[dep].info.IsFavorite then
189-
color = themeColors.dependencyOfFavoriteColor
190-
break
191-
elseif not scene.modsByName[dep].info.IsBlacklisted then
192-
color = themeColors.dependencyColor
191+
for _, mod in pairs(scene.modsByName[dep]) do
192+
if mod.info.IsFavorite then
193+
isDependencyOfFavorite = true
194+
elseif not mod.info.IsBlacklisted then
195+
isDependency = true
196+
end
193197
end
194198
end
195199
end
200+
201+
if isDependencyOfFavorite then
202+
color = themeColors.dependencyOfFavoriteColor
203+
elseif isDependency then
204+
color = themeColors.dependencyColor
205+
end
196206
end
197207

198208
color = {color[1], color[2], color[3], info.IsBlacklisted and 0.5 or 1}
@@ -244,12 +254,18 @@ local function findDependenciesToEnable(mod)
244254

245255
while #queue > 0 do
246256
local depName = table.remove(queue, 1)
247-
local dep = scene.modsByName[depName]
248-
if dep then
249-
if dep.info.IsBlacklisted and not dependenciesToEnable[depName] then
250-
dependenciesToEnable[depName] = dep
257+
local depOptions = scene.modsByName[depName]
258+
if depOptions then
259+
local disabled = true
260+
for _, dep in pairs(depOptions) do
261+
if not dep.info.IsBlacklisted then
262+
disabled = false
263+
end
264+
end
265+
if disabled and not dependenciesToEnable[depName] then
266+
dependenciesToEnable[depName] = depOptions[1] -- can't really take an informed decision there...
251267
end
252-
for _, subdep in ipairs(scene.modDependencies[dep.info.Name] or {}) do
268+
for _, subdep in ipairs(scene.modDependencies[depName] or {}) do
253269
if not tried[subdep] then
254270
tried[subdep] = true
255271
table.insert(queue, subdep)
@@ -267,9 +283,11 @@ end
267283

268284
local function updateLabelTextForDependencies(mod)
269285
for _, depName in ipairs(scene.modDependencies[mod.info.Name] or {}) do
270-
local dep = scene.modsByName[depName]
271-
if dep then
272-
updateLabelTextForMod(dep)
286+
local depOptions = scene.modsByName[depName]
287+
if depOptions then
288+
for _, dep in pairs(depOptions) do
289+
updateLabelTextForMod(dep)
290+
end
273291
end
274292
end
275293
end
@@ -288,9 +306,11 @@ end
288306

289307
local function updateWarningButtonForDependents(mod)
290308
for _, depName in ipairs(scene.modDependents[mod.info.Name] or {}) do
291-
local dep = scene.modsByName[depName]
292-
if dep then
293-
updateWarningButtonForMod(dep)
309+
local depOptions = scene.modsByName[depName]
310+
if depOptions then
311+
for _, dep in pairs(depOptions) do
312+
updateWarningButtonForMod(dep)
313+
end
294314
end
295315
end
296316
end
@@ -411,7 +431,7 @@ end
411431

412432
-- similar to the above checkDisabledDependenciesOfEnabledMod, but has no "Cancel" button and is meant to be called from the warning button
413433
local function checkDisabledDependenciesOfEnabledModFromWarning(info)
414-
local mod = scene.modsByName[info.Name]
434+
local mod = scene.modsByPath[info.Path]
415435
local dependenciesToToggle = findDependenciesToEnable(mod)
416436
local numDependencies = dictLength(dependenciesToToggle)
417437

@@ -460,11 +480,13 @@ local function findDependentsToDisable(mod)
460480

461481
while #queue > 0 do
462482
local depName = table.remove(queue, 1)
463-
local dep = scene.modsByName[depName]
464-
if not dep.info.IsBlacklisted and not dep.info.IsFavorite and not dependentsToDisable[depName] then
465-
dependentsToDisable[depName] = dep
483+
local depOptions = scene.modsByName[depName] or {}
484+
for _, dep in pairs(depOptions) do
485+
if not dep.info.IsBlacklisted and not dep.info.IsFavorite and not dependentsToDisable[depName] then
486+
dependentsToDisable[depName] = dep
487+
end
466488
end
467-
for _, subdep in ipairs(scene.modDependents[dep.info.Name] or {}) do
489+
for _, subdep in ipairs(scene.modDependents[depName] or {}) do
468490
if not tried[subdep] then
469491
tried[subdep] = true
470492
table.insert(queue, subdep)
@@ -492,15 +514,17 @@ local function findDependenciesThatCanBeDisabled(newlyDisabledMods)
492514

493515
while #queue > 0 do
494516
local depName = table.remove(queue, 1)
495-
local dep = scene.modsByName[depName]
496-
if dep and not dep.info.IsBlacklisted and not dep.info.IsFavorite and not dependenciesThatCanBeDisabled[depName] then
497-
local enabledDependents = findDependentsToDisable(dep)
498-
if not next(enabledDependents) then
499-
dependenciesThatCanBeDisabled[depName] = dep
500-
for _, subdep in ipairs(scene.modDependencies[depName] or {}) do
501-
if not tried[subdep] then
502-
tried[subdep] = true
503-
table.insert(queue, subdep)
517+
local depOptions = scene.modsByName[depName] or {}
518+
for _, dep in pairs(depOptions) do
519+
if not dep.info.IsBlacklisted and not dep.info.IsFavorite and not dependenciesThatCanBeDisabled[depName] then
520+
local enabledDependents = findDependentsToDisable(dep)
521+
if not next(enabledDependents) then
522+
dependenciesThatCanBeDisabled[depName] = dep
523+
for _, subdep in ipairs(scene.modDependencies[depName] or {}) do
524+
if not tried[subdep] then
525+
tried[subdep] = true
526+
table.insert(queue, subdep)
527+
end
504528
end
505529
end
506530
end
@@ -1063,7 +1087,10 @@ function scene.reload()
10631087
scene.modsByPath[info.Path] = mod
10641088

10651089
if info.Name then
1066-
scene.modsByName[info.Name] = mod
1090+
if not scene.modsByName[info.Name] then
1091+
scene.modsByName[info.Name] = {}
1092+
end
1093+
table.insert(scene.modsByName[info.Name], mod)
10671094
if not scene.modDependencies[info.Name] then
10681095
scene.modDependencies[info.Name] = {}
10691096
end

0 commit comments

Comments
 (0)