< Summary

Class:HotScenesController
Assembly:HotScenesController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HotScenesController/HotScenesController.cs
Covered lines:13
Uncovered lines:4
Coverable lines:17
Total lines:73
Line coverage:76.4% (13 of 17)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HotScenesController()0%110100%
Awake()0%110100%
UpdateHotScenesList(...)0%5.025090.91%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using UnityEngine;
 5
 6public class HotScenesController : MonoBehaviour
 7{
 08    public static HotScenesController i { get; private set; }
 9
 10    public event Action OnHotSceneListFinishUpdating;
 11    public event Action OnHotSceneListChunkUpdated;
 12
 113    public List<HotSceneInfo> hotScenesList { get; private set; } = new List<HotSceneInfo>();
 014    public bool isUpdating { get; private set; }
 015    public float timeSinceLastUpdate { get { return Time.realtimeSinceStartup - lastUpdateTime; } }
 16
 117    private float lastUpdateTime = float.MinValue * .5f;
 18
 19    [Serializable]
 20    public class HotSceneInfo
 21    {
 22        [Serializable]
 23        public class Realm
 24        {
 25            public string serverName;
 26            public string layer;
 27            public int usersCount;
 28            public int maxUsers;
 29            public Vector2Int[] userParcels;
 30        }
 31
 32        public string id;
 33        public string name;
 34        public string creator;
 35        public string description;
 36        public string thumbnail;
 37        public Vector2Int baseCoords;
 38        public Vector2Int[] parcels;
 39        public int usersTotalCount;
 40        public Realm[] realms;
 41    }
 42
 43    [Serializable]
 44    internal struct HotScenesUpdatePayload
 45    {
 46        public int chunkIndex;
 47        public int chunksCount;
 48        public HotSceneInfo[] scenesInfo;
 49    }
 50
 251    void Awake() { i = this; }
 52
 53    public void UpdateHotScenesList(string json)
 54    {
 155        var updatePayload = Utils.SafeFromJson<HotScenesUpdatePayload>(json);
 56
 157        if (updatePayload.chunkIndex == 0)
 58        {
 159            isUpdating = true;
 160            hotScenesList.Clear();
 61        }
 62
 163        hotScenesList.AddRange(updatePayload.scenesInfo);
 164        OnHotSceneListChunkUpdated?.Invoke();
 65
 166        if (updatePayload.chunkIndex >= updatePayload.chunksCount - 1)
 67        {
 168            isUpdating = false;
 169            lastUpdateTime = Time.realtimeSinceStartup;
 170            OnHotSceneListFinishUpdating?.Invoke();
 71        }
 072    }
 73}