Fix cyclic dependencies
This commit is contained in:
@@ -280,6 +280,7 @@ class ModList {
|
||||
loadOrder.errors.add(
|
||||
"Cyclic dependency detected: ${cyclePath.join(' -> ')}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mod.visited) {
|
||||
@@ -514,12 +515,17 @@ class ModList {
|
||||
LoadOrder? loadOrder,
|
||||
List<String>? toEnable,
|
||||
Map<String, bool>? seen,
|
||||
List<String>? cyclePath,
|
||||
]) {
|
||||
final mod = mods[modId]!;
|
||||
loadOrder ??= LoadOrder();
|
||||
toEnable ??= <String>[];
|
||||
seen ??= <String, bool>{};
|
||||
|
||||
cyclePath ??= <String>[];
|
||||
|
||||
// Add current mod to cycle path
|
||||
cyclePath.add(modId);
|
||||
|
||||
for (final dep in mod.dependencies) {
|
||||
if (!mods.containsKey(dep)) {
|
||||
loadOrder.errors.add(
|
||||
@@ -529,14 +535,22 @@ class ModList {
|
||||
}
|
||||
final depMod = mods[dep]!;
|
||||
if (seen[dep] == true) {
|
||||
loadOrder.errors.add('Cyclic dependency detected: $modId -> $dep');
|
||||
// Find the start of the cycle
|
||||
int cycleStart = cyclePath.indexOf(dep);
|
||||
if (cycleStart >= 0) {
|
||||
// Extract the cycle part
|
||||
List<String> cycleIds = [...cyclePath.sublist(cycleStart), modId];
|
||||
loadOrder.errors.add('Cyclic dependency detected: ${cycleIds.join(' -> ')}');
|
||||
} else {
|
||||
loadOrder.errors.add('Cyclic dependency detected: $modId -> $dep');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
seen[dep] = true;
|
||||
toEnable.add(depMod.id);
|
||||
loadDependencies(depMod.id, loadOrder, toEnable, seen);
|
||||
loadDependencies(depMod.id, loadOrder, toEnable, seen, List.from(cyclePath));
|
||||
}
|
||||
|
||||
|
||||
return loadOrder;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user