Skip to content

Commit

Permalink
Added GetAllModules
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Apr 25, 2024
1 parent 1990801 commit af410a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/Bannerlord.LauncherManager/LauncherManagerHandler.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ partial class LauncherManagerHandler
protected static IEnumerable<ModuleInfoExtended> GetLauncherFeatures() =>
FeatureIds.LauncherFeatures.Select(x => new ModuleInfoExtended { Id = x, IsSingleplayerModule = true });

private List<ModuleInfoExtendedWithMetadata>? _modules;
private List<ModuleInfoExtendedWithMetadata> _modules;
private List<ModuleInfoExtendedWithMetadata>? _allModules;

/// <summary>
/// Internal<br/>
Expand All @@ -28,7 +29,30 @@ protected static IEnumerable<ModuleInfoExtended> GetLauncherFeatures() =>
/// <summary>
/// Internal<br/>
/// </summary>
protected internal IReadOnlyList<ModuleInfoExtendedWithMetadata> GetModules() => _modules ??= ReloadModules().GroupBy(x => x.Id).Select(x => x.First()).ToList();
protected internal IReadOnlyList<ModuleInfoExtendedWithMetadata> GetModules()
{
if (_allModules is null)
{
_allModules = ReloadModules().ToList();
_modules = _allModules.GroupBy(x => x.Id).Select(x => x.First()).ToList();
}

return _modules;
}

/// <summary>
/// Internal<br/>
/// </summary>
protected internal IReadOnlyList<ModuleInfoExtendedWithMetadata> GetAllModules()
{
if (_allModules is null)
{
_allModules = ReloadModules().ToList();
_modules = _allModules.GroupBy(x => x.Id).Select(x => x.First()).ToList();
}

return _allModules;
}

/// <summary>
/// Internal<br/>
Expand Down
3 changes: 2 additions & 1 deletion src/Bannerlord.LauncherManager/LauncherManagerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public LauncherManagerHandler(ILauncherStateProvider launcherStateProvider, IGam
/// </summary>
public void RefreshModules()
{
_modules = null;
_modules.Clear();
_allModules = null;
ExtendedModuleInfoCache = GetLauncherFeatures().Concat(GetModules()).ToDictionary(x => x.Id, x => x);
}

Expand Down

0 comments on commit af410a8

Please sign in to comment.