Fix up load dependencies to handle circular and multi dependencies
This commit is contained in:
@@ -400,13 +400,30 @@ class ModList {
|
|||||||
return bestOrder;
|
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() {
|
List<String> loadRequired() {
|
||||||
final toEnable = <String>[];
|
final toEnable = <String>[];
|
||||||
for (final modid in activeMods.keys) {
|
for (final modid in activeMods.keys) {
|
||||||
final mod = mods[modid]!;
|
loadDependencies(modid, toEnable);
|
||||||
for (final dep in mod.dependencies) {
|
|
||||||
toEnable.add(dep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (final modid in toEnable) {
|
for (final modid in toEnable) {
|
||||||
setEnabled(modid, true);
|
setEnabled(modid, true);
|
||||||
|
Reference in New Issue
Block a user