Add copy with to modlist

This commit is contained in:
2025-03-16 22:14:50 +01:00
parent d41413dbcd
commit 2a7b3f8345

View File

@@ -407,38 +407,38 @@ class ModList {
// Find groups of mods that can be reordered without breaking constraints
List<List<String>> groups = [];
List<String> currentGroup = [];
for (int i = 0; i < order.length; i++) {
String modId = order[i];
Mod mod = mods[modId]!;
if (currentGroup.isEmpty) {
currentGroup.add(modId);
continue;
}
// Check if this mod can join the current group
bool canJoin = true;
for (String groupModId in currentGroup) {
Mod groupMod = mods[groupModId]!;
// Check hard dependencies
if (mod.dependencies.contains(groupModId) ||
if (mod.dependencies.contains(groupModId) ||
groupMod.dependencies.contains(modId)) {
canJoin = false;
break;
}
// Check soft constraints
if (mod.loadAfter.contains(groupModId) ||
if (mod.loadAfter.contains(groupModId) ||
groupMod.loadBefore.contains(modId) ||
mod.loadBefore.contains(groupModId) ||
mod.loadBefore.contains(groupModId) ||
groupMod.loadAfter.contains(modId)) {
canJoin = false;
break;
}
}
if (canJoin) {
currentGroup.add(modId);
} else {
@@ -449,25 +449,25 @@ class ModList {
}
}
}
// Add the last group if not empty
if (currentGroup.isNotEmpty) {
groups.add(currentGroup);
}
// Sort each group by size
for (List<String> group in groups) {
if (group.length > 1) {
group.sort((a, b) => mods[b]!.size.compareTo(mods[a]!.size));
}
}
// Reconstruct the order
List<String> result = [];
for (List<String> group in groups) {
result.addAll(group);
}
return result;
}
@@ -501,6 +501,21 @@ class ModList {
}
return generateLoadOrder();
}
ModList copyWith({
String? configPath,
String? modsPath,
Map<String, Mod>? mods,
Map<String, bool>? activeMods,
}) {
final newModlist = ModList(
configPath: configPath ?? this.configPath,
modsPath: modsPath ?? this.modsPath,
);
newModlist.mods = mods ?? this.mods;
newModlist.activeMods = activeMods ?? this.activeMods;
return newModlist;
}
}
String _expansionNameFromId(String id) {