Skip to content

Commit

Permalink
added support for addons with multiple jsons, updated to 0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfds committed Nov 20, 2024
1 parent d8900c4 commit 54bf73a
Show file tree
Hide file tree
Showing 13 changed files with 611 additions and 473 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.26.0</Version>
<Version>0.27.0</Version>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
73 changes: 57 additions & 16 deletions src/Addons/Helpers/AutoloadModsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,84 @@ public static bool ValidateAutoloadMod(AutoloadMod autoloadMod, IAddon campaign,
return false;
}

var areDependenciesPassed = CheckDependencies(autoloadMod, campaign, mods);

if (!areDependenciesPassed)
{
return false;
}

var areIncompatiblesPassed = CheckIncompatibles(autoloadMod, campaign, mods);

return areIncompatiblesPassed;
}


/// <summary>
/// Check if addon has all required dependencies
/// </summary>
private static bool CheckDependencies(
AutoloadMod autoloadMod,
IAddon campaign,
Dictionary<AddonVersion, IAddon> mods)
{
if (autoloadMod.DependentAddons is not null)
{
foreach (var dependantAddon in autoloadMod.DependentAddons)
byte passedDependenciesCount = 0;

foreach (var dependentAddon in autoloadMod.DependentAddons)
{
if (campaign.Id.Equals(dependantAddon.Key, StringComparison.InvariantCultureIgnoreCase) &&
(dependantAddon.Value is null || VersionComparer.Compare(campaign.Version, dependantAddon.Value)))
if (dependentAddon.Key.Equals(campaign.Id, StringComparison.InvariantCultureIgnoreCase) &&
(dependentAddon.Value is null || VersionComparer.Compare(campaign.Version, dependentAddon.Value)))
{
return true;
passedDependenciesCount++;
}

foreach (var addon in mods)
{
if (!dependantAddon.Key.Equals(addon.Key.Id, StringComparison.InvariantCultureIgnoreCase))
if (!dependentAddon.Key.Equals(addon.Key.Id, StringComparison.InvariantCultureIgnoreCase))
{
continue;
}
else if (dependantAddon.Value is null)

if (dependentAddon.Value is null)
{
return true;
passedDependenciesCount++;
}
else if (VersionComparer.Compare(addon.Key.Version, dependantAddon.Value))
else if (VersionComparer.Compare(addon.Key.Version, dependentAddon.Value))
{
return true;
passedDependenciesCount++;
}
}
}

return false;
return autoloadMod.DependentAddons.Count == passedDependenciesCount;
}
else
{
return true;
}
}

/// <summary>
/// Check if addon doesn't have any loaded incompatibles
/// </summary>
private static bool CheckIncompatibles(AutoloadMod autoloadMod, IAddon campaign, Dictionary<AddonVersion, IAddon> mods)
{
if (autoloadMod.IncompatibleAddons is not null)
{
foreach (var incompatibleAddon in autoloadMod.IncompatibleAddons)
{
//What a fucking mess...
//if campaign id equals addon id
if (campaign.Id.Equals(incompatibleAddon.Key, StringComparison.InvariantCultureIgnoreCase) &&
//AND either both campaign's and addon's versions are null
((incompatibleAddon.Value is null && campaign.Version is null) ||
//AND either campaign's id is null
(incompatibleAddon.Value is null ||
//OR addon's versions are null
campaign.Version is null ||
//OR addon's version is not null and does match the comparer
(incompatibleAddon.Value is not null && VersionComparer.Compare(campaign.Version, incompatibleAddon.Value))))
(incompatibleAddon.Value is not null && VersionComparer.Compare(campaign.Version, incompatibleAddon.Value))
))
{
//the addon is incompatible
return false;
Expand All @@ -94,12 +131,14 @@ public static bool ValidateAutoloadMod(AutoloadMod autoloadMod, IAddon campaign,
{
continue;
}

if (addon.Value is AutoloadMod aMod &&
!aMod.IsEnabled)
{
continue;
}
else if (incompatibleAddon.Value is null)

if (incompatibleAddon.Value is null)
{
return false;
}
Expand All @@ -112,7 +151,9 @@ public static bool ValidateAutoloadMod(AutoloadMod autoloadMod, IAddon campaign,

return true;
}

return true;
else
{
return true;
}
}
}
Loading

0 comments on commit 54bf73a

Please sign in to comment.