| | 1 | | using System.Linq; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public class DeployedScene |
| | 5 | | { |
| | 6 | | public enum Source { BUILDER, BUILDER_IN_WORLD, SDK } |
| | 7 | |
|
| 0 | 8 | | public string title => metadata.display.title; |
| 0 | 9 | | public string description => metadata.display.description; |
| 0 | 10 | | public string author => metadata.contact.name; |
| 0 | 11 | | public string navmapThumbnail => thumbnail; |
| 0 | 12 | | public Vector2Int @base => baseCoord; |
| 0 | 13 | | public Vector2Int[] parcels => parcelsCoord; |
| 0 | 14 | | public string id => entityId; |
| 0 | 15 | | public Source source => deploymentSource; |
| 0 | 16 | | public LandWithAccess land => sceneLand; |
| 0 | 17 | | public string[] requiredPermissions => metadata.requiredPermissions; |
| 1 | 18 | | public string contentRating => metadata.policy?.contentRating; |
| 0 | 19 | | public bool voiceEnabled => metadata.policy?.voiceEnabled ?? false; |
| 1 | 20 | | public string[] bannedUsers => metadata.policy?.blacklist; |
| 1 | 21 | | public string projectId => metadata.source?.projectId; |
| 2 | 22 | | 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 | |
|
| 0 | 33 | | public DeployedScene() { } |
| | 34 | |
|
| 1 | 35 | | 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 | |
|
| 1 | 41 | | metadata = pointerData.metadata; |
| 1 | 42 | | entityId = pointerData.id; |
| | 43 | |
|
| 1 | 44 | | deploymentSource = Source.SDK; |
| | 45 | |
|
| 1 | 46 | | if (pointerData.content != null && pointerData.content.Any(content => content.file == builderInWorldStateJson)) |
| | 47 | | { |
| 0 | 48 | | deploymentSource = Source.BUILDER_IN_WORLD; |
| 0 | 49 | | } |
| 1 | 50 | | else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName) |
| | 51 | | { |
| 0 | 52 | | deploymentSource = Source.BUILDER_IN_WORLD; |
| 0 | 53 | | } |
| 1 | 54 | | else if (metadata.source != null && metadata.source.origin == builderSourceName) |
| | 55 | | { |
| 0 | 56 | | deploymentSource = Source.BUILDER; |
| | 57 | | } |
| | 58 | |
|
| 1 | 59 | | baseCoord = StringToVector2Int(metadata.scene.@base); |
| 1 | 60 | | parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray(); |
| 1 | 61 | | thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl); |
| 1 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | public void SetScene(LandWithAccess land) { sceneLand = land; } |
| | 65 | |
|
| | 66 | | static Vector2Int StringToVector2Int(string coords) |
| | 67 | | { |
| 2 | 68 | | string[] coordSplit = coords.Split(','); |
| 2 | 69 | | if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int y)) |
| | 70 | | { |
| 2 | 71 | | return new Vector2Int(x, y); |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | 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 | |
|
| 1 | 82 | | string thumbnail = pointerData.metadata.display.navmapThumbnail; |
| | 83 | |
|
| 1 | 84 | | bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail); |
| 1 | 85 | | bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http"); |
| | 86 | |
|
| 1 | 87 | | if (isThumbnailPresent && !isThumbnailFileDeployed) |
| | 88 | | { |
| 0 | 89 | | return thumbnail; |
| | 90 | | } |
| | 91 | |
|
| 1 | 92 | | if (isThumbnailFileDeployed && pointerData.content != null) |
| | 93 | | { |
| 0 | 94 | | string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash; |
| 0 | 95 | | if (!string.IsNullOrEmpty(thumbnailHash)) |
| | 96 | | { |
| 0 | 97 | | return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash); |
| | 98 | | } |
| | 99 | | } |
| | 100 | |
|
| 1 | 101 | | if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId)) |
| | 102 | | { |
| 0 | 103 | | return string.Format(builderUrlFormat, pointerData.metadata.source.projectId); |
| | 104 | | } |
| | 105 | |
|
| 1 | 106 | | return thumbnail; |
| | 107 | | } |
| | 108 | | } |