< 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:134
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 UnityEngine;
 4
 5[Serializable]
 6public 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    {
 060        if (wearables == null || wearables.Count == 0)
 061            return null;
 62
 063        List<WearableItem> result = new List<WearableItem>();
 64
 065        foreach (var wearableData in wearables)
 66        {
 67            // Populate new WearableItem with fetched data
 068            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
 083            List<WearableItem.Representation> wearableRepresentations = new List<WearableItem.Representation>();
 084            foreach (var wearableDataRepresentation in wearableData.data.representations)
 85            {
 086                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
 094                List<WearableItem.MappingPair> contentMappingPairs = new List<WearableItem.MappingPair>();
 095                foreach (var content in wearableDataRepresentation.contents)
 96                {
 097                    if (string.IsNullOrEmpty(content.url))
 98                    {
 099                        Debug.Log($"WearablesAPIData - Couldn't get hash from mappings for asset '{content.key}', it's c
 100
 0101                        continue;
 102                    }
 103
 0104                    contentMappingPairs.Add(new WearableItem.MappingPair()
 105                    {
 106                        key = content.key,
 107                        hash = content.url.Substring(content.url.LastIndexOf("/") + 1)
 108                    });
 109                }
 110
 0111                wearableRepresentation.contents = contentMappingPairs.ToArray();
 0112                wearableRepresentations.Add(wearableRepresentation);
 113            }
 114
 0115            wearable.data.representations = wearableRepresentations.ToArray();
 0116            result.Add(wearable);
 117        }
 118
 0119        return result;
 120    }
 121}
 122
 123[Serializable]
 124public class WearableCollectionsAPIData
 125{
 126    [Serializable]
 127    public class Collection
 128    {
 129        public string id;
 130        public string name;
 131    }
 132
 133    public Collection[] collections;
 134}

Methods/Properties

GetWearableItems()