< Summary

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

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using DCL;
 3using UnityEngine;
 4
 5namespace NFTShape_Internal
 6{
 7    public class NFTAsset_Image : INFTAsset
 8    {
 9        private const int RESOLUTION_HQ = 1024;
 010        public bool isHQ => hqTexture != null;
 011        public ITexture previewAsset { get; }
 012        public ITexture hqAsset => hqTexture?.asset;
 13
 14        private AssetPromise_Texture hqTexture;
 15        public event Action<Texture2D> OnTextureUpdate;
 16
 017        public NFTAsset_Image(Asset_Texture previewTexture)
 18        {
 019            previewAsset = previewTexture;
 020        }
 21
 22        public void Dispose()
 23        {
 024            if (hqTexture == null)
 025                return;
 26
 027            AssetPromiseKeeper_Texture.i.Forget(hqTexture);
 028            hqTexture = null;
 029            OnTextureUpdate = null;
 030        }
 31
 32        public void FetchAndSetHQAsset(string url, Action onSuccess, Action<Exception> onFail)
 33        {
 034            string finalUrl = $"{url}=s{RESOLUTION_HQ}";
 035            hqTexture = new AssetPromise_Texture($"{finalUrl}");
 36
 037            hqTexture.OnSuccessEvent += asset =>
 38            {
 039                OnTextureUpdate?.Invoke(asset.texture);
 040                onSuccess?.Invoke();
 041            };
 042            hqTexture.OnFailEvent += (asset, error) =>
 43            {
 044                hqTexture = null;
 045                onFail?.Invoke(error);
 046            };
 47
 048            AssetPromiseKeeper_Texture.i.Keep(hqTexture);
 049        }
 50
 51        public void RestorePreviewAsset()
 52        {
 053            if (hqTexture != null)
 54            {
 055                AssetPromiseKeeper_Texture.i.Forget(hqTexture);
 056                hqTexture = null;
 57            }
 58
 059            OnTextureUpdate?.Invoke(previewAsset.texture);
 060        }
 61    }
 62}