diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs index 05d831b57..1476ce2e6 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/ImGuiWidget.cs @@ -364,7 +364,7 @@ internal class ImGuiWidget : IDataWindowWidget public static readonly string[] AssetSources = Enum.GetValues() - .Where(x => x.GetAttribute()?.Purpose is DalamudAssetPurpose.TextureFromPng) + .Where(x => x.GetPurpose() is DalamudAssetPurpose.TextureFromPng) .Select(Enum.GetName) .ToArray(); diff --git a/Dalamud/Storage/Assets/DalamudAssetExtensions.cs b/Dalamud/Storage/Assets/DalamudAssetExtensions.cs index 9181f1a5d..9052a1c6d 100644 --- a/Dalamud/Storage/Assets/DalamudAssetExtensions.cs +++ b/Dalamud/Storage/Assets/DalamudAssetExtensions.cs @@ -1,4 +1,7 @@ -using Dalamud.Utility; +using System.Collections.Frozen; +using System.Collections.Generic; + +using Dalamud.Utility; namespace Dalamud.Storage.Assets; @@ -7,11 +10,37 @@ namespace Dalamud.Storage.Assets; /// public static class DalamudAssetExtensions { + private static readonly FrozenDictionary AttributeCache = CreateCache(); + /// /// Gets the purpose. /// /// The asset. /// The purpose. - public static DalamudAssetPurpose GetPurpose(this DalamudAsset asset) => - asset.GetAttribute()?.Purpose ?? DalamudAssetPurpose.Empty; + public static DalamudAssetPurpose GetPurpose(this DalamudAsset asset) + { + return GetAssetAttribute(asset)?.Purpose ?? DalamudAssetPurpose.Empty; + } + + /// + /// Gets the attribute. + /// + /// The asset. + /// The attribute. + internal static DalamudAssetAttribute? GetAssetAttribute(this DalamudAsset asset) + { + return AttributeCache.GetValueOrDefault(asset); + } + + private static FrozenDictionary CreateCache() + { + var dict = new Dictionary(); + + foreach (var asset in Enum.GetValues()) + { + dict.Add(asset, asset.GetAttribute()); + } + + return dict.ToFrozenDictionary(); + } } diff --git a/Dalamud/Storage/Assets/DalamudAssetManager.cs b/Dalamud/Storage/Assets/DalamudAssetManager.cs index 0109339fe..f750de64a 100644 --- a/Dalamud/Storage/Assets/DalamudAssetManager.cs +++ b/Dalamud/Storage/Assets/DalamudAssetManager.cs @@ -68,7 +68,7 @@ internal sealed class DalamudAssetManager : IInternalDisposableService, IDalamud Task.WhenAll( Enum.GetValues() .Where(x => x is not DalamudAsset.Empty4X4) - .Where(x => x.GetAttribute()?.Required is true) + .Where(x => x.GetAssetAttribute()?.Required is true) .Select(this.CreateStreamAsync) .Select(x => x.ToContentDisposedTask())) .ContinueWith( @@ -83,7 +83,7 @@ internal sealed class DalamudAssetManager : IInternalDisposableService, IDalamud Task.WhenAll( Enum.GetValues() .Where(x => x is not DalamudAsset.Empty4X4) - .Where(x => x.GetAttribute()?.Required is false) + .Where(x => x.GetAssetAttribute()?.Required is false) .Select(this.CreateStreamAsync) .Select(x => x.ToContentDisposedTask(true))) .ContinueWith(r => Log.Verbose($"Optional assets load state: {r}")); @@ -120,7 +120,7 @@ internal sealed class DalamudAssetManager : IInternalDisposableService, IDalamud /// [Pure] public bool IsStreamImmediatelyAvailable(DalamudAsset asset) => - asset.GetAttribute()?.Data is not null + asset.GetAssetAttribute()?.Data is not null || this.fileStreams[asset]?.IsCompletedSuccessfully is true; /// @@ -140,7 +140,7 @@ internal sealed class DalamudAssetManager : IInternalDisposableService, IDalamud [Pure] public Task CreateStreamAsync(DalamudAsset asset) { - if (asset.GetAttribute() is { Data: { } rawData }) + if (asset.GetAssetAttribute() is { Data: { } rawData }) return Task.FromResult(new MemoryStream(rawData, false)); Task task;