< Summary

Class:MinimapMetadata
Assembly:MapRenderer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MapRenderer/MinimapMetadata.cs
Covered lines:19
Uncovered lines:2
Coverable lines:21
Total lines:94
Line coverage:90.4% (19 of 21)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MinimapMetadata()0%110100%
GetSceneInfo(...)0%220100%
AddSceneInfo(...)0%5.125083.33%
Clear()0%110100%
GetMetadata()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MapRenderer/MinimapMetadata.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5[CreateAssetMenu(fileName = "MinimapMetadata", menuName = "MinimapMetadata")]
 6public class MinimapMetadata : ScriptableObject
 7{
 8    public enum TileType
 9    {
 10        MyParcel = 0,
 11        MyParcelsOnSale = 1,
 12        MyEstates = 2,
 13        MyEstatesOnSale = 3,
 14        WithAccess = 4,
 15        District = 5,
 16        Contribution = 6,
 17        Roads = 7,
 18        Plaza = 8,
 19        Taken = 9,
 20        OnSale = 10,
 21        Unowned = 11,
 22        Background = 12,
 23        Loading = 13
 24    }
 25
 26    [Serializable]
 27    public class MinimapSceneInfo
 28    {
 29        public string name;
 30        public TileType type;
 31        public List<Vector2Int> parcels;
 32
 33        public bool isPOI;
 34        public string owner;
 35        public string description;
 36        public string previewImageUrl;
 37    }
 38
 39    public event Action<MinimapSceneInfo> OnSceneInfoUpdated;
 40
 141    HashSet<MinimapSceneInfo> scenesInfo = new HashSet<MinimapSceneInfo>();
 142    Dictionary<Vector2Int, MinimapSceneInfo> sceneInfoMap = new Dictionary<Vector2Int, MinimapSceneInfo>();
 43
 44    public MinimapSceneInfo GetSceneInfo(int x, int y)
 45    {
 13246        if (sceneInfoMap.TryGetValue(new Vector2Int(x, y), out MinimapSceneInfo result))
 247            return result;
 48
 13049        return null;
 50    }
 51
 52    public void AddSceneInfo(MinimapSceneInfo sceneInfo)
 53    {
 554        if (scenesInfo.Contains(sceneInfo))
 055            return;
 56
 557        int parcelsCount = sceneInfo.parcels.Count;
 58
 3459        for (int i = 0; i < parcelsCount; i++)
 60        {
 1261            if (sceneInfoMap.ContainsKey(sceneInfo.parcels[i]))
 62            {
 63                //NOTE(Brian): I intended at first to just return; here. But turns out kernel is sending
 64                //             overlapping coordinates, sending first gigantic 'Estate' and 'Roads' scenes to
 65                //             send the proper scenes later. This will be fixed when we implement the content v3 data
 66                //             plumbing.
 067                sceneInfoMap.Remove(sceneInfo.parcels[i]);
 68            }
 69
 1270            sceneInfoMap.Add(sceneInfo.parcels[i], sceneInfo);
 71        }
 72
 573        scenesInfo.Add(sceneInfo);
 74
 575        OnSceneInfoUpdated?.Invoke(sceneInfo);
 576    }
 77
 78    public void Clear()
 79    {
 12580        scenesInfo.Clear();
 12581        sceneInfoMap.Clear();
 12582    }
 83
 84    private static MinimapMetadata minimapMetadata;
 85    public static MinimapMetadata GetMetadata()
 86    {
 132487        if (minimapMetadata == null)
 88        {
 189            minimapMetadata = Resources.Load<MinimapMetadata>("ScriptableObjects/MinimapMetadata");
 90        }
 91
 132492        return minimapMetadata;
 93    }
 94}