From fa63a25cf47c8452e1cf3a5cc308edeb30bf639f Mon Sep 17 00:00:00 2001 From: Sewer56 Date: Tue, 26 Nov 2024 19:07:42 +0000 Subject: [PATCH] Added: Autosort capability to public API 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. --- .../LauncherManagerHandler.Sorter.cs | 12 +----------- src/Bannerlord.LauncherManager/Utils/SortHelper.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Bannerlord.LauncherManager/LauncherManagerHandler.Sorter.cs b/src/Bannerlord.LauncherManager/LauncherManagerHandler.Sorter.cs index 035b8ce..f8f0c00 100644 --- a/src/Bannerlord.LauncherManager/LauncherManagerHandler.Sorter.cs +++ b/src/Bannerlord.LauncherManager/LauncherManagerHandler.Sorter.cs @@ -20,19 +20,9 @@ partial class LauncherManagerHandler /// public void Sort() { - static IEnumerable Sort(IEnumerable 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); diff --git a/src/Bannerlord.LauncherManager/Utils/SortHelper.cs b/src/Bannerlord.LauncherManager/Utils/SortHelper.cs index 3fd93b9..fa74b96 100644 --- a/src/Bannerlord.LauncherManager/Utils/SortHelper.cs +++ b/src/Bannerlord.LauncherManager/Utils/SortHelper.cs @@ -9,6 +9,20 @@ namespace Bannerlord.LauncherManager.Utils; public static class SortHelper { + /// + /// Given a list of modules provided as , automatically + /// sorts the modules such that they form a valid load order based on module metadata. + /// + public static IEnumerable AutoSort(IEnumerable source) + { + var orderedModules = source + .OrderByDescending(x => x.IsOfficial) + .ThenBy(x => x.Id, new AlphanumComparatorFast()) + .ToArray(); + + return ModuleSorter.TopologySort(orderedModules, module => ModuleUtilities.GetDependencies(orderedModules, module)); + } + /// /// External
///