Implement loading dependencies for mods

This commit is contained in:
2025-03-16 13:31:15 +01:00
parent 76363dd523
commit 9931e7bf89
2 changed files with 76 additions and 10 deletions

View File

@@ -5,13 +5,13 @@ import 'package:rimworld_modman/mod.dart';
import 'package:xml/xml.dart';
class ModList {
final String configPath;
final String modsPath;
String configPath = '';
String modsPath = '';
// O(1) lookup
Map<String, bool> activeMods = {};
Map<String, Mod> mods = {};
ModList({required this.configPath, required this.modsPath});
ModList({this.configPath = '', this.modsPath = ''});
Stream<Mod> loadAvailable() async* {
final logger = Logger.instance;
@@ -184,6 +184,18 @@ class ModList {
}
}
void enableAll() {
for (final mod in mods.values) {
setEnabled(mod.id, true);
}
}
void disableAll() {
for (final mod in mods.values) {
setEnabled(mod.id, false);
}
}
List<List<String>> checkIncompatibilities() {
List<List<String>> conflicts = [];
List<String> activeModIds = activeMods.keys.toList();
@@ -387,6 +399,20 @@ class ModList {
return bestOrder;
}
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);
}
}
for (final modid in toEnable) {
setEnabled(modid, true);
}
return generateLoadOrder();
}
}
String _expansionNameFromId(String id) {