lil bit more refactoring
This commit is contained in:
@@ -184,27 +184,15 @@ class ModList {
|
||||
}
|
||||
}
|
||||
|
||||
// List of mod ids
|
||||
List<String> sort() {
|
||||
final sortedMods = activeMods.keys.toList();
|
||||
sortedMods.sort((a, b) {
|
||||
final aIndex = mods[a]!.loadBefore.length;
|
||||
final bIndex = mods[b]!.loadBefore.length;
|
||||
return aIndex.compareTo(bIndex);
|
||||
});
|
||||
return sortedMods;
|
||||
}
|
||||
|
||||
List<List<String>> checkIncompatibilities() {
|
||||
List<List<String>> conflicts = [];
|
||||
List<String> activeModIds = activeMods.keys.toList();
|
||||
|
||||
// Only check each pair once
|
||||
for (int i = 0; i < activeModIds.length; i++) {
|
||||
String modId = activeModIds[i];
|
||||
for (final modId in activeModIds) {
|
||||
Mod mod = mods[modId]!;
|
||||
|
||||
for (String incompId in mod.incompatibilities) {
|
||||
for (final incompId in mod.incompatibilities) {
|
||||
// Only process if other mod is active and we haven't checked this pair yet
|
||||
if (activeMods.containsKey(incompId) && modId.compareTo(incompId) < 0) {
|
||||
conflicts.add([modId, incompId]);
|
||||
@@ -217,7 +205,7 @@ class ModList {
|
||||
/// Generate a load order for active mods
|
||||
List<String> generateLoadOrder() {
|
||||
// Check for incompatibilities first
|
||||
List<List<String>> conflicts = checkIncompatibilities();
|
||||
final conflicts = checkIncompatibilities();
|
||||
if (conflicts.isNotEmpty) {
|
||||
throw Exception(
|
||||
"Incompatible mods selected: ${conflicts.map((c) => "${c[0]} and ${c[1]}").join(', ')}",
|
||||
@@ -225,19 +213,23 @@ class ModList {
|
||||
}
|
||||
|
||||
// Reset all marks for topological sort
|
||||
for (Mod mod in mods.values) {
|
||||
for (final mod in mods.values) {
|
||||
mod.visited = false;
|
||||
mod.mark = false;
|
||||
mod.position = -1;
|
||||
}
|
||||
|
||||
List<String> result = [];
|
||||
final result = <String>[];
|
||||
int position = 0;
|
||||
|
||||
// Topological sort
|
||||
void visit(Mod mod) {
|
||||
if (!mod.enabled) {
|
||||
mod.visited = true;
|
||||
return;
|
||||
}
|
||||
if (mod.mark) {
|
||||
List<String> cyclePath =
|
||||
final cyclePath =
|
||||
mods.values.where((m) => m.mark).map((m) => m.name).toList();
|
||||
throw Exception(
|
||||
"Cyclic dependency detected: ${cyclePath.join(' -> ')}",
|
||||
|
Reference in New Issue
Block a user