Skip to content

Commit

Permalink
Added: Autosort capability to public API
Browse files Browse the repository at this point in the history
This adds the ability to Autosort to public API.
Previously this was only accessible via the LauncherManager , but not for users who wished to call it without providing the full LauncherManager abstraction.

This commit makes that functionality visible now.
  • Loading branch information
Sewer56 committed Nov 26, 2024
1 parent e49e31b commit fa63a25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/Bannerlord.LauncherManager/LauncherManagerHandler.Sorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@ partial class LauncherManagerHandler
/// </summary>
public void Sort()
{
static IEnumerable<ModuleInfoExtended> Sort(IEnumerable<ModuleInfoExtended> source)
{
var orderedModules = source
.OrderByDescending(x => x.IsOfficial)
.ThenBy(x => x.Id, new AlphanumComparatorFast())
.ToArray();

return ModuleSorter.TopologySort(orderedModules, module => ModuleUtilities.GetDependencies(orderedModules, module));
}

IsSorting = true;
var modules = GetModuleViewModels()?.Select(x => x.ModuleInfoExtended) ?? [];
var sorted = Sort(modules);
var sorted = SortHelper.AutoSort(modules);
var sortedViewModels = GetViewModelsFromModules(sorted);
SetModuleViewModels(sortedViewModels);

Expand Down
14 changes: 14 additions & 0 deletions src/Bannerlord.LauncherManager/Utils/SortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ namespace Bannerlord.LauncherManager.Utils;

public static class SortHelper
{
/// <summary>
/// Given a list of modules provided as <paramref name="source"/>, automatically
/// sorts the modules such that they form a valid load order based on module metadata.
/// </summary>
public static IEnumerable<ModuleInfoExtended> AutoSort(IEnumerable<ModuleInfoExtended> source)
{
var orderedModules = source
.OrderByDescending(x => x.IsOfficial)
.ThenBy(x => x.Id, new AlphanumComparatorFast())
.ToArray();

return ModuleSorter.TopologySort(orderedModules, module => ModuleUtilities.GetDependencies(orderedModules, module));
}

/// <summary>
/// External<br/>
/// </summary>
Expand Down

0 comments on commit fa63a25

Please sign in to comment.