< Summary

Class:NFTShape_Internal.NFTGifAsset
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/Scripts/NFTGifAsset.cs
Covered lines:0
Uncovered lines:29
Coverable lines:29
Total lines:63
Line coverage:0% (0 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NFTGifAsset(...)0%2100%
Dispose()0%6200%
FetchAndSetHQAsset(...)0%2100%
RestorePreviewAsset()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/Scripts/NFTGifAsset.cs

#LineLine coverage
 1using System;
 2using DCL;
 3
 4namespace NFTShape_Internal
 5{
 6    public class NFTGifAsset : INFTAsset
 7    {
 08        public bool isHQ => hqGifPromise != null;
 09        public int hqResolution { get; }
 010        public ITexture previewAsset => previewGif;
 011        public ITexture hqAsset => hqGifPromise?.asset;
 12
 13        private AssetPromise_Gif hqGifPromise;
 14
 15        private readonly GifPlayer gifPlayer;
 16        private readonly Asset_Gif previewGif;
 17
 018        public NFTGifAsset(Asset_Gif previewGif, int hqResolution, GifPlayer gifPlayer)
 19        {
 020            this.previewGif = previewGif;
 021            this.hqResolution = hqResolution;
 022            this.gifPlayer = gifPlayer;
 023        }
 24
 25        public void Dispose()
 26        {
 027            if (hqGifPromise != null)
 28            {
 029                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 030                hqGifPromise = null;
 31            }
 032        }
 33
 34        public void FetchAndSetHQAsset(string url, Action onSuccess, Action<Exception> onFail)
 35        {
 036            hqGifPromise = new AssetPromise_Gif(url);
 37
 038            hqGifPromise.OnSuccessEvent += (asset) =>
 39            {
 040                gifPlayer?.SetGif(asset);
 041                onSuccess?.Invoke();
 042            };
 043            hqGifPromise.OnFailEvent += (asset, error) =>
 44            {
 045                hqGifPromise = null;
 046                onFail?.Invoke(error);
 047            };
 48
 049            AssetPromiseKeeper_Gif.i.Keep(hqGifPromise);
 050        }
 51
 52        public void RestorePreviewAsset()
 53        {
 054            gifPlayer?.SetGif(previewGif);
 55
 056            if (hqGifPromise != null)
 57            {
 058                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 059                hqGifPromise = null;
 60            }
 061        }
 62    }
 63}