< Summary

Class:CatalogAssetPackAdapter
Assembly:BuilderInWorldCatalog
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Catalog/UI/Adapters/CatalogAssetPackAdapter.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:72
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetContent(...)0%6200%
GetThumbnail()0%42600%
SetThumbnail(...)0%6200%
SceneAssetPackClick()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Catalog/UI/Adapters/CatalogAssetPackAdapter.cs

#LineLine coverage
 1using DCL;
 2using DCL.Configuration;
 3using System;
 4using System.Collections;
 5using System.Collections.Generic;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class CatalogAssetPackAdapter : MonoBehaviour
 11{
 12    public TextMeshProUGUI titleTxt;
 13    public RawImage packImg;
 14    public Texture collectiblesSprite;
 15
 16    public event Action<CatalogItemPack> OnCatalogItemPackClick;
 17    CatalogItemPack catalogItemPack;
 18
 19    string loadedThumbnailURL;
 20    AssetPromise_Texture loadedThumbnailPromise;
 21    public void SetContent(CatalogItemPack catalogItemPack)
 22    {
 023        this.catalogItemPack = catalogItemPack;
 024        titleTxt.text = this.catalogItemPack.title;
 25
 026        if (catalogItemPack.id != BIWSettings.ASSETS_COLLECTIBLES)
 27        {
 028            GetThumbnail();
 029        }
 30        else
 31        {
 032            packImg.enabled = true;
 033            packImg.texture = collectiblesSprite;
 34        }
 035    }
 36
 37    private void GetThumbnail()
 38    {
 039        var url = catalogItemPack?.GetThumbnailUrl();
 40
 041        if (url == loadedThumbnailURL)
 042            return;
 43
 044        if (catalogItemPack == null || string.IsNullOrEmpty(url))
 045            return;
 46
 047        string newLoadedThumbnailURL = url;
 048        var newLoadedThumbnailPromise = new AssetPromise_Texture(url);
 49
 50
 051        newLoadedThumbnailPromise.OnSuccessEvent += SetThumbnail;
 052        newLoadedThumbnailPromise.OnFailEvent += (x, error) => { Debug.Log($"Error downloading: {url}, Exception: {error
 53
 054        AssetPromiseKeeper_Texture.i.Keep(newLoadedThumbnailPromise);
 55
 56
 057        AssetPromiseKeeper_Texture.i.Forget(loadedThumbnailPromise);
 058        loadedThumbnailPromise = newLoadedThumbnailPromise;
 059        loadedThumbnailURL = newLoadedThumbnailURL;
 060    }
 61
 62    public void SetThumbnail(Asset_Texture texture)
 63    {
 064        if (packImg != null)
 65        {
 066            packImg.enabled = true;
 067            packImg.texture = texture.texture;
 68        }
 069    }
 70
 071    public void SceneAssetPackClick() { OnCatalogItemPackClick?.Invoke(catalogItemPack); }
 72}