Skip to content

Commit

Permalink
Merge #3651 Highlight incompatible mods recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 31, 2022
2 parents 79445be + 8887476 commit a1ffa56
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Show reverse relationships (#3638, #3649 by: HebaruSan; reviewed: techman83)
- [GUI] Debounce search events on all platforms (#3641 by: HebaruSan; reviewed: techman83)
- [Multiple] Improvements for failed repo updates (#3645 by: HebaruSan; reviewed: techman83)
- [GUI] Highlight incompatible mods recursively (#3651 by: HebaruSan; reviewed: techman83)

## Bugfixes

Expand Down
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 a1ffa56

Please sign in to comment.