Add copy with to modlist
This commit is contained in:
@@ -407,38 +407,38 @@ class ModList {
|
|||||||
// Find groups of mods that can be reordered without breaking constraints
|
// Find groups of mods that can be reordered without breaking constraints
|
||||||
List<List<String>> groups = [];
|
List<List<String>> groups = [];
|
||||||
List<String> currentGroup = [];
|
List<String> currentGroup = [];
|
||||||
|
|
||||||
for (int i = 0; i < order.length; i++) {
|
for (int i = 0; i < order.length; i++) {
|
||||||
String modId = order[i];
|
String modId = order[i];
|
||||||
Mod mod = mods[modId]!;
|
Mod mod = mods[modId]!;
|
||||||
|
|
||||||
if (currentGroup.isEmpty) {
|
if (currentGroup.isEmpty) {
|
||||||
currentGroup.add(modId);
|
currentGroup.add(modId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this mod can join the current group
|
// Check if this mod can join the current group
|
||||||
bool canJoin = true;
|
bool canJoin = true;
|
||||||
for (String groupModId in currentGroup) {
|
for (String groupModId in currentGroup) {
|
||||||
Mod groupMod = mods[groupModId]!;
|
Mod groupMod = mods[groupModId]!;
|
||||||
|
|
||||||
// Check hard dependencies
|
// Check hard dependencies
|
||||||
if (mod.dependencies.contains(groupModId) ||
|
if (mod.dependencies.contains(groupModId) ||
|
||||||
groupMod.dependencies.contains(modId)) {
|
groupMod.dependencies.contains(modId)) {
|
||||||
canJoin = false;
|
canJoin = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check soft constraints
|
// Check soft constraints
|
||||||
if (mod.loadAfter.contains(groupModId) ||
|
if (mod.loadAfter.contains(groupModId) ||
|
||||||
groupMod.loadBefore.contains(modId) ||
|
groupMod.loadBefore.contains(modId) ||
|
||||||
mod.loadBefore.contains(groupModId) ||
|
mod.loadBefore.contains(groupModId) ||
|
||||||
groupMod.loadAfter.contains(modId)) {
|
groupMod.loadAfter.contains(modId)) {
|
||||||
canJoin = false;
|
canJoin = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canJoin) {
|
if (canJoin) {
|
||||||
currentGroup.add(modId);
|
currentGroup.add(modId);
|
||||||
} else {
|
} else {
|
||||||
@@ -449,25 +449,25 @@ class ModList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the last group if not empty
|
// Add the last group if not empty
|
||||||
if (currentGroup.isNotEmpty) {
|
if (currentGroup.isNotEmpty) {
|
||||||
groups.add(currentGroup);
|
groups.add(currentGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort each group by size
|
// Sort each group by size
|
||||||
for (List<String> group in groups) {
|
for (List<String> group in groups) {
|
||||||
if (group.length > 1) {
|
if (group.length > 1) {
|
||||||
group.sort((a, b) => mods[b]!.size.compareTo(mods[a]!.size));
|
group.sort((a, b) => mods[b]!.size.compareTo(mods[a]!.size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reconstruct the order
|
// Reconstruct the order
|
||||||
List<String> result = [];
|
List<String> result = [];
|
||||||
for (List<String> group in groups) {
|
for (List<String> group in groups) {
|
||||||
result.addAll(group);
|
result.addAll(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,6 +501,21 @@ class ModList {
|
|||||||
}
|
}
|
||||||
return generateLoadOrder();
|
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) {
|
String _expansionNameFromId(String id) {
|
||||||
|
Reference in New Issue
Block a user