diff --git a/src/Bannerlord.LauncherManager/Utils/DefaultModuleContext.cs b/src/Bannerlord.LauncherManager/Utils/DefaultModuleContext.cs new file mode 100644 index 0000000..638dff9 --- /dev/null +++ b/src/Bannerlord.LauncherManager/Utils/DefaultModuleContext.cs @@ -0,0 +1,54 @@ +using Bannerlord.LauncherManager.Models; +using Bannerlord.ModuleManager; + +using System.Collections.Generic; +using System.Linq; + +namespace Bannerlord.LauncherManager.Utils; + +public class DefaultModuleContext where TModuleViewModel : class, IModuleViewModel +{ + private readonly IDictionary _lookup; + public DefaultModuleContext(IEnumerable moduleVMs) + { + _lookup = moduleVMs.ToDictionary(x => x.ModuleInfoExtended.Id, x => x); + } + public DefaultModuleContext(IDictionary lookup) + { + _lookup = lookup; + } + + public bool GetIsValid(ModuleInfoExtended module) + { + if (FeatureIds.LauncherFeatures.Contains(module.Id)) + return true; + + return _lookup[module.Id].IsValid; + } + public bool GetIsSelected(ModuleInfoExtended module) + { + if (FeatureIds.LauncherFeatures.Contains(module.Id)) + return false; + + return _lookup[module.Id].IsSelected; + } + public void SetIsSelected(ModuleInfoExtended module, bool value) + { + if (FeatureIds.LauncherFeatures.Contains(module.Id)) + return; + _lookup[module.Id].IsSelected = value; + } + public bool GetIsDisabled(ModuleInfoExtended module) + { + if (FeatureIds.LauncherFeatures.Contains(module.Id)) + return false; + + return _lookup[module.Id].IsDisabled; + } + public void SetIsDisabled(ModuleInfoExtended module, bool value) + { + if (FeatureIds.LauncherFeatures.Contains(module.Id)) + return; + _lookup[module.Id].IsDisabled = value; + } +} \ No newline at end of file diff --git a/src/Bannerlord.LauncherManager/Utils/SortHelper.cs b/src/Bannerlord.LauncherManager/Utils/SortHelper.cs index 9d5f9cd..3fd93b9 100644 --- a/src/Bannerlord.LauncherManager/Utils/SortHelper.cs +++ b/src/Bannerlord.LauncherManager/Utils/SortHelper.cs @@ -9,53 +9,6 @@ namespace Bannerlord.LauncherManager.Utils; public static class SortHelper { - private class ModuleContext where TModuleViewModel : class, IModuleViewModel - { - private readonly IDictionary _lookup; - public ModuleContext(IEnumerable moduleVMs) - { - _lookup = moduleVMs.ToDictionary(x => x.ModuleInfoExtended.Id, x => x); - } - public ModuleContext(IDictionary lookup) - { - _lookup = lookup; - } - - public bool GetIsValid(ModuleInfoExtended module) - { - if (FeatureIds.LauncherFeatures.Contains(module.Id)) - return true; - - return _lookup[module.Id].IsValid; - } - public bool GetIsSelected(ModuleInfoExtended module) - { - if (FeatureIds.LauncherFeatures.Contains(module.Id)) - return false; - - return _lookup[module.Id].IsSelected; - } - public void SetIsSelected(ModuleInfoExtended module, bool value) - { - if (FeatureIds.LauncherFeatures.Contains(module.Id)) - return; - _lookup[module.Id].IsSelected = value; - } - public bool GetIsDisabled(ModuleInfoExtended module) - { - if (FeatureIds.LauncherFeatures.Contains(module.Id)) - return false; - - return _lookup[module.Id].IsDisabled; - } - public void SetIsDisabled(ModuleInfoExtended module, bool value) - { - if (FeatureIds.LauncherFeatures.Contains(module.Id)) - return; - _lookup[module.Id].IsDisabled = value; - } - } - /// /// External
///
@@ -63,7 +16,7 @@ public static void ToggleModuleSelection(IEnumerable x.ModuleInfoExtended).ToList(); - var ctx = new ModuleContext(lookup); + var ctx = new DefaultModuleContext(lookup); if (moduleVM.IsSelected) ModuleUtilities.DisableModule(modules, moduleVM.ModuleInfoExtended, ctx.GetIsSelected, ctx.SetIsSelected, ctx.GetIsDisabled, ctx.SetIsDisabled); @@ -78,7 +31,7 @@ public static IEnumerable ValidateModule(IEnumerable x.ModuleInfoExtended).Concat(FeatureIds.LauncherFeatures.Select(x => new ModuleInfoExtended { Id = x })).ToList(); - var ctx = new ModuleContext(lookup); + var ctx = new DefaultModuleContext(lookup); return ModuleUtilities.ValidateModule(modules, moduleVM.ModuleInfoExtended, ctx.GetIsSelected, ctx.GetIsValid).Select(ModuleIssueRenderer.Render); }