Skip to content

Commit

Permalink
Support non-Space Age games (#326)
Browse files Browse the repository at this point in the history
I checked all of the #320 commits to see if they would a hard dependency
on the Space Age DLC. And I only found the one commit that adds the mods
by default.

As far as I could figure out, there is no need to forcefully add these
mods: when they are enabled in mod-list.json they get loaded. No other
code is depending on these mods, all related code adds support when it
is encountered when loading the mods.

I tested by loading both a Space Age and a non-Space Age project (with
the mods enabled/disabled) without issues.

So in the end the fix for #323 is fairly straightforward 😌
  • Loading branch information
shpaass authored Oct 28, 2024
2 parents 812dc48 + 3bf9ec0 commit 149d2e3
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 149d2e3

Please sign in to comment.