< 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:26
Uncovered lines:25
Coverable lines:51
Total lines:116
Line coverage:50.9% (26 of 51)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Scene()0%2100%
Scene(...)0%9.638070.59%
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 UnityEngine;
 4
 5namespace DCL.Builder
 6{
 7    public class Scene
 8    {
 9        public enum Source { BUILDER, BUILDER_IN_WORLD, SDK }
 10
 011        public string title => metadata.display.title;
 012        public string description => metadata.display.description;
 013        public string author => metadata.contact.name;
 014        public string navmapThumbnail => thumbnail;
 015        public Vector2Int @base => baseCoord;
 016        public Vector2Int[] parcels => parcelsCoord;
 017        public string id => entityId;
 018        public Source source => deploymentSource;
 019        public LandWithAccess land => sceneLand;
 020        public string[] requiredPermissions => metadata.requiredPermissions;
 121        public string contentRating => metadata.policy?.contentRating;
 022        public bool voiceEnabled => metadata.policy?.voiceEnabled ?? false;
 123        public string[] bannedUsers => metadata.policy?.blacklist;
 124        public string projectId => metadata.source?.projectId;
 225        public bool isEmpty => metadata.source?.isEmpty ?? false;
 026        public long deployTimestamp => timestamp;
 27
 28        private CatalystSceneEntityMetadata metadata;
 29        internal Source deploymentSource;
 30        private Vector2Int baseCoord;
 31        internal Vector2Int[] parcelsCoord;
 32        private string thumbnail;
 33        private string entityId;
 34
 35        internal LandWithAccess sceneLand;
 36        internal long timestamp;
 37
 038        public Scene() { }
 39
 540        public Scene(CatalystSceneEntityPayload pointerData, string contentUrl)
 41        {
 42            const string builderInWorldStateJson = "scene-state-definition.json";
 43            const string builderSourceName = "builder";
 44            const string builderInWorldSourceName = "builder-in-world";
 45
 546            metadata = pointerData.metadata;
 547            entityId = pointerData.id;
 48
 549            deploymentSource = Source.SDK;
 50
 551            if (pointerData.content != null && pointerData.content.Any(content => content.file == builderInWorldStateJso
 52            {
 053                deploymentSource = Source.BUILDER_IN_WORLD;
 054            }
 555            else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName)
 56            {
 057                deploymentSource = Source.BUILDER_IN_WORLD;
 058            }
 559            else if (metadata.source != null && metadata.source.origin == builderSourceName)
 60            {
 061                deploymentSource = Source.BUILDER;
 62            }
 63
 564            baseCoord = StringToVector2Int(metadata.scene.@base);
 565            parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray();
 566            thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl);
 67
 568            timestamp = pointerData.timestamp;
 569        }
 70
 071        public void SetScene(LandWithAccess land) { sceneLand = land; }
 72
 73        static Vector2Int StringToVector2Int(string coords)
 74        {
 1075            string[] coordSplit = coords.Split(',');
 1076            if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int 
 77            {
 1078                return new Vector2Int(x, y);
 79            }
 80
 081            return Vector2Int.zero;
 82        }
 83
 84        static string GetNavmapThumbnailUrl(CatalystSceneEntityPayload pointerData, string contentUrl)
 85        {
 86            const string contentDownloadUrlFormat = "{0}/contents/{1}";
 87            const string builderUrlFormat = "https://builder-api.decentraland.org/v1/projects/{0}/media/preview.png";
 88
 589            string thumbnail = pointerData.metadata.display.navmapThumbnail;
 90
 591            bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail);
 592            bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http");
 93
 594            if (isThumbnailPresent && !isThumbnailFileDeployed)
 95            {
 096                return thumbnail;
 97            }
 98
 599            if (isThumbnailFileDeployed && pointerData.content != null)
 100            {
 0101                string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash;
 0102                if (!string.IsNullOrEmpty(thumbnailHash))
 103                {
 0104                    return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash);
 105                }
 106            }
 107
 5108            if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId))
 109            {
 0110                return string.Format(builderUrlFormat, pointerData.metadata.source.projectId);
 111            }
 112
 5113            return thumbnail;
 114        }
 115    }
 116}