Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight incompatible mods recursively #3651

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ IEnumerable<string> FindReverseDependencies(
/// <param name="with_provides">If set to false will not check for provided versions.</param>
/// <returns>The version of the mod or null if not found</returns>
ModuleVersion InstalledVersion(string identifier, bool with_provides = true);

/// <summary>
/// Check whether any versions of this mod are installable (including dependencies) on the given game versions
/// </summary>
/// <param name="identifier">Identifier of mod</param>
/// <param name="crit">Game versions</param>
/// <returns>true if any version is recursively compatible, false otherwise</returns>
bool IdentifierCompatible(string identifier, GameVersionCriteria crit);
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,20 @@ public IEnumerable<CkanModule> IncompatibleModules(GameVersionCriteria ksp_versi
return sorter.Incompatible.Values.Select(avail => avail.Latest(null)).ToList();
}

/// <summary>
/// Check whether any versions of this mod are installable (including dependencies) on the given game versions.
/// Quicker than checking CompatibleModules for one identifier.
/// </summary>
/// <param name="identifier">Identifier of mod</param>
/// <param name="crit">Game versions</param>
/// <returns>true if any version is recursively compatible, false otherwise</returns>
public bool IdentifierCompatible(string identifier, GameVersionCriteria crit)
{
// Set up our compatibility partition
SetCompatibleVersion(crit);
return sorter.Compatible.ContainsKey(identifier);
}

/// <summary>
/// <see cref="IRegistryQuerier.LatestAvailable" />
/// </summary>
Expand Down
14 changes: 8 additions & 6 deletions GUI/Controls/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ private TreeNode findDependencyShallow(IRegistryQuerier registry, RelationshipDe
out CkanModule matched))
{
return matched != null
? indexedNode(registry, matched, relationship, true)
? indexedNode(registry, matched, relationship, crit)
: nonModuleNode(relDescr, null, relationship);
}

Expand All @@ -603,13 +603,13 @@ private TreeNode findDependencyShallow(IRegistryQuerier registry, RelationshipDe
&& relDescr.ContainsAny(new string[] { dependencyModules[0].identifier }))
{
// Only one exact match module, return a simple node
return indexedNode(registry, dependencyModules[0], relationship, crit != null);
return indexedNode(registry, dependencyModules[0], relationship, crit);
}
else
{
// Several found or not same id, return a "provides" node
return providesNode(relDescr.ToString(), relationship,
dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit != null))
dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit))
);
}
}
Expand All @@ -623,11 +623,11 @@ private IEnumerable<TreeNode> ReverseRelationships(IRegistryQuerier registry, Tr
compat.SelectMany(otherMod =>
GetModRelationships(otherMod, relationship)
.Where(r => r.MatchesAny(toFind, null, null))
.Select(r => indexedNode(registry, otherMod, relationship, true)))
.Select(r => indexedNode(registry, otherMod, relationship, crit)))
.Concat(incompat.SelectMany(otherMod =>
GetModRelationships(otherMod, relationship)
.Where(r => r.MatchesAny(toFind, null, null))
.Select(r => indexedNode(registry, otherMod, relationship, false)))));
.Select(r => indexedNode(registry, otherMod, relationship, crit)))));
}

private TreeNode providesNode(string identifier, RelationshipType relationship, IEnumerable<TreeNode> children)
Expand All @@ -641,9 +641,11 @@ private TreeNode providesNode(string identifier, RelationshipType relationship,
};
}

private TreeNode indexedNode(IRegistryQuerier registry, CkanModule module, RelationshipType relationship, bool compatible)
private TreeNode indexedNode(IRegistryQuerier registry, CkanModule module, RelationshipType relationship, GameVersionCriteria crit)
{
int icon = (int)relationship + 1;
bool compatible = crit == null ? false
: registry.IdentifierCompatible(module.identifier, crit);
string suffix = compatible ? ""
: $" ({registry.CompatibleGameVersions(manager.CurrentInstance.game, module.identifier)})";
return new TreeNode($"{module.name} {module.version}{suffix}", icon, icon)
Expand Down