< 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:0
Uncovered lines:54
Coverable lines:54
Total lines:133
Line coverage:0% (0 of 54)
Covered branches:0
Total branches:0

Metrics

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

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, 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;
 022        public string projectId => metadata.source?.projectId;
 023        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
 039        public Scene(CatalystSceneEntityPayload pointerData, string contentUrl)
 40        {
 41
 42            const string builderSourceName = "builder";
 43
 044            metadata = pointerData.metadata;
 045            entityId = pointerData.id;
 46
 047            deploymentSource = Source.SDK;
 48
 049            if (metadata.source != null && metadata.source.origin == builderSourceName)
 50            {
 051                deploymentSource = Source.BUILDER;
 52            }
 53
 054            if (pointerData.content != null)
 055                contents = pointerData.content;
 56
 057            baseCoord = StringToVector2Int(metadata.scene.@base);
 058            parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray();
 059            thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl);
 60
 061            timestamp = pointerData.timestamp;
 062        }
 63
 64        public bool HasContent(string name)
 65        {
 066            foreach (CatalystEntityContent content in contents)
 67            {
 068                if (content.file == name)
 069                    return true;
 70            }
 071            return false;
 72        }
 73
 74        public bool TryGetHashForContent(string name, out string hash)
 75        {
 076            hash = null;
 077            foreach (CatalystEntityContent content in contents)
 78            {
 079                if (content.file == name)
 80                {
 081                    hash = content.hash;
 082                    return true;
 83                }
 84            }
 085            return false;
 86        }
 87
 088        public void SetScene(LandWithAccess land) { sceneLand = land; }
 89
 90        static Vector2Int StringToVector2Int(string coords)
 91        {
 092            string[] coordSplit = coords.Split(',');
 093            if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int 
 94            {
 095                return new Vector2Int(x, y);
 96            }
 97
 098            return Vector2Int.zero;
 99        }
 100
 101        static string GetNavmapThumbnailUrl(CatalystSceneEntityPayload pointerData, string contentUrl)
 102        {
 103            const string contentDownloadUrlFormat = "{0}/contents/{1}";
 104            const string builderUrlFormat = "https://builder-api.decentraland.org/v1/projects/{0}/media/preview.png";
 105
 0106            string thumbnail = pointerData.metadata.display.navmapThumbnail;
 107
 0108            bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail);
 0109            bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http");
 110
 0111            if (isThumbnailPresent && !isThumbnailFileDeployed)
 112            {
 0113                return thumbnail;
 114            }
 115
 0116            if (isThumbnailFileDeployed && pointerData.content != null)
 117            {
 0118                string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash;
 0119                if (!string.IsNullOrEmpty(thumbnailHash))
 120                {
 0121                    return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash);
 122                }
 123            }
 124
 0125            if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId))
 126            {
 0127                return string.Format(builderUrlFormat, pointerData.metadata.source.projectId);
 128            }
 129
 0130            return thumbnail;
 131        }
 132    }
 133}