Skip to content

Commit

Permalink
Merge pull request #8 from Sewer56/add-public-autosort
Browse files Browse the repository at this point in the history
Added: Autosort capability to public API
  • Loading branch information
Aragas authored Nov 30, 2024
2 parents e49e31b + fa63a25 commit 57435cf
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 57435cf

Please sign in to comment.