< Summary

Class:WearablesAPIData
Assembly:WearablesFetching
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/Wearables/WearablesAPIData.cs
Covered lines:0
Uncovered lines:19
Coverable lines:19
Total lines:137
Line coverage:0% (0 of 19)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetWearableItems()0%56700%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/ServiceProviders/Wearables/WearablesAPIData.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Emotes;
 4using UnityEngine;
 5
 6[Serializable]
 7public 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 long createdAt;
 45        public long 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    {
 062        if (wearables == null || wearables.Count == 0)
 063            return null;
 64
 065        List<WearableItem> result = new List<WearableItem>();
 66
 067        foreach (var wearableData in wearables)
 68        {
 69            // Populate new WearableItem with fetched data
 070            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
 086            List<WearableItem.Representation> wearableRepresentations = new List<WearableItem.Representation>();
 087            foreach (var wearableDataRepresentation in wearableData.data.representations)
 88            {
 089                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
 097                List<WearableItem.MappingPair> contentMappingPairs = new List<WearableItem.MappingPair>();
 098                foreach (var content in wearableDataRepresentation.contents)
 99                {
 0100                    if (string.IsNullOrEmpty(content.url))
 101                    {
 0102                        Debug.Log($"WearablesAPIData - Couldn't get hash from mappings for asset '{content.key}', it's c
 103
 0104                        continue;
 105                    }
 106
 0107                    contentMappingPairs.Add(new WearableItem.MappingPair()
 108                    {
 109                        key = content.key,
 110                        hash = content.url.Substring(content.url.LastIndexOf("/") + 1)
 111                    });
 112                }
 113
 0114                wearableRepresentation.contents = contentMappingPairs.ToArray();
 0115                wearableRepresentations.Add(wearableRepresentation);
 116            }
 117
 0118            wearable.data.representations = wearableRepresentations.ToArray();
 0119            result.Add(wearable);
 120        }
 121
 0122        return result;
 123    }
 124}
 125
 126[Serializable]
 127public 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}

Methods/Properties

GetWearableItems()