Add the old loadRequired
This commit is contained in:
@@ -397,13 +397,69 @@ class ModList {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadOrder loadRequired() {
|
LoadOrder loadDependencies(
|
||||||
final loadOrder = generateLoadOrder();
|
String modId, [
|
||||||
for (final modId in loadOrder.order.map((e) => e.id)) {
|
LoadOrder? loadOrder,
|
||||||
setEnabled(modId, true);
|
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(
|
||||||
|
'Missing dependency: ${mod.name} requires mod with ID $dep',
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final depMod = mods[dep]!;
|
||||||
|
if (seen[dep] == true) {
|
||||||
|
// 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,
|
||||||
|
List.from(cyclePath),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadOrder;
|
return loadOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LoadOrder loadRequired([LoadOrder? loadOrder]) {
|
||||||
|
loadOrder ??= LoadOrder();
|
||||||
|
final toEnable = <String>[];
|
||||||
|
for (final modid in activeMods.keys) {
|
||||||
|
loadDependencies(modid, loadOrder, toEnable);
|
||||||
|
}
|
||||||
|
for (final modid in toEnable) {
|
||||||
|
setEnabled(modid, true);
|
||||||
|
}
|
||||||
|
return generateLoadOrder(loadOrder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _expansionNameFromId(String id) {
|
String _expansionNameFromId(String id) {
|
||||||
|
Reference in New Issue
Block a user