< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FetchScenes(...)0%2100%
FetchLandsFromOwner(...)0%6200%
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    {
 028        Promise<LandWithAccess[]> resultPromise = new Promise<LandWithAccess[]>();
 29
 030        List<Land> lands = new List<Land>();
 31
 032        Promise<string[]> getOwnedParcelsPromise = new Promise<string[]>();
 033        Promise<Scene[]> getDeployedScenesPromise = new Promise<Scene[]>();
 34
 035        var queryLandsPromise = theGraph.QueryLands(network, ethAddress, cacheMaxAgeSecondsLand);
 36
 037        if ( queryLandsPromise != null )
 38        {
 039            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
 057        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));
 64                }
 65                else
 66                {
 067                    getDeployedScenesPromise.Resolve(new Scene[] { });
 68                }
 069            })
 070            .Catch(err => getDeployedScenesPromise.Reject(err));
 71
 072        getDeployedScenesPromise.Then(scenes =>
 73            {
 074                resultPromise.Resolve(GetLands(lands, scenes));
 075            })
 076            .Catch(err => resultPromise.Reject(err));
 77
 078        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}