< Summary

Class:DCL.AssetPromise_Gif
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Gif/AssetPromise_Gif.cs
Covered lines:25
Uncovered lines:3
Coverable lines:28
Total lines:72
Line coverage:89.2% (25 of 28)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetPromise_Gif(...)0%110100%
GetId()0%110100%
OnLoad(...)0%110100%
GetGifProcessor()0%2.152066.67%
OnLoadSuccsess(...)0%220100%
OnCancelLoading()0%110100%
AddToLibrary()0%2.262060%
OnBeforeLoadOrReuse()0%110100%
OnAfterLoadOrReuse()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/Gif/AssetPromise_Gif.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4using UnityEngine;
 5
 6namespace DCL
 7{
 8    public class AssetPromise_Gif : AssetPromise<Asset_Gif>
 9    {
 10        private readonly string url;
 11        private Action onSuccsess;
 12        private CancellationTokenSource tokenSource;
 13        private bool jsGIFProcessingEnabled;
 14
 1515        public AssetPromise_Gif(string url)
 16        {
 3017            KernelConfig.i.EnsureConfigInitialized().Then(config => jsGIFProcessingEnabled = config.gifSupported);
 1518            this.url = url;
 1519        }
 20
 7521        public override object GetId() { return url; }
 22
 23        protected override void OnLoad(Action OnSuccess, Action<Exception> OnFail)
 24        {
 1225            tokenSource = new CancellationTokenSource();
 1226            IGifProcessor processor = GetGifProcessor();
 1227            onSuccsess = OnSuccess;
 1228            asset.processor = processor;
 1229            CancellationToken token = tokenSource.Token;
 30
 1231            processor.Load(OnLoadSuccsess, OnFail, token)
 32                     .AttachExternalCancellation(token)
 33                     .Forget();
 1234        }
 35
 36        private IGifProcessor GetGifProcessor()
 37        {
 1238            if (jsGIFProcessingEnabled)
 39            {
 040                return new JSGifProcessor(url);
 41            }
 42
 1243            return new GifDecoderProcessor(url, Environment.i.platform.webRequest);
 44        }
 45        private void OnLoadSuccsess(GifFrameData[] frames)
 46        {
 647            asset.frames = frames;
 648            onSuccsess?.Invoke();
 649        }
 50        protected override void OnCancelLoading()
 51        {
 652            tokenSource.Cancel();
 653            tokenSource.Dispose();
 654        }
 55
 56        protected override bool AddToLibrary()
 57        {
 658            if (!library.Add(asset))
 59            {
 060                Debug.Log("add to library fail?");
 061                return false;
 62            }
 63
 664            asset = library.Get(asset.id);
 665            return true;
 66        }
 67
 1568        protected override void OnBeforeLoadOrReuse() { }
 69
 970        protected override void OnAfterLoadOrReuse() { }
 71    }
 72}