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

@@ -8,7 +8,7 @@ const configRoot = '$root/AppData/RimWorld by Ludeon Studios/Config';
const configPath = '$configRoot/ModsConfig.xml';
const logsPath = '$root/ModManager';
void main() {
Map<String, Mod> generateDummyMods() {
final dummyMod = Mod(
name: 'Dummy Mod',
id: 'dummy',
@@ -32,6 +32,13 @@ void main() {
loadBefore: ["ludeon.rimworld"],
size: 47,
),
'prepatcher': dummyMod.copyWith(
name: 'Prepatcher',
id: 'prepatcher',
loadAfter: ["ludeon.rimworld"],
dependencies: ["harmony"],
size: 47,
),
'ludeon.rimworld': dummyMod.copyWith(
name: 'RimWorld',
id: 'ludeon.rimworld',
@@ -56,11 +63,14 @@ void main() {
),
};
final dummyList = ModList(configPath: configPath, modsPath: modsRoot);
dummyList.mods.addAll(dummyMods);
for (final mod in dummyMods.keys) {
dummyList.setEnabled(mod, true);
}
return dummyMods;
}
void main() {
final dummyMods = generateDummyMods();
final dummyList = ModList();
dummyList.mods = dummyMods;
dummyList.enableAll();
dummyList.setEnabled('disabledDummy', false);
dummyList.setEnabled('incompatible', false);
final sortedMods = dummyList.generateLoadOrder();
@@ -71,6 +81,13 @@ void main() {
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
expect(harmonyIndex, lessThan(rimworldIndex));
});
test('Prepatcher should load after Harmony and RimWorld', () {
final prepatcherIndex = sortedMods.indexOf('prepatcher');
final harmonyIndex = sortedMods.indexOf('harmony');
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
expect(prepatcherIndex, greaterThan(harmonyIndex));
expect(prepatcherIndex, greaterThan(rimworldIndex));
});
test('RimWorld should load before Anomaly', () {
final rimworldIndex = sortedMods.indexOf('ludeon.rimworld');
final anomalyIndex = sortedMods.indexOf('ludeon.rimworld.anomaly');
@@ -85,9 +102,32 @@ void main() {
final yuuugeIndex = sortedMods.indexOf('yuuuge');
expect(yuuugeIndex, lessThan(smolIndex));
});
dummyList.setEnabled('incompatible', true);
test('Error generating load order with incompatible mods', () {
dummyList.setEnabled('incompatible', true);
expect(() => dummyList.generateLoadOrder(), throwsException);
});
});
final dummyMods2 = generateDummyMods();
final dummyList2 = ModList();
dummyList2.mods = dummyMods2;
dummyList2.disableAll();
dummyList2.setEnabled('prepatcher', true);
final sortedMods2 = dummyList2.loadRequired();
group('Test loadRequired', () {
test(
'Harmony should get enabled by loadRequired as a dependency of prepatcher',
() {
final harmonyIndex = sortedMods2.indexOf('harmony');
expect(harmonyIndex, isNot(-1));
},
);
test('No other mods should get enabled', () {
for (final mod in dummyMods2.keys) {
if (mod != 'prepatcher' && mod != 'harmony') {
expect(sortedMods2.indexOf(mod), isNegative);
}
}
});
});
}