< Summary

Class:DCL.Builder.Scene
Assembly:LandWIthAccess
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/LandWithAccess/Scene.cs
Covered lines:25
Uncovered lines:35
Coverable lines:60
Total lines:142
Line coverage:41.6% (25 of 60)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Scene()0%2100%
Scene(...)0%11.559068.42%
HasContent(...)0%12300%
TryGetHashForContent(...)0%12300%
SetScene(...)0%2100%
StringToVector2Int(...)0%4.254075%
GetNavmapThumbnailUrl(...)0%19.7511058.33%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Linq;
 3using DCL.Configuration;
 4using UnityEngine;
 5
 6namespace DCL.Builder
 7{
 8    public class Scene
 9    {
 10        public enum Source { BUILDER, BUILDER_IN_WORLD, SDK }
 11
 012        public string title => metadata.display.title;
 013        public string description => metadata.display.description;
 014        public string author => metadata.contact.name;
 015        public string navmapThumbnail => thumbnail;
 016        public Vector2Int @base => baseCoord;
 017        public Vector2Int[] parcels => parcelsCoord;
 018        public string id => entityId;
 019        public Source source => deploymentSource;
 020        public LandWithAccess land => sceneLand;
 021        public string[] requiredPermissions => metadata.requiredPermissions;
 122        public string projectId => metadata.source?.projectId;
 223        public bool isEmpty => metadata.source?.isEmpty ?? false;
 024        public long deployTimestamp => timestamp;
 25
 26        private CatalystSceneEntityMetadata metadata;
 27        internal Source deploymentSource;
 28        private Vector2Int baseCoord;
 29        internal Vector2Int[] parcelsCoord;
 30        private string thumbnail;
 31        private string entityId;
 32
 33        internal LandWithAccess sceneLand;
 34        internal long timestamp;
 35        internal CatalystEntityContent[] contents;
 36
 037        public Scene() { }
 38
 539        public Scene(CatalystSceneEntityPayload pointerData, string contentUrl)
 40        {
 41
 42            const string builderSourceName = "builder";
 43            const string builderInWorldSourceName = "builder-in-world";
 44
 545            metadata = pointerData.metadata;
 546            entityId = pointerData.id;
 47
 548            deploymentSource = Source.SDK;
 49
 550            if (pointerData.content != null && pointerData.content.Any(content => content.file == BIWSettings.BUILDER_SC
 51            {
 052                deploymentSource = Source.BUILDER_IN_WORLD;
 053            }
 554            else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName)
 55            {
 056                deploymentSource = Source.BUILDER_IN_WORLD;
 057            }
 558            else if (metadata.source != null && metadata.source.origin == builderSourceName)
 59            {
 060                deploymentSource = Source.BUILDER;
 61            }
 62
 563            if (pointerData.content != null)
 064                contents = pointerData.content;
 65
 566            baseCoord = StringToVector2Int(metadata.scene.@base);
 567            parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray();
 568            thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl);
 69
 570            timestamp = pointerData.timestamp;
 571        }
 72
 73        public bool HasContent(string name)
 74        {
 075            foreach (CatalystEntityContent content in contents)
 76            {
 077                if (content.file == name)
 078                    return true;
 79            }
 080            return false;
 81        }
 82
 83        public bool TryGetHashForContent(string name, out string hash)
 84        {
 085            hash = null;
 086            foreach (CatalystEntityContent content in contents)
 87            {
 088                if (content.file == name)
 89                {
 090                    hash = content.hash;
 091                    return true;
 92                }
 93            }
 094            return false;
 95        }
 96
 097        public void SetScene(LandWithAccess land) { sceneLand = land; }
 98
 99        static Vector2Int StringToVector2Int(string coords)
 100        {
 10101            string[] coordSplit = coords.Split(',');
 10102            if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int 
 103            {
 10104                return new Vector2Int(x, y);
 105            }
 106
 0107            return Vector2Int.zero;
 108        }
 109
 110        static string GetNavmapThumbnailUrl(CatalystSceneEntityPayload pointerData, string contentUrl)
 111        {
 112            const string contentDownloadUrlFormat = "{0}/contents/{1}";
 113            const string builderUrlFormat = "https://builder-api.decentraland.org/v1/projects/{0}/media/preview.png";
 114
 5115            string thumbnail = pointerData.metadata.display.navmapThumbnail;
 116
 5117            bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail);
 5118            bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http");
 119
 5120            if (isThumbnailPresent && !isThumbnailFileDeployed)
 121            {
 0122                return thumbnail;
 123            }
 124
 5125            if (isThumbnailFileDeployed && pointerData.content != null)
 126            {
 0127                string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash;
 0128                if (!string.IsNullOrEmpty(thumbnailHash))
 129                {
 0130                    return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash);
 131                }
 132            }
 133
 5134            if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId))
 135            {
 0136                return string.Format(builderUrlFormat, pointerData.metadata.source.projectId);
 137            }
 138
 5139            return thumbnail;
 140        }
 141    }
 142}