< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DeployedScene()0%2100%
DeployedScene(...)0%72800%
StringToVector2Int(...)0%20400%
GetNavmapThumbnailUrl(...)0%1321100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DeployedScenesFetcher/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;
 018    public string contentRating => metadata.policy?.contentRating;
 019    public bool voiceEnabled => metadata.policy?.voiceEnabled ?? false;
 020    public string[] bannedUsers => metadata.policy?.blacklist;
 021    public string projectId => metadata.source?.projectId;
 022    public bool isEmpty => metadata.source?.isEmpty ?? false;
 23
 24    private CatalystSceneEntityMetadata metadata;
 25    private Source deploymentSource;
 26    private Vector2Int baseCoord;
 27    private Vector2Int[] parcelsCoord;
 28    private string thumbnail;
 29    private string entityId;
 30
 31    internal LandWithAccess sceneLand;
 32
 033    public DeployedScene() { }
 34
 035    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
 041        metadata = pointerData.metadata;
 042        entityId = pointerData.id;
 43
 044        deploymentSource = Source.SDK;
 45
 046        if (pointerData.content != null && pointerData.content.Any(content => content.file == builderInWorldStateJson))
 47        {
 048            deploymentSource = Source.BUILDER_IN_WORLD;
 049        }
 050        else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName)
 51        {
 052            deploymentSource = Source.BUILDER_IN_WORLD;
 053        }
 054        else if (metadata.source != null && metadata.source.origin == builderSourceName)
 55        {
 056            deploymentSource = Source.BUILDER;
 57        }
 58
 059        baseCoord = StringToVector2Int(metadata.scene.@base);
 060        parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray();
 061        thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl);
 062    }
 63
 64    static Vector2Int StringToVector2Int(string coords)
 65    {
 066        string[] coordSplit = coords.Split(',');
 067        if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int y))
 68        {
 069            return new Vector2Int(x, y);
 70        }
 71
 072        return Vector2Int.zero;
 73    }
 74
 75    static string GetNavmapThumbnailUrl(CatalystSceneEntityPayload pointerData, string contentUrl)
 76    {
 77        const string contentDownloadUrlFormat = "{0}/contents/{1}";
 78        const string builderUrlFormat = "https://builder-api.decentraland.org/v1/projects/{0}/media/preview.png";
 79
 080        string thumbnail = pointerData.metadata.display.navmapThumbnail;
 81
 082        bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail);
 083        bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http");
 84
 085        if (isThumbnailPresent && !isThumbnailFileDeployed)
 86        {
 087            return thumbnail;
 88        }
 89
 090        if (isThumbnailFileDeployed && pointerData.content != null)
 91        {
 092            string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash;
 093            if (!string.IsNullOrEmpty(thumbnailHash))
 94            {
 095                return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash);
 96            }
 97        }
 98
 099        if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId))
 100        {
 0101            return string.Format(builderUrlFormat, pointerData.metadata.source.projectId);
 102        }
 103
 0104        return thumbnail;
 105    }
 106}