Skip to content

Commit

Permalink
Do not force load Space Age DLC mods
Browse files Browse the repository at this point in the history
There is no need to forcefully add these mods, when they are enabled
they get loaded. If there is no mod-list.json and the DLC is available,
the mods get added automatically (like the game would do).
  • Loading branch information
veger committed Oct 24, 2024
1 parent 7031cfd commit 69cd2fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Yafc.Parser/FactorioDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@ public static Project Parse(string factorioPath, string modPath, string projectP
string modListPath = Path.Combine(modPath, "mod-list.json");
Dictionary<string, Version> versionSpecifiers = [];

if (File.Exists(modListPath)) {
bool hasModList = File.Exists(modListPath);
if (hasModList) {
var mods = JsonSerializer.Deserialize<ModList>(File.ReadAllText(modListPath)) ?? throw new($"Could not read mod list from {modListPath}");
allMods = mods.mods.Where(x => x.enabled).Select(x => x.name).ToDictionary(x => x, x => (ModInfo)null!);
versionSpecifiers = mods.mods.Where(x => x.enabled && !string.IsNullOrEmpty(x.version)).ToDictionary(x => x.name, x => Version.Parse(x.version!)); // null-forgiving: null version strings are filtered by the Where.
}
else {
allMods = new Dictionary<string, ModInfo> { { "base", null! }, { "elevated-rails", null! }, { "quality", null! }, { "space-age", null! } };
allMods = new Dictionary<string, ModInfo> { { "base", null! } };
}

allMods["core"] = null!;
Expand All @@ -198,6 +199,18 @@ public static Project Parse(string factorioPath, string modPath, string projectP
FindMods(modPath, progress, allFoundMods);
}

if (!hasModList) {
// Check if the Space Age DLC mods are available, as the game will enable them by default when available.
bool foundSpaceAge = allFoundMods.Exists(modInfo => modInfo.name == "space-age");
if (foundSpaceAge) {
// Add space-age mod ...
allMods.Add("space-age", null!);
// ... and its dependencies
allMods.Add("quality", null!);
allMods.Add("elevated-rails", null!);
}
}

Version? factorioVersion = null;

foreach (var mod in allFoundMods) {
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
// Internal changes:
// Changes to the code that do not affect the behavior of the program.
----------------------------------------------------------------------------------------------------------------------
Version: 2.0.2
Date: soon(tm)
Bugfixes:
- Support games without the Space Age DLC again.
----------------------------------------------------------------------------------------------------------------------
Version: 2.0.1
Date: October 23rd 2024
Bugfixes:
Expand Down

0 comments on commit 69cd2fd

Please sign in to comment.