< Summary

Class:DCL.ECSComponents.Utils.UITextureUpdater
Assembly:DCL.ECSComponents.UIComponentsUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/UIComponentsUtils/UITextureUpdater.cs
Covered lines:0
Uncovered lines:21
Coverable lines:21
Total lines:57
Line coverage:0% (0 of 21)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UITextureUpdater(...)0%2100%
Update(...)0%12300%
OnTextureDownloaded(...)0%2100%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/UIComponentsUtils/UITextureUpdater.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.UIElements.Image;
 3using Decentraland.Common;
 4using JetBrains.Annotations;
 5
 6namespace DCL.ECSComponents.Utils
 7{
 8    public struct UITextureUpdater
 9    {
 10        private TextureUnion lastTexture;
 11
 12        private AssetPromise_Texture lastPromise;
 13        private readonly IUITextureConsumer target;
 14        private readonly AssetPromiseKeeper_Texture texturePromiseKeeper;
 15
 16        public UITextureUpdater(IUITextureConsumer target, AssetPromiseKeeper_Texture texturePromiseKeeper)
 17        {
 018            this.target = target;
 019            this.texturePromiseKeeper = texturePromiseKeeper;
 020            lastPromise = null;
 021            lastTexture = null;
 022        }
 23
 24        public void Update([CanBeNull] TextureUnion texture, IParcelScene parcelScene)
 25        {
 026            if (Equals(lastTexture, texture))
 027                return;
 28
 029            lastTexture = texture;
 30
 031            var prevPromise = lastPromise;
 032            texturePromiseKeeper.Forget(prevPromise);
 33
 034            if (texture == null)
 35            {
 036                target.Texture = null;
 037                lastPromise = null;
 38            }
 39            else
 40            {
 041                lastPromise = new AssetPromise_Texture(texture.GetTextureUrl(parcelScene), texture.GetWrapMode(), textur
 042                lastPromise.OnSuccessEvent += OnTextureDownloaded;
 043                texturePromiseKeeper.Keep(lastPromise);
 44            }
 045        }
 46
 47        private void OnTextureDownloaded(Asset_Texture texture)
 48        {
 049            target.Texture = texture.texture;
 050        }
 51
 52        public void Dispose()
 53        {
 054            texturePromiseKeeper.Forget(lastPromise);
 055        }
 56    }
 57}