< Summary

Class:DeployedScene
Assembly:LandWIthAccess
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/LandWithAccess/DeployedScene.cs
Covered lines:25
Uncovered lines:24
Coverable lines:49
Total lines:108
Line coverage:51% (25 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DeployedScene()0%2100%
DeployedScene(...)0%9.958068.75%
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/DeployedScene.cs

#LineLine coverage
 1using System.Linq;
 2using UnityEngine;
 3
 4public class DeployedScene
 5{
 6    public enum Source { BUILDER, BUILDER_IN_WORLD, SDK }
 7
 08    public string title => metadata.display.title;
 09    public string description => metadata.display.description;
 010    public string author => metadata.contact.name;
 011    public string navmapThumbnail => thumbnail;
 012    public Vector2Int @base => baseCoord;
 013    public Vector2Int[] parcels => parcelsCoord;
 014    public string id => entityId;
 015    public Source source => deploymentSource;
 016    public LandWithAccess land => sceneLand;
 017    public string[] requiredPermissions => metadata.requiredPermissions;
 118    public string contentRating => metadata.policy?.contentRating;
 019    public bool voiceEnabled => metadata.policy?.voiceEnabled ?? false;
 120    public string[] bannedUsers => metadata.policy?.blacklist;
 121    public string projectId => metadata.source?.projectId;
 222    public bool isEmpty => metadata.source?.isEmpty ?? false;
 23
 24    private CatalystSceneEntityMetadata metadata;
 25    internal Source deploymentSource;
 26    private Vector2Int baseCoord;
 27    internal Vector2Int[] parcelsCoord;
 28    private string thumbnail;
 29    private string entityId;
 30
 31    internal LandWithAccess sceneLand;
 32
 033    public DeployedScene() { }
 34
 135    public DeployedScene(CatalystSceneEntityPayload pointerData, string contentUrl)
 36    {
 37        const string builderInWorldStateJson = "scene-state-definition.json";
 38        const string builderSourceName = "builder";
 39        const string builderInWorldSourceName = "builder-in-world";
 40
 141        metadata = pointerData.metadata;
 142        entityId = pointerData.id;
 43
 144        deploymentSource = Source.SDK;
 45
 146        if (pointerData.content != null && pointerData.content.Any(content => content.file == builderInWorldStateJson))
 47        {
 048            deploymentSource = Source.BUILDER_IN_WORLD;
 049        }
 150        else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName)
 51        {
 052            deploymentSource = Source.BUILDER_IN_WORLD;
 053        }
 154        else if (metadata.source != null && metadata.source.origin == builderSourceName)
 55        {
 056            deploymentSource = Source.BUILDER;
 57        }
 58
 159        baseCoord = StringToVector2Int(metadata.scene.@base);
 160        parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray();
 161        thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl);
 162    }
 63
 064    public void SetScene(LandWithAccess land) { sceneLand = land; }
 65
 66    static Vector2Int StringToVector2Int(string coords)
 67    {
 268        string[] coordSplit = coords.Split(',');
 269        if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int y))
 70        {
 271            return new Vector2Int(x, y);
 72        }
 73
 074        return Vector2Int.zero;
 75    }
 76
 77    static string GetNavmapThumbnailUrl(CatalystSceneEntityPayload pointerData, string contentUrl)
 78    {
 79        const string contentDownloadUrlFormat = "{0}/contents/{1}";
 80        const string builderUrlFormat = "https://builder-api.decentraland.org/v1/projects/{0}/media/preview.png";
 81
 182        string thumbnail = pointerData.metadata.display.navmapThumbnail;
 83
 184        bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail);
 185        bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http");
 86
 187        if (isThumbnailPresent && !isThumbnailFileDeployed)
 88        {
 089            return thumbnail;
 90        }
 91
 192        if (isThumbnailFileDeployed && pointerData.content != null)
 93        {
 094            string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash;
 095            if (!string.IsNullOrEmpty(thumbnailHash))
 96            {
 097                return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash);
 98            }
 99        }
 100
 1101        if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId))
 102        {
 0103            return string.Format(builderUrlFormat, pointerData.metadata.source.projectId);
 104        }
 105
 1106        return thumbnail;
 107    }
 108}