Fix up load dependencies to handle circular and multi dependencies
This commit is contained in:
@@ -400,13 +400,30 @@ class ModList {
|
||||
return bestOrder;
|
||||
}
|
||||
|
||||
List<String> loadDependencies(
|
||||
String modId, [
|
||||
List<String>? toEnable,
|
||||
Map<String, bool>? seen,
|
||||
]) {
|
||||
final mod = mods[modId]!;
|
||||
toEnable ??= <String>[];
|
||||
seen ??= <String, bool>{};
|
||||
for (final dep in mod.dependencies) {
|
||||
final depMod = mods[dep]!;
|
||||
if (seen[dep] == true) {
|
||||
throw Exception('Cyclic dependency detected: $modId -> $dep');
|
||||
}
|
||||
seen[dep] = true;
|
||||
toEnable.add(depMod.id);
|
||||
loadDependencies(depMod.id, toEnable, seen);
|
||||
}
|
||||
return toEnable;
|
||||
}
|
||||
|
||||
List<String> loadRequired() {
|
||||
final toEnable = <String>[];
|
||||
for (final modid in activeMods.keys) {
|
||||
final mod = mods[modid]!;
|
||||
for (final dep in mod.dependencies) {
|
||||
toEnable.add(dep);
|
||||
}
|
||||
loadDependencies(modid, toEnable);
|
||||
}
|
||||
for (final modid in toEnable) {
|
||||
setEnabled(modid, true);
|
||||
|
Reference in New Issue
Block a user