From 2a7b3f834592188213aa6140cb1e11654aeed75d Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 16 Mar 2025 22:14:50 +0100 Subject: [PATCH] Add copy with to modlist --- lib/mod_list.dart | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/mod_list.dart b/lib/mod_list.dart index ce53e86..bc6c225 100644 --- a/lib/mod_list.dart +++ b/lib/mod_list.dart @@ -407,38 +407,38 @@ class ModList { // Find groups of mods that can be reordered without breaking constraints List> groups = []; List currentGroup = []; - + for (int i = 0; i < order.length; i++) { String modId = order[i]; Mod mod = mods[modId]!; - + if (currentGroup.isEmpty) { currentGroup.add(modId); continue; } - + // Check if this mod can join the current group bool canJoin = true; for (String groupModId in currentGroup) { Mod groupMod = mods[groupModId]!; - + // Check hard dependencies - if (mod.dependencies.contains(groupModId) || + if (mod.dependencies.contains(groupModId) || groupMod.dependencies.contains(modId)) { canJoin = false; break; } - + // Check soft constraints - if (mod.loadAfter.contains(groupModId) || + if (mod.loadAfter.contains(groupModId) || groupMod.loadBefore.contains(modId) || - mod.loadBefore.contains(groupModId) || + mod.loadBefore.contains(groupModId) || groupMod.loadAfter.contains(modId)) { canJoin = false; break; } } - + if (canJoin) { currentGroup.add(modId); } else { @@ -449,25 +449,25 @@ class ModList { } } } - + // Add the last group if not empty if (currentGroup.isNotEmpty) { groups.add(currentGroup); } - + // Sort each group by size for (List group in groups) { if (group.length > 1) { group.sort((a, b) => mods[b]!.size.compareTo(mods[a]!.size)); } } - + // Reconstruct the order List result = []; for (List group in groups) { result.addAll(group); } - + return result; } @@ -501,6 +501,21 @@ class ModList { } return generateLoadOrder(); } + + ModList copyWith({ + String? configPath, + String? modsPath, + Map? mods, + Map? activeMods, + }) { + final newModlist = ModList( + configPath: configPath ?? this.configPath, + modsPath: modsPath ?? this.modsPath, + ); + newModlist.mods = mods ?? this.mods; + newModlist.activeMods = activeMods ?? this.activeMods; + return newModlist; + } } String _expansionNameFromId(String id) {