| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Emotes; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | [Serializable] |
| | 7 | | public class WearablesAPIData |
| | 8 | | { |
| | 9 | | [Serializable] |
| | 10 | | public class Wearable |
| | 11 | | { |
| | 12 | | [Serializable] |
| | 13 | | public class Data |
| | 14 | | { |
| | 15 | | [Serializable] |
| | 16 | | public class Representation |
| | 17 | | { |
| | 18 | | [Serializable] |
| | 19 | | public class Content |
| | 20 | | { |
| | 21 | | public string key; |
| | 22 | | public string url; |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public string[] bodyShapes; |
| | 26 | | public string mainFile; |
| | 27 | | public string[] overrideReplaces; |
| | 28 | | public string[] overrideHides; |
| | 29 | | public Content[] contents; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public string[] tags; |
| | 33 | | public string category; |
| | 34 | | public Representation[] representations; |
| | 35 | | } |
| | 36 | |
|
| | 37 | | public string id; |
| | 38 | | public string description; |
| | 39 | | public string thumbnail; |
| | 40 | | public string rarity; |
| | 41 | | public Data data; |
| | 42 | | public i18n[] i18n; |
| | 43 | | public EmoteDataV0 emoteDataV0 = null; |
| | 44 | | public int createdAt; |
| | 45 | | public int updatedAt; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | [Serializable] |
| | 49 | | public class PaginationData |
| | 50 | | { |
| | 51 | | public int limit; |
| | 52 | | public string next = null; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | // TODO: dinamically use ICatalyst.contentUrl, content server is not a const |
| | 56 | | private const string WEARABLES_CONTENT_BASE_URL = "https://peer.decentraland.org/content/contents/"; |
| | 57 | |
|
| | 58 | | public List<Wearable> wearables; |
| | 59 | | public PaginationData pagination; |
| | 60 | | public List<WearableItem> GetWearableItems() |
| | 61 | | { |
| 0 | 62 | | if (wearables == null || wearables.Count == 0) |
| 0 | 63 | | return null; |
| | 64 | |
|
| 0 | 65 | | List<WearableItem> result = new List<WearableItem>(); |
| | 66 | |
|
| 0 | 67 | | foreach (var wearableData in wearables) |
| | 68 | | { |
| | 69 | | // Populate new WearableItem with fetched data |
| 0 | 70 | | WearableItem wearable = new WearableItem() |
| | 71 | | { |
| | 72 | | id = wearableData.id, |
| | 73 | | baseUrl = WEARABLES_CONTENT_BASE_URL, |
| | 74 | | thumbnail = wearableData.thumbnail, |
| | 75 | | rarity = wearableData.rarity, |
| | 76 | | description = wearableData.description, |
| | 77 | | i18n = wearableData.i18n, |
| | 78 | | emoteDataV0 = wearableData.emoteDataV0, |
| | 79 | | data = new WearableItem.Data() |
| | 80 | | { |
| | 81 | | category = wearableData.data.category, |
| | 82 | | tags = wearableData.data.tags |
| | 83 | | } |
| | 84 | | }; |
| | 85 | |
|
| 0 | 86 | | List<WearableItem.Representation> wearableRepresentations = new List<WearableItem.Representation>(); |
| 0 | 87 | | foreach (var wearableDataRepresentation in wearableData.data.representations) |
| | 88 | | { |
| 0 | 89 | | WearableItem.Representation wearableRepresentation = new WearableItem.Representation() |
| | 90 | | { |
| | 91 | | bodyShapes = wearableDataRepresentation.bodyShapes, |
| | 92 | | overrideHides = wearableDataRepresentation.overrideHides, |
| | 93 | | overrideReplaces = wearableDataRepresentation.overrideReplaces, |
| | 94 | | mainFile = wearableDataRepresentation.mainFile |
| | 95 | | }; |
| | 96 | |
|
| 0 | 97 | | List<WearableItem.MappingPair> contentMappingPairs = new List<WearableItem.MappingPair>(); |
| 0 | 98 | | foreach (var content in wearableDataRepresentation.contents) |
| | 99 | | { |
| 0 | 100 | | if (string.IsNullOrEmpty(content.url)) |
| | 101 | | { |
| 0 | 102 | | Debug.Log($"WearablesAPIData - Couldn't get hash from mappings for asset '{content.key}', it's c |
| | 103 | |
|
| 0 | 104 | | continue; |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | contentMappingPairs.Add(new WearableItem.MappingPair() |
| | 108 | | { |
| | 109 | | key = content.key, |
| | 110 | | hash = content.url.Substring(content.url.LastIndexOf("/") + 1) |
| | 111 | | }); |
| | 112 | | } |
| | 113 | |
|
| 0 | 114 | | wearableRepresentation.contents = contentMappingPairs.ToArray(); |
| 0 | 115 | | wearableRepresentations.Add(wearableRepresentation); |
| | 116 | | } |
| | 117 | |
|
| 0 | 118 | | wearable.data.representations = wearableRepresentations.ToArray(); |
| 0 | 119 | | result.Add(wearable); |
| | 120 | | } |
| | 121 | |
|
| 0 | 122 | | return result; |
| | 123 | | } |
| | 124 | | } |
| | 125 | |
|
| | 126 | | [Serializable] |
| | 127 | | public class WearableCollectionsAPIData |
| | 128 | | { |
| | 129 | | [Serializable] |
| | 130 | | public class Collection |
| | 131 | | { |
| | 132 | | public string urn; |
| | 133 | | public string name; |
| | 134 | | } |
| | 135 | |
|
| | 136 | | public Collection[] data; |
| | 137 | | } |