| | 1 | | using DCL.Emotes; |
| | 2 | | using System; |
| | 3 | |
|
| | 4 | | namespace DCLServices.EmotesCatalog |
| | 5 | | { |
| | 6 | | [Serializable] |
| | 7 | | public class EmoteEntityDto |
| | 8 | | { |
| | 9 | | [Serializable] |
| | 10 | | public class ContentDto |
| | 11 | | { |
| | 12 | | public string file; |
| | 13 | | public string hash; |
| | 14 | | } |
| | 15 | |
|
| | 16 | | [Serializable] |
| | 17 | | public class MetadataDto |
| | 18 | | { |
| | 19 | | [Serializable] |
| | 20 | | public class Representation |
| | 21 | | { |
| | 22 | | public string[] bodyShapes; |
| | 23 | | public string mainFile; |
| | 24 | | public string[] contents; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | [Serializable] |
| | 28 | | public class DataDto |
| | 29 | | { |
| | 30 | | public Representation[] representations; |
| | 31 | | public string category; |
| | 32 | | public string[] tags; |
| | 33 | | public bool loop; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public DataDto emoteDataADR74; |
| | 37 | | public string id; |
| | 38 | |
|
| | 39 | | public i18n[] i18n; |
| | 40 | | public string thumbnail; |
| | 41 | |
|
| | 42 | | public string rarity; |
| | 43 | | public string description; |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public MetadataDto metadata; |
| | 47 | | public ContentDto[] content; |
| | 48 | | public string id; |
| | 49 | |
|
| | 50 | | public string GetContentHashByFileName(string fileName) |
| | 51 | | { |
| 0 | 52 | | foreach (ContentDto dto in content) |
| 0 | 53 | | if (dto.file == fileName) |
| 0 | 54 | | return dto.hash; |
| | 55 | |
|
| 0 | 56 | | return null; |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public WearableItem ToWearableItem(string contentBaseUrl) |
| | 60 | | { |
| 0 | 61 | | WearableItem wearable = new WearableItem(); |
| 0 | 62 | | wearable.entityId = id; |
| 0 | 63 | | wearable.emoteDataV0 = null; |
| | 64 | |
|
| 0 | 65 | | MetadataDto metadataDto = metadata; |
| 0 | 66 | | if (metadataDto == null) return wearable; |
| | 67 | |
|
| 0 | 68 | | wearable.description = metadataDto.description; |
| 0 | 69 | | wearable.rarity = metadataDto.rarity; |
| 0 | 70 | | wearable.i18n = metadataDto.i18n; |
| 0 | 71 | | wearable.id = metadataDto.id; |
| 0 | 72 | | wearable.thumbnail = GetContentHashByFileName(metadataDto.thumbnail); |
| | 73 | |
|
| 0 | 74 | | var data = metadataDto.emoteDataADR74; |
| 0 | 75 | | if (data == null) return wearable; |
| | 76 | |
|
| | 77 | | // todo: remove this when we refactor the WearableItem into EmoteItem |
| 0 | 78 | | wearable.emoteDataV0 = new EmoteDataV0() { loop = data.loop }; |
| | 79 | |
|
| 0 | 80 | | wearable.data = new WearableItem.Data |
| | 81 | | { |
| | 82 | | representations = new WearableItem.Representation[data.representations.Length], |
| | 83 | | category = data.category, |
| | 84 | | tags = data.tags, |
| | 85 | | loop = data.loop |
| | 86 | | }; |
| | 87 | |
|
| 0 | 88 | | for (var i = 0; i < data.representations.Length; i++) |
| | 89 | | { |
| 0 | 90 | | MetadataDto.Representation representation = data.representations[i]; |
| | 91 | |
|
| 0 | 92 | | wearable.data.representations[i] = new WearableItem.Representation |
| | 93 | | { |
| | 94 | | bodyShapes = representation.bodyShapes, |
| | 95 | | mainFile = representation.mainFile, |
| | 96 | | contents = new WearableItem.MappingPair[representation.contents.Length], |
| | 97 | | }; |
| | 98 | |
|
| 0 | 99 | | for (var z = 0; z < representation.contents.Length; z++) |
| | 100 | | { |
| 0 | 101 | | string fileName = representation.contents[z]; |
| 0 | 102 | | string hash = GetContentHashByFileName(fileName); |
| | 103 | |
|
| 0 | 104 | | wearable.data.representations[i].contents[z] = new WearableItem.MappingPair |
| | 105 | | { |
| | 106 | | url = $"{contentBaseUrl}/{hash}", |
| | 107 | | hash = hash, |
| | 108 | | key = fileName, |
| | 109 | | }; |
| | 110 | | } |
| | 111 | | } |
| | 112 | |
|
| 0 | 113 | | return wearable; |
| | 114 | | } |
| | 115 | | } |
| | 116 | | } |