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