< Summary

Class:DeployedScenesFetcher
Assembly:DeployedScenesFetcher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/DeployedScenesFetcher.cs
Covered lines:10
Uncovered lines:38
Coverable lines:48
Total lines:112
Line coverage:20.8% (10 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FetchScenes(...)0%2100%
FetchLandsFromOwner(...)0%220100%
GetLands(...)0%6200%
ProcessLand(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/DeployedScenesFetcher.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL;
 4using DCL.Builder;
 5using DCL.Helpers;
 6using UnityEngine;
 7
 8public static class DeployedScenesFetcher
 9{
 10    private const float DEFAULT_SCENES_CACHE_TIME = 3 * 60;
 11    private const float DEFAULT_LAND_CACHE_TIME = 5 * 60;
 12
 13    public static Promise<Scene[]> FetchScenes(ICatalyst catalyst, string[] parcels, float cacheMaxAgeSeconds = DEFAULT_
 14    {
 015        Promise<Scene[]> promise = new Promise<Scene[]>();
 016        catalyst.GetDeployedScenes(parcels, cacheMaxAgeSeconds)
 17            .Then(result =>
 18            {
 019                promise.Resolve(result.Select(deployment => new Scene(deployment, catalyst.contentUrl)).ToArray());
 020            })
 021            .Catch(err => promise.Reject(err));
 022        return promise;
 23    }
 24
 25    public static Promise<LandWithAccess[]> FetchLandsFromOwner(ICatalyst catalyst, ITheGraph theGraph, string ethAddres
 26        float cacheMaxAgeSecondsLand = DEFAULT_LAND_CACHE_TIME, float cacheMaxAgeSecondsScenes = DEFAULT_SCENES_CACHE_TI
 27    {
 628        Promise<LandWithAccess[]> resultPromise = new Promise<LandWithAccess[]>();
 29
 630        List<Land> lands = new List<Land>();
 31
 632        Promise<string[]> getOwnedParcelsPromise = new Promise<string[]>();
 633        Promise<Scene[]> getDeployedScenesPromise = new Promise<Scene[]>();
 34
 635        var queryLandsPromise = theGraph.QueryLands(network, ethAddress, cacheMaxAgeSecondsLand);
 36
 637        if ( queryLandsPromise != null )
 38        {
 439            queryLandsPromise.Then(landsReceived =>
 40                {
 041                    lands = landsReceived;
 42
 043                    List<string> parcels = new List<string>();
 044                    for (int i = 0; i < landsReceived.Count; i++)
 45                    {
 046                        if (landsReceived[i].parcels == null)
 47                            continue;
 48
 049                        parcels.AddRange(landsReceived[i].parcels.Select(parcel => $"{parcel.x},{parcel.y}"));
 50                    }
 51
 052                    getOwnedParcelsPromise.Resolve(parcels.ToArray());
 053                })
 054                .Catch(err => getOwnedParcelsPromise.Reject(err));
 55        }
 56
 657        getOwnedParcelsPromise.Then(parcels =>
 58            {
 059                if (parcels.Length > 0)
 60                {
 061                    FetchScenes(catalyst, parcels, cacheMaxAgeSecondsScenes)
 062                        .Then(scenes => getDeployedScenesPromise.Resolve(scenes))
 063                        .Catch(err => getDeployedScenesPromise.Reject(err));
 064                }
 65                else
 66                {
 067                    getDeployedScenesPromise.Resolve(new Scene[] { });
 68                }
 069            })
 070            .Catch(err => getDeployedScenesPromise.Reject(err));
 71
 672        getDeployedScenesPromise.Then(scenes =>
 73            {
 074                resultPromise.Resolve(GetLands(lands, scenes));
 075            })
 076            .Catch(err => resultPromise.Reject(err));
 77
 678        return resultPromise;
 79    }
 80
 81    private static LandWithAccess[] GetLands(List<Land> lands, Scene[] scenes)
 82    {
 083        LandWithAccess[] result = new LandWithAccess[lands.Count];
 84
 085        for (int i = 0; i < lands.Count; i++)
 86        {
 087            result[i] = ProcessLand(lands[i], scenes);
 88        }
 89
 090        return result;
 91    }
 92
 93    private static LandWithAccess ProcessLand(Land land, Scene[] scenes)
 94    {
 095        List<Scene> scenesInLand = new List<Scene>();
 96
 097        LandWithAccess result = new LandWithAccess(land);
 098        for (int i = 0; i < result.parcels.Length; i++)
 99        {
 0100            Scene sceneInParcel = scenes.FirstOrDefault(scene => scene.parcels.Contains(result.parcels[i]) && !scenesInL
 0101            if (sceneInParcel != null)
 102            {
 0103                sceneInParcel.SetScene(result);
 0104                scenesInLand.Add(sceneInParcel);
 105            }
 106        }
 107
 0108        result.scenes = scenesInLand;
 109
 0110        return result;
 111    }
 112}