| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Builder |
| | 6 | | { |
| | 7 | | public class Scene |
| | 8 | | { |
| | 9 | | public enum Source { BUILDER, BUILDER_IN_WORLD, SDK } |
| | 10 | |
|
| 0 | 11 | | public string title => metadata.display.title; |
| 0 | 12 | | public string description => metadata.display.description; |
| 0 | 13 | | public string author => metadata.contact.name; |
| 0 | 14 | | public string navmapThumbnail => thumbnail; |
| 0 | 15 | | public Vector2Int @base => baseCoord; |
| 0 | 16 | | public Vector2Int[] parcels => parcelsCoord; |
| 0 | 17 | | public string id => entityId; |
| 0 | 18 | | public Source source => deploymentSource; |
| 0 | 19 | | public LandWithAccess land => sceneLand; |
| 0 | 20 | | public string[] requiredPermissions => metadata.requiredPermissions; |
| 1 | 21 | | public string contentRating => metadata.policy?.contentRating; |
| 0 | 22 | | public bool voiceEnabled => metadata.policy?.voiceEnabled ?? false; |
| 1 | 23 | | public string[] bannedUsers => metadata.policy?.blacklist; |
| 1 | 24 | | public string projectId => metadata.source?.projectId; |
| 2 | 25 | | public bool isEmpty => metadata.source?.isEmpty ?? false; |
| 0 | 26 | | 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 | |
|
| 0 | 38 | | public Scene() { } |
| | 39 | |
|
| 5 | 40 | | 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 | |
|
| 5 | 46 | | metadata = pointerData.metadata; |
| 5 | 47 | | entityId = pointerData.id; |
| | 48 | |
|
| 5 | 49 | | deploymentSource = Source.SDK; |
| | 50 | |
|
| 5 | 51 | | if (pointerData.content != null && pointerData.content.Any(content => content.file == builderInWorldStateJso |
| | 52 | | { |
| 0 | 53 | | deploymentSource = Source.BUILDER_IN_WORLD; |
| 0 | 54 | | } |
| 5 | 55 | | else if (metadata.source != null && metadata.source.origin == builderInWorldSourceName) |
| | 56 | | { |
| 0 | 57 | | deploymentSource = Source.BUILDER_IN_WORLD; |
| 0 | 58 | | } |
| 5 | 59 | | else if (metadata.source != null && metadata.source.origin == builderSourceName) |
| | 60 | | { |
| 0 | 61 | | deploymentSource = Source.BUILDER; |
| | 62 | | } |
| | 63 | |
|
| 5 | 64 | | baseCoord = StringToVector2Int(metadata.scene.@base); |
| 5 | 65 | | parcelsCoord = metadata.scene.parcels.Select(StringToVector2Int).ToArray(); |
| 5 | 66 | | thumbnail = GetNavmapThumbnailUrl(pointerData, contentUrl); |
| | 67 | |
|
| 5 | 68 | | timestamp = pointerData.timestamp; |
| 5 | 69 | | } |
| | 70 | |
|
| 0 | 71 | | public void SetScene(LandWithAccess land) { sceneLand = land; } |
| | 72 | |
|
| | 73 | | static Vector2Int StringToVector2Int(string coords) |
| | 74 | | { |
| 10 | 75 | | string[] coordSplit = coords.Split(','); |
| 10 | 76 | | if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out int x) && int.TryParse(coordSplit[1], out int |
| | 77 | | { |
| 10 | 78 | | return new Vector2Int(x, y); |
| | 79 | | } |
| | 80 | |
|
| 0 | 81 | | 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 | |
|
| 5 | 89 | | string thumbnail = pointerData.metadata.display.navmapThumbnail; |
| | 90 | |
|
| 5 | 91 | | bool isThumbnailPresent = !string.IsNullOrEmpty(thumbnail); |
| 5 | 92 | | bool isThumbnailFileDeployed = isThumbnailPresent && !thumbnail.StartsWith("http"); |
| | 93 | |
|
| 5 | 94 | | if (isThumbnailPresent && !isThumbnailFileDeployed) |
| | 95 | | { |
| 0 | 96 | | return thumbnail; |
| | 97 | | } |
| | 98 | |
|
| 5 | 99 | | if (isThumbnailFileDeployed && pointerData.content != null) |
| | 100 | | { |
| 0 | 101 | | string thumbnailHash = pointerData.content.FirstOrDefault(content => content.file == thumbnail)?.hash; |
| 0 | 102 | | if (!string.IsNullOrEmpty(thumbnailHash)) |
| | 103 | | { |
| 0 | 104 | | return string.Format(contentDownloadUrlFormat, contentUrl, thumbnailHash); |
| | 105 | | } |
| | 106 | | } |
| | 107 | |
|
| 5 | 108 | | if (pointerData.metadata.source != null && !string.IsNullOrEmpty(pointerData.metadata.source.projectId)) |
| | 109 | | { |
| 0 | 110 | | return string.Format(builderUrlFormat, pointerData.metadata.source.projectId); |
| | 111 | | } |
| | 112 | |
|
| 5 | 113 | | return thumbnail; |
| | 114 | | } |
| | 115 | | } |
| | 116 | | } |