< Summary

Class:DCL.AssetPromise_Gif
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Gif/AssetPromise_Gif.cs
Covered lines:34
Uncovered lines:4
Coverable lines:38
Total lines:98
Line coverage:89.4% (34 of 38)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:11
Method coverage:100% (11 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetPromise_Gif(...)0%110100%
GetId()0%110100%
OnLoad(...)0%22090.91%
OnLoadFail(...)0%110100%
GetGifProcessor()0%2.152066.67%
OnLoadSuccsess(...)0%220100%
OnCancelLoading()0%110100%
AddToLibrary()0%2.262060%
OnBeforeLoadOrReuse()0%110100%
OnAfterLoadOrReuse()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Gif/AssetPromise_Gif.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4using UnityEngine;
 5
 6namespace DCL
 7{
 8    public class AssetPromise_Gif : AssetPromise<Asset_Gif>
 9    {
 10        private readonly string url;
 11        private Action onSuccsess;
 12        private Action<Exception> onFail;
 13        private CancellationTokenSource tokenSource;
 14        private bool jsGIFProcessingEnabled;
 15        private bool isLoading = false;
 16
 1517        public AssetPromise_Gif(string url)
 18        {
 3019            KernelConfig.i.EnsureConfigInitialized().Then(config => jsGIFProcessingEnabled = config.gifSupported);
 1520            this.url = url;
 1521        }
 22
 7523        public override object GetId() { return url; }
 24
 25        protected override void OnLoad(Action OnSuccess, Action<Exception> OnFail)
 26        {
 1227            tokenSource = new CancellationTokenSource();
 28            IGifProcessor processor;
 29
 1230            if (asset.processor == null)
 31            {
 1232                processor = GetGifProcessor();
 1233                asset.processor = processor;
 34            }
 35            else
 36            {
 037                processor = asset.processor;
 38            }
 1239            onSuccsess = OnSuccess;
 1240            onFail = OnFail;
 41
 1242            CancellationToken token = tokenSource.Token;
 43
 1244            isLoading = true;
 45
 1246            processor.Load(OnLoadSuccsess, OnLoadFail, token)
 47                     .AttachExternalCancellation(token)
 48                     .Forget();
 1249        }
 50
 51        private void OnLoadFail(Exception exception)
 52        {
 353            isLoading = false;
 354            onFail(exception);
 355        }
 56
 57        private IGifProcessor GetGifProcessor()
 58        {
 1259            if (jsGIFProcessingEnabled)
 60            {
 061                return new JSGifProcessor(url);
 62            }
 63
 1264            return new GifDecoderProcessor(url, Environment.i.platform.webRequest);
 65        }
 66
 14467        public override bool keepWaiting => isLoading;
 68
 69        private void OnLoadSuccsess(GifFrameData[] frames)
 70        {
 671            isLoading = false;
 672            asset.frames = frames;
 673            onSuccsess?.Invoke();
 674        }
 75        protected override void OnCancelLoading()
 76        {
 677            isLoading = false;
 678            tokenSource.Cancel();
 679            tokenSource.Dispose();
 680        }
 81
 82        protected override bool AddToLibrary()
 83        {
 684            if (!library.Add(asset))
 85            {
 086                Debug.Log("add to library fail?");
 087                return false;
 88            }
 89
 690            asset = library.Get(asset.id);
 691            return true;
 92        }
 93
 1594        protected override void OnBeforeLoadOrReuse() { }
 95
 996        protected override void OnAfterLoadOrReuse() { }
 97    }
 98}