< 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:64
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;
 3using UnityEngine;
 4
 5namespace NFTShape_Internal
 6{
 7    public class NFTGifAsset : INFTAsset
 8    {
 09        public bool isHQ => hqGifPromise != null;
 010        public int hqResolution { get; }
 011        public ITexture previewAsset => previewGif;
 012        public ITexture hqAsset => hqGifPromise?.asset;
 13
 14        private AssetPromise_Gif hqGifPromise;
 15
 16        private readonly GifPlayer gifPlayer;
 17        private readonly Asset_Gif previewGif;
 18
 019        public NFTGifAsset(Asset_Gif previewGif, int hqResolution, GifPlayer gifPlayer)
 20        {
 021            this.previewGif = previewGif;
 022            this.hqResolution = hqResolution;
 023            this.gifPlayer = gifPlayer;
 024        }
 25
 26        public void Dispose()
 27        {
 028            if (hqGifPromise != null)
 29            {
 030                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 031                hqGifPromise = null;
 32            }
 033        }
 34
 35        public void FetchAndSetHQAsset(string url, Action onSuccess, Action onFail)
 36        {
 037            hqGifPromise = new AssetPromise_Gif(url);
 38
 039            hqGifPromise.OnSuccessEvent += (asset) =>
 40            {
 041                gifPlayer?.SetGif(asset);
 042                onSuccess?.Invoke();
 043            };
 044            hqGifPromise.OnFailEvent += (asset) =>
 45            {
 046                hqGifPromise = null;
 047                onFail?.Invoke();
 048            };
 49
 050            AssetPromiseKeeper_Gif.i.Keep(hqGifPromise);
 051        }
 52
 53        public void RestorePreviewAsset()
 54        {
 055            gifPlayer?.SetGif(previewGif);
 56
 057            if (hqGifPromise != null)
 58            {
 059                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 060                hqGifPromise = null;
 61            }
 062        }
 63    }
 64}