-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #583 from Mutagen-Modding/env-asset-provider
Env asset provider
- Loading branch information
Showing
17 changed files
with
474 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
Mutagen.Bethesda.Core/Archives/DI/CachedArchiveListingDetailsProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Mutagen.Bethesda.Plugins.Order.DI; | ||
using Noggog; | ||
|
||
namespace Mutagen.Bethesda.Archives.DI; | ||
|
||
public class CachedArchiveListingDetailsProvider : IArchiveListingDetailsProvider | ||
{ | ||
private readonly ILoadOrderListingsProvider _listingsProvider; | ||
private readonly IGetArchiveIniListings _getArchiveIniListings; | ||
private readonly Lazy<Payload> _payload; | ||
|
||
private class Payload | ||
{ | ||
public required IReadOnlyList<FileName> Listed { get; init; } | ||
public required IReadOnlyList<FileName> Priority { get; init; } | ||
public required IReadOnlySet<FileName> Set { get; init; } | ||
} | ||
|
||
public CachedArchiveListingDetailsProvider( | ||
ILoadOrderListingsProvider listingsProvider, | ||
IGetArchiveIniListings getArchiveIniListings) | ||
{ | ||
_listingsProvider = listingsProvider; | ||
_getArchiveIniListings = getArchiveIniListings; | ||
_payload = new Lazy<Payload>(() => | ||
{ | ||
var listed = new List<FileName>(); | ||
listed.AddRange(_getArchiveIniListings.TryGet().EmptyIfNull()); | ||
listed.AddRange(_listingsProvider.Get() | ||
.Where(x => x.Enabled) | ||
.Select(x => x.ModKey) | ||
.Select(x => x.FileName)); | ||
return new Payload() | ||
{ | ||
Listed = listed, | ||
Priority = ((IEnumerable<FileName>)listed).Reverse().ToList(), | ||
Set = listed.ToHashSet(), | ||
}; | ||
}); | ||
} | ||
|
||
public bool Empty => _payload.Value.Listed.Count == 0; | ||
|
||
public int PriorityIndexFor(FileName fileName) | ||
{ | ||
return _payload.Value.Priority.IndexOf(fileName); | ||
} | ||
|
||
public bool Contains(FileName fileName) | ||
{ | ||
return _payload.Value.Set.Contains(fileName); | ||
} | ||
} |
Oops, something went wrong.