< Summary

Class:NFTShape_Internal.NFTAsset_Gif
Assembly:DCL.Components.NFT
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTAsset/NFTAsset_Gif.cs
Covered lines:6
Uncovered lines:26
Coverable lines:32
Total lines:74
Line coverage:18.7% (6 of 32)
Covered branches:0
Total branches:0

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using DCL;
 3using UnityEngine;
 4
 5namespace NFTShape_Internal
 6{
 7    public class NFTAsset_Gif : INFTAsset
 8    {
 9        private const int RESOLUTION_HQ = 512;
 010        public bool isHQ => hqGifPromise != null;
 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        public event Action<Texture2D> OnTextureUpdate;
 19
 220        public NFTAsset_Gif(Asset_Gif previewGif)
 21        {
 222            this.previewGif = previewGif;
 223            this.gifPlayer = new GifPlayer(previewGif);
 24
 225            gifPlayer.Play();
 226            gifPlayer.OnFrameTextureChanged += OnFrameTextureChanged;
 227        }
 28
 29        void OnFrameTextureChanged(Texture2D texture)
 30        {
 031            OnTextureUpdate?.Invoke(texture);
 032        }
 33
 34        public void Dispose()
 35        {
 036            if (hqGifPromise != null)
 37            {
 038                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 039                hqGifPromise = null;
 40            }
 41
 042            gifPlayer.Dispose();
 043        }
 44
 45        public void FetchAndSetHQAsset(string url, Action onSuccess, Action<Exception> onFail)
 46        {
 047            hqGifPromise = new AssetPromise_Gif($"{url}=s{RESOLUTION_HQ}");
 48
 049            hqGifPromise.OnSuccessEvent += (asset) =>
 50            {
 051                gifPlayer?.SetGif(asset);
 052                onSuccess?.Invoke();
 053            };
 054            hqGifPromise.OnFailEvent += (asset, error) =>
 55            {
 056                hqGifPromise = null;
 057                onFail?.Invoke(error);
 058            };
 59
 060            AssetPromiseKeeper_Gif.i.Keep(hqGifPromise);
 061        }
 62
 63        public void RestorePreviewAsset()
 64        {
 065            gifPlayer?.SetGif(previewGif);
 66
 067            if (hqGifPromise != null)
 68            {
 069                AssetPromiseKeeper_Gif.i.Forget(hqGifPromise);
 070                hqGifPromise = null;
 71            }
 072        }
 73    }
 74}