< Summary

Class:PlayerInfoCollectibleItem
Assembly:PlayerInfoCardHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCollectibleItem.cs
Covered lines:4
Uncovered lines:20
Coverable lines:24
Total lines:62
Line coverage:16.6% (4 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%3.333066.67%
OnEnable()0%6200%
OnDisable()0%20400%
GetThumbnail()0%2100%
ForgetThumbnail()0%2100%
OnThumbnailReady(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCollectibleItem.cs

#LineLine coverage
 1using DCL;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public class PlayerInfoCollectibleItem : MonoBehaviour
 6{
 7    [SerializeField] private Image thumbnail;
 8
 9    internal WearableItem collectible;
 10    private AssetPromise_Texture thumbnailPromise;
 11    private bool finishedLoading = false;
 12
 13    public void Initialize(WearableItem collectible)
 14    {
 15015        this.collectible = collectible;
 16
 15017        if (this.collectible == null)
 018            return;
 19
 15020        if (gameObject.activeInHierarchy)
 021            GetThumbnail();
 15022    }
 23
 24    private void OnEnable()
 25    {
 026        if (collectible == null)
 027            return;
 28
 029        GetThumbnail();
 030    }
 31
 32    private void OnDisable()
 33    {
 034        if (collectible != null)
 35        {
 036            ForgetThumbnail();
 37
 038            if (thumbnail.sprite != null && finishedLoading)
 039                Destroy(thumbnail.sprite);
 40        }
 041    }
 42
 43    private void GetThumbnail()
 44    {
 045        string url = collectible.ComposeThumbnailUrl();
 46        //NOTE(Brian): Get before forget to prevent referenceCount == 0 and asset unload
 047        var newThumbnailPromise = ThumbnailsManager.GetThumbnail(url, OnThumbnailReady);
 048        ForgetThumbnail();
 049        thumbnailPromise = newThumbnailPromise;
 050    }
 51
 052    private void ForgetThumbnail() { ThumbnailsManager.ForgetThumbnail(thumbnailPromise); }
 53
 54    private void OnThumbnailReady(Asset_Texture texture)
 55    {
 56        // we override the previously stored placeholder image (a referenced asset), we don't destroy it as it
 57        // references the asset and it will provoke a "Destroying assets is not permitted to avoid data loss" error
 058        thumbnail.sprite = ThumbnailsManager.CreateSpriteFromTexture(texture.texture);
 59
 060        finishedLoading = true;
 061    }
 62}