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 28, 2024
1 parent 812dc48 commit 3bf9ec0
Show file tree
Hide file tree
Showing 2 changed files with 16 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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Date:
Bugfixes:
- Recipes no longer have excessive question marks in their names
- Moved mining and research bonuses have to the Preferences screen.
- Support games without the Space Age DLC again.
Internal changes:
- Added rudimentary tools for drawing tab controls.
----------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 3bf9ec0

Please sign in to comment.