Skip to content

Commit

Permalink
Highlight incompatible mods recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 30, 2022
1 parent 79445be commit 8887476
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
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

0 comments on commit 8887476

Please sign in to comment.