| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using MainScripts.DCL.Controllers.AssetManager; |
| | 3 | | using MainScripts.DCL.Controllers.AssetManager.Font; |
| | 4 | | using MainScripts.DCL.Helpers.Utils; |
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Threading; |
| | 8 | | using TMPro; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | namespace DCL |
| | 12 | | { |
| | 13 | | public class FontAssetResolver : AssetResolverBase, IFontAssetResolver |
| | 14 | | { |
| | 15 | | private readonly IReadOnlyDictionary<AssetSource, IFontAssetProvider> providers; |
| | 16 | |
|
| | 17 | | public FontAssetResolver(IReadOnlyDictionary<AssetSource, IFontAssetProvider> providers, DataStore_FeatureFlag f |
| 741 | 18 | | : base(featureFlags) |
| | 19 | | { |
| 741 | 20 | | this.providers = providers; |
| 741 | 21 | | } |
| | 22 | |
|
| | 23 | | public async UniTask<FontResponse> GetFontAsync(AssetSource permittedSources, string url, CancellationToken canc |
| | 24 | | { |
| 33 | 25 | | Exception lastException = null; |
| 33 | 26 | | TMP_FontAsset font = null; |
| | 27 | |
|
| 33 | 28 | | using PoolUtils.ListPoolRent<IFontAssetProvider> permittedSourcesRent = GetPermittedProviders(providers, per |
| 33 | 29 | | List<IFontAssetProvider> permittedProviders = permittedSourcesRent.GetList(); |
| | 30 | |
|
| 99 | 31 | | foreach (IFontAssetProvider provider in permittedProviders) |
| | 32 | | { |
| | 33 | | try |
| | 34 | | { |
| 99 | 35 | | font = await provider.GetFontAsync(url, cancellationToken); |
| | 36 | |
|
| 29 | 37 | | if (font) |
| | 38 | | { |
| | 39 | | // The valid font is retrieved |
| 29 | 40 | | AssetResolverLogger.LogVerbose(featureFlags, LogType.Log, $"Font {url} loaded from {provider}"); |
| 29 | 41 | | break; |
| | 42 | | } |
| | 43 | |
|
| 0 | 44 | | AssetResolverLogger.LogVerbose(featureFlags, LogType.Log, $"Font {url} loaded from {provider} is nul |
| 0 | 45 | | } |
| 4 | 46 | | catch (Exception e) |
| | 47 | | { |
| 4 | 48 | | lastException = e; |
| | 49 | |
|
| 4 | 50 | | AssetResolverLogger.LogVerbose(featureFlags, e); |
| | 51 | |
|
| | 52 | | // Propagate `OperationCanceledException` further as there is no reason to iterate |
| 4 | 53 | | if (e is OperationCanceledException) |
| 4 | 54 | | break; |
| 0 | 55 | | } |
| 0 | 56 | | } |
| | 57 | |
|
| 33 | 58 | | if (font) |
| 29 | 59 | | return new FontResponse(new FontSuccessResponse(font)); |
| | 60 | |
|
| 4 | 61 | | lastException ??= new AssetNotFoundException(permittedSources, url); |
| 4 | 62 | | return new FontResponse(new FontFailResponse(lastException)); |
| 33 | 63 | | } |
| | 64 | | } |
| | 65 | | } |