More slight refactoring
This commit is contained in:
38
lib/mod.dart
38
lib/mod.dart
@@ -22,25 +22,29 @@ class Mod {
|
||||
final String path; // figure it out
|
||||
final List<String> versions; // ModMetaData.supportedVersions
|
||||
final String description; // ModMetaData.description
|
||||
final List<String> hardDependencies; // ModMetaData.modDependencies
|
||||
final List<String> dependencies; // ModMetaData.modDependencies
|
||||
final List<String> loadAfter; // ModMetaData.loadAfter
|
||||
final List<String> loadBefore; // ModMetaData.loadBefore
|
||||
final List<String> incompatabilities; // ModMetaData.incompatibleWith
|
||||
final List<String> incompatibilities; // ModMetaData.incompatibleWith
|
||||
bool enabled;
|
||||
final int size; // Count of files in the mod directory
|
||||
final bool isBaseGame; // Is this the base RimWorld game
|
||||
final bool isExpansion; // Is this a RimWorld expansion
|
||||
|
||||
bool visited = false;
|
||||
bool mark = false;
|
||||
int position = -1;
|
||||
|
||||
Mod({
|
||||
required this.name,
|
||||
required this.id,
|
||||
required this.path,
|
||||
required this.versions,
|
||||
required this.description,
|
||||
required this.hardDependencies,
|
||||
required this.dependencies,
|
||||
required this.loadAfter,
|
||||
required this.loadBefore,
|
||||
required this.incompatabilities,
|
||||
required this.incompatibilities,
|
||||
required this.size,
|
||||
this.isBaseGame = false,
|
||||
this.isExpansion = false,
|
||||
@@ -130,9 +134,9 @@ class Mod {
|
||||
);
|
||||
}
|
||||
|
||||
List<String> hardDependencies = [];
|
||||
List<String> dependencies = [];
|
||||
try {
|
||||
hardDependencies =
|
||||
dependencies =
|
||||
metadata
|
||||
.findElements('modDependenciesByVersion')
|
||||
.first
|
||||
@@ -145,10 +149,10 @@ class Mod {
|
||||
e.findElements("packageId").first.innerText.toLowerCase(),
|
||||
)
|
||||
.toList();
|
||||
logger.info('Hard dependencies found: ${hardDependencies.join(", ")}');
|
||||
logger.info('Dependencies found: ${dependencies.join(", ")}');
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
'Hard dependencies element is missing in ModMetaData ($aboutFile).',
|
||||
'Dependencies element is missing in ModMetaData ($aboutFile).',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -184,16 +188,16 @@ class Mod {
|
||||
);
|
||||
}
|
||||
|
||||
List<String> incompatabilities = [];
|
||||
List<String> incompatibilities = [];
|
||||
try {
|
||||
incompatabilities =
|
||||
incompatibilities =
|
||||
metadata
|
||||
.findElements('incompatibleWith')
|
||||
.first
|
||||
.findElements('li')
|
||||
.map((e) => e.innerText.toLowerCase())
|
||||
.toList();
|
||||
logger.info('Incompatibilities found: ${incompatabilities.join(", ")}');
|
||||
logger.info('Incompatibilities found: ${incompatibilities.join(", ")}');
|
||||
} catch (e) {
|
||||
logger.warning(
|
||||
'Incompatibilities element is missing in ModMetaData ($aboutFile).',
|
||||
@@ -245,10 +249,10 @@ class Mod {
|
||||
path: path,
|
||||
versions: versions,
|
||||
description: description,
|
||||
hardDependencies: hardDependencies,
|
||||
dependencies: dependencies,
|
||||
loadAfter: loadAfter,
|
||||
loadBefore: loadBefore,
|
||||
incompatabilities: incompatabilities,
|
||||
incompatibilities: incompatibilities,
|
||||
size: size,
|
||||
isBaseGame: isBaseGame,
|
||||
isExpansion: isExpansion,
|
||||
@@ -261,10 +265,10 @@ class Mod {
|
||||
String? path,
|
||||
List<String>? versions,
|
||||
String? description,
|
||||
List<String>? hardDependencies,
|
||||
List<String>? dependencies,
|
||||
List<String>? loadAfter,
|
||||
List<String>? loadBefore,
|
||||
List<String>? incompatabilities,
|
||||
List<String>? incompatibilities,
|
||||
int? size,
|
||||
bool? isBaseGame,
|
||||
bool? isExpansion,
|
||||
@@ -276,10 +280,10 @@ class Mod {
|
||||
path: path ?? this.path,
|
||||
versions: versions ?? this.versions,
|
||||
description: description ?? this.description,
|
||||
hardDependencies: hardDependencies ?? this.hardDependencies,
|
||||
dependencies: dependencies ?? this.dependencies,
|
||||
loadAfter: loadAfter ?? this.loadAfter,
|
||||
loadBefore: loadBefore ?? this.loadBefore,
|
||||
incompatabilities: incompatabilities ?? this.incompatabilities,
|
||||
incompatibilities: incompatibilities ?? this.incompatibilities,
|
||||
size: size ?? this.size,
|
||||
isBaseGame: isBaseGame ?? this.isBaseGame,
|
||||
isExpansion: isExpansion ?? this.isExpansion,
|
||||
|
@@ -57,10 +57,10 @@ class ModList {
|
||||
path: mod.path,
|
||||
versions: mod.versions,
|
||||
description: mod.description,
|
||||
hardDependencies: mod.hardDependencies,
|
||||
dependencies: mod.dependencies,
|
||||
loadAfter: mod.loadAfter,
|
||||
loadBefore: mod.loadBefore,
|
||||
incompatabilities: mod.incompatabilities,
|
||||
incompatibilities: mod.incompatibilities,
|
||||
size: mod.size,
|
||||
enabled: existingMod.enabled,
|
||||
isBaseGame: existingMod.isBaseGame,
|
||||
@@ -147,12 +147,12 @@ class ModList {
|
||||
: isExpansion
|
||||
? "RimWorld expansion"
|
||||
: ""),
|
||||
hardDependencies: existingMod?.hardDependencies ?? [],
|
||||
dependencies: existingMod?.dependencies ?? [],
|
||||
loadAfter:
|
||||
existingMod?.loadAfter ??
|
||||
(isExpansion ? ['ludeon.rimworld'] : []),
|
||||
loadBefore: existingMod?.loadBefore ?? [],
|
||||
incompatabilities: existingMod?.incompatabilities ?? [],
|
||||
incompatibilities: existingMod?.incompatibilities ?? [],
|
||||
enabled: existingMod?.enabled ?? false,
|
||||
size: existingMod?.size ?? 0,
|
||||
isBaseGame: isBaseGame,
|
||||
@@ -162,7 +162,7 @@ class ModList {
|
||||
logger.warning('Mod $modId already exists in mods list, overwriting');
|
||||
}
|
||||
mods[modId] = mod;
|
||||
activeMods[modId] = true;
|
||||
setEnabled(modId, mod.enabled);
|
||||
yield mod;
|
||||
}
|
||||
|
||||
@@ -172,6 +172,28 @@ class ModList {
|
||||
throw Exception('Failed to load config file: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void setEnabled(String modId, bool enabled) {
|
||||
if (mods.containsKey(modId)) {
|
||||
mods[modId]!.enabled = enabled;
|
||||
if (enabled) {
|
||||
activeMods[modId] = true;
|
||||
} else {
|
||||
activeMods.remove(modId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
String _expansionNameFromId(String id) {
|
||||
|
@@ -57,8 +57,7 @@ void main() {
|
||||
for (final mod in dummyMods.keys) {
|
||||
dummyList.activeMods[mod] = true;
|
||||
}
|
||||
// final sortedMods = dummyList.sort();
|
||||
final sortedMods = ['harmony', 'ludeon.rimworld', 'ludeon.rimworld.anomaly'];
|
||||
final sortedMods = dummyList.sort();
|
||||
|
||||
group('Test sorting', () {
|
||||
test('Harmony should load before RimWorld', () {
|
||||
|
Reference in New Issue
Block a user