< Summary

Class:MapTexturePlugin
Assembly:MapTexturePlugin
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/MapTexturePlugin/MapTexturePlugin.cs
Covered lines:0
Uncovered lines:24
Coverable lines:24
Total lines:69
Line coverage:0% (0 of 24)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MapTexturePlugin(...)0%2100%
DownloadTexture()0%1321100%
Dispose()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/MapTexturePlugin/MapTexturePlugin.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4using DCL;
 5using DCL.Providers;
 6using UnityEngine;
 7using UnityEngine.Experimental.Rendering;
 8using UnityEngine.Networking;
 9
 10public class MapTexturePlugin : IPlugin
 11{
 12    private readonly IAddressableResourceProvider resourceProvider;
 13
 14    private const int RETRY_TIME = 10;
 15    private const string MAIN_TEXTURE_URL = "https://api.decentraland.org/v1/minimap.png";
 16    private const string ESTATES_TEXTURE_URL = "https://api.decentraland.org/v1/estatemap.png";
 17
 18    private CancellationTokenSource cts;
 19
 020    public MapTexturePlugin(IAddressableResourceProvider resourceProvider)
 21    {
 022        cts = new CancellationTokenSource();
 23
 024        this.resourceProvider = resourceProvider;
 25
 026        DownloadTexture(MAIN_TEXTURE_URL, DataStore.i.HUDs.latestDownloadedMainTexture, cts.Token, "MapDefault").Forget(
 027        DownloadTexture(ESTATES_TEXTURE_URL, DataStore.i.HUDs.latestDownloadedMapEstatesTexture, cts.Token, "MapDefaultE
 028    }
 29
 30    private async UniTaskVoid DownloadTexture(string url, IBaseVariable<Texture> textureVariable, CancellationToken ct, 
 31    {
 032        var texture = await resourceProvider.GetAddressable<Texture2D>(textureName, ct);
 033        textureVariable.Set(texture);
 34
 035        while (true)
 36        {
 037            using (UnityWebRequest www = UnityWebRequest.Get(url))
 38            {
 039                await www.SendWebRequest();
 040                if (www.error != null)
 41                {
 042                    Debug.LogException(new Exception(www.error));
 43                }
 44                else
 45                {
 046                    Texture2D tex = new Texture2D(0, 0, GraphicsFormatUtility.GetGraphicsFormat(TextureFormat.RGBA32, fa
 47                        {
 48                            filterMode = FilterMode.Point,
 49                            wrapMode = TextureWrapMode.Clamp,
 50                        };
 51
 052                    tex.LoadImage(www.downloadHandler.data);
 053                    tex.Apply(false, false);
 054                    textureVariable.Set(tex);
 055                    return;
 56                }
 057            }
 58
 59            // We retry in 10 seconds
 060            await UniTask.Delay(TimeSpan.FromSeconds(RETRY_TIME), cancellationToken: ct).AttachExternalCancellation(ct);
 61        }
 062    }
 63
 64    public void Dispose()
 65    {
 066        cts?.Cancel();
 067        cts?.Dispose();
 068    }
 69}