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