| | 1 | | using DCLServices.Lambdas; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | namespace DCLServices.WearablesCatalogService |
| | 6 | | { |
| | 7 | | [Serializable] |
| | 8 | | public class WearableWithoutDefinitionResponse |
| | 9 | | { |
| | 10 | | public List<WearableItem> wearables; |
| | 11 | | } |
| | 12 | |
|
| | 13 | | [Serializable] |
| | 14 | | public class WearableWithDefinitionResponse : PaginatedResponse |
| | 15 | | { |
| | 16 | | public List<WearableElementV1Dto> elements; |
| | 17 | |
|
| | 18 | | public WearableWithDefinitionResponse(List<WearableElementV1Dto> elements, |
| | 19 | | int pageNum, int pageSize, int totalAmount) |
| | 20 | | { |
| | 21 | | this.elements = elements; |
| | 22 | | this.pageNum = pageNum; |
| | 23 | | this.pageSize = pageSize; |
| | 24 | | this.totalAmount = totalAmount; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | public WearableWithDefinitionResponse() { } |
| | 28 | | } |
| | 29 | |
|
| | 30 | | [Serializable] |
| | 31 | | [Obsolete("Deprecated. Use WearableElementV2Dto instead")] |
| | 32 | | public class WearableElementV1Dto |
| | 33 | | { |
| | 34 | | public string urn; |
| | 35 | | public long maxTransferredAt; |
| | 36 | | public WearableItem definition; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | [Serializable] |
| | 40 | | public class WearableWithEntityResponseDto : PaginatedResponse |
| | 41 | | { |
| | 42 | | [Serializable] |
| | 43 | | public class ElementDto |
| | 44 | | { |
| | 45 | | [Serializable] |
| | 46 | | public class IndividualDataDto |
| | 47 | | { |
| | 48 | | public string id; |
| | 49 | | public string tokenId; |
| | 50 | | public string transferredAt; |
| | 51 | | public string price; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | [Serializable] |
| | 55 | | public class EntityDto |
| | 56 | | { |
| | 57 | | [Serializable] |
| | 58 | | public class ContentDto |
| | 59 | | { |
| | 60 | | public string file; |
| | 61 | | public string hash; |
| | 62 | | } |
| | 63 | |
|
| | 64 | | [Serializable] |
| | 65 | | public class MetadataDto |
| | 66 | | { |
| | 67 | | [Serializable] |
| | 68 | | public class Representation |
| | 69 | | { |
| | 70 | | public string[] bodyShapes; |
| | 71 | | public string mainFile; |
| | 72 | | public string[] contents; |
| | 73 | | public string[] overrideHides; |
| | 74 | | public string[] overrideReplaces; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | [Serializable] |
| | 78 | | public class DataDto |
| | 79 | | { |
| | 80 | | public Representation[] representations; |
| | 81 | | public string category; |
| | 82 | | public string[] tags; |
| | 83 | | public string[] replaces; |
| | 84 | | public string[] hides; |
| | 85 | | public string[] removesDefaultHiding; |
| | 86 | | public bool blockVrmExport; |
| | 87 | | } |
| | 88 | |
|
| | 89 | | public DataDto data; |
| | 90 | | public string id; |
| | 91 | |
|
| | 92 | | public i18n[] i18n; |
| | 93 | | public string thumbnail; |
| | 94 | |
|
| | 95 | | public string rarity; |
| | 96 | | public string description; |
| | 97 | | } |
| | 98 | |
|
| | 99 | | public MetadataDto metadata; |
| | 100 | | public ContentDto[] content; |
| | 101 | | public string id; |
| | 102 | |
|
| | 103 | | public string GetContentHashByFileName(string fileName) |
| | 104 | | { |
| 64 | 105 | | foreach (ContentDto dto in content) |
| 24 | 106 | | if (dto.file == fileName) |
| 16 | 107 | | return dto.hash; |
| | 108 | |
|
| 0 | 109 | | return null; |
| | 110 | | } |
| | 111 | |
|
| | 112 | | public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl, int amount) |
| | 113 | | { |
| 8 | 114 | | WearableItem wearable = new WearableItem |
| | 115 | | { |
| | 116 | | data = new WearableItem.Data |
| | 117 | | { |
| | 118 | | representations = new WearableItem.Representation[metadata.data.representations.Length], |
| | 119 | | category = metadata.data.category, |
| | 120 | | hides = metadata.data.hides, |
| | 121 | | replaces = metadata.data.replaces, |
| | 122 | | tags = metadata.data.tags, |
| | 123 | | removesDefaultHiding = metadata.data.removesDefaultHiding, |
| | 124 | | blockVrmExport = metadata.data.blockVrmExport, |
| | 125 | | }, |
| | 126 | | baseUrl = contentBaseUrl, |
| | 127 | | baseUrlBundles = bundlesBaseUrl, |
| | 128 | | emoteDataV0 = null, |
| | 129 | | description = metadata.description, |
| | 130 | | i18n = metadata.i18n, |
| | 131 | | id = metadata.id, |
| | 132 | | entityId = id, |
| | 133 | | rarity = metadata.rarity, |
| | 134 | | amount = amount, |
| | 135 | | thumbnail = GetContentHashByFileName(metadata.thumbnail), |
| | 136 | | }; |
| | 137 | |
|
| 32 | 138 | | for (var i = 0; i < metadata.data.representations.Length; i++) |
| | 139 | | { |
| 8 | 140 | | MetadataDto.Representation representation = metadata.data.representations[i]; |
| | 141 | |
|
| 8 | 142 | | wearable.data.representations[i] = new WearableItem.Representation |
| | 143 | | { |
| | 144 | | bodyShapes = representation.bodyShapes, |
| | 145 | | mainFile = representation.mainFile, |
| | 146 | | overrideHides = representation.overrideHides, |
| | 147 | | overrideReplaces = representation.overrideReplaces, |
| | 148 | | contents = new WearableItem.MappingPair[representation.contents.Length], |
| | 149 | | }; |
| | 150 | |
|
| 32 | 151 | | for (var z = 0; z < representation.contents.Length; z++) |
| | 152 | | { |
| 8 | 153 | | string fileName = representation.contents[z]; |
| 8 | 154 | | string hash = GetContentHashByFileName(fileName); |
| | 155 | |
|
| 8 | 156 | | wearable.data.representations[i].contents[z] = new WearableItem.MappingPair |
| | 157 | | { |
| | 158 | | url = $"{contentBaseUrl}/{hash}", |
| | 159 | | hash = hash, |
| | 160 | | key = fileName, |
| | 161 | | }; |
| | 162 | | } |
| | 163 | | } |
| | 164 | |
|
| 8 | 165 | | return wearable; |
| | 166 | | } |
| | 167 | | } |
| | 168 | |
|
| | 169 | | public string urn; |
| | 170 | | public IndividualDataDto[] individualData; |
| | 171 | | public EntityDto entity; |
| | 172 | | public int amount; |
| | 173 | | public string rarity; |
| | 174 | |
|
| | 175 | | public long GetMostRecentTransferTimestamp() |
| | 176 | | { |
| 8 | 177 | | if (individualData == null) return 0; |
| | 178 | |
|
| 0 | 179 | | long max = 0; |
| | 180 | |
|
| 0 | 181 | | foreach (IndividualDataDto dto in individualData) |
| | 182 | | { |
| 0 | 183 | | if (!long.TryParse(dto.transferredAt, out long transferredAt)) |
| | 184 | | continue; |
| | 185 | |
|
| 0 | 186 | | if (transferredAt > max) |
| 0 | 187 | | max = transferredAt; |
| | 188 | | } |
| | 189 | |
|
| 0 | 190 | | return max; |
| | 191 | | } |
| | 192 | |
|
| | 193 | | public WearableItem ToWearableItem(string contentBaseUrl, string bundlesBaseUrl) |
| | 194 | | { |
| 4 | 195 | | string individualId = individualData != null ? individualData[0].id : string.Empty; |
| 4 | 196 | | var wearable = entity.ToWearableItem(contentBaseUrl, bundlesBaseUrl, amount); |
| | 197 | |
|
| 4 | 198 | | if (!string.IsNullOrEmpty(individualId)) |
| 0 | 199 | | wearable.id = individualId; |
| | 200 | |
|
| 4 | 201 | | wearable.rarity ??= rarity; |
| 4 | 202 | | wearable.MostRecentTransferredDate = DateTimeOffset.FromUnixTimeSeconds(GetMostRecentTransferTimestamp() |
| 4 | 203 | | return wearable; |
| | 204 | | } |
| | 205 | | } |
| | 206 | |
|
| | 207 | | public List<ElementDto> elements; |
| | 208 | |
|
| 4 | 209 | | public WearableWithEntityResponseDto(List<ElementDto> elements, |
| | 210 | | int pageNum, int pageSize, int totalAmount) |
| | 211 | | { |
| 4 | 212 | | this.elements = elements; |
| 4 | 213 | | this.pageNum = pageNum; |
| 4 | 214 | | this.pageSize = pageSize; |
| 4 | 215 | | this.totalAmount = totalAmount; |
| 4 | 216 | | } |
| | 217 | |
|
| 0 | 218 | | public WearableWithEntityResponseDto() { } |
| | 219 | | } |
| | 220 | | } |