From 856d98ac126455e451aab5f861f7970ef826cbbe Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 16 Mar 2025 14:01:24 +0100 Subject: [PATCH] Fix up load dependencies to handle circular and multi dependencies --- lib/mod_list.dart | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/mod_list.dart b/lib/mod_list.dart index 227bc89..9f31e10 100644 --- a/lib/mod_list.dart +++ b/lib/mod_list.dart @@ -400,13 +400,30 @@ class ModList { return bestOrder; } + List loadDependencies( + String modId, [ + List? toEnable, + Map? seen, + ]) { + final mod = mods[modId]!; + toEnable ??= []; + seen ??= {}; + 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 loadRequired() { final toEnable = []; 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);