< Summary

Class:DCL.MapGlobalUsersPositionMarkerController
Assembly:GlobalUsersPositionMarker
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MapRenderer/GlobalUsersPositionMarker/MapGlobalUsersPositionMarkerController.cs
Covered lines:30
Uncovered lines:2
Coverable lines:32
Total lines:91
Line coverage:93.7% (30 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MapGlobalUsersPositionMarkerController(...)0%110100%
SetUpdateMode(...)0%110100%
Dispose()0%110100%
OnScenesFetched(...)0%2100%
OnPlayerCoordsChanged(...)0%110100%
OnRenderStateChanged(...)0%2.032080%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL
 6{
 7    public class MapGlobalUsersPositionMarkerController : IDisposable
 8    {
 9        private const float UPDATE_INTERVAL_INITIAL = 10f;
 10        private const float UPDATE_INTERVAL_FOREGROUND = 60f;
 11        private const float UPDATE_INTERVAL_BACKGROUND = 5 * 60f;
 12
 13        private const int MAX_MARKERS = 100;
 14
 15        private const int COMMS_RADIUS_THRESHOLD = 2;
 16
 17        public enum UpdateMode
 18        {
 19            FOREGROUND,
 20            BACKGROUND
 21        }
 22
 23        FetchScenesHandler fetchScenesHandler;
 24        MarkersHandler markersHandler;
 25        UserPositionHandler userPositionHandler;
 26        Transform markersContainer;
 27
 1028        int commsRadius = 4;
 29
 30        /// <summary>
 31        /// Constructor
 32        /// </summary>
 33        /// <param name="markerPrefab">prefab for markers</param>
 34        /// <param name="overlayContainer">parent for markers</param>
 35        /// <param name="coordToMapPosFunc">function to transform coords to map position</param>
 1036        public MapGlobalUsersPositionMarkerController(UserMarkerObject markerPrefab, Transform overlayContainer, Func<fl
 37        {
 1038            fetchScenesHandler = new FetchScenesHandler(UPDATE_INTERVAL_INITIAL, UPDATE_INTERVAL_FOREGROUND, UPDATE_INTE
 1039            markersHandler = new MarkersHandler(markerPrefab, overlayContainer, MAX_MARKERS, coordToMapPosFunc);
 1040            userPositionHandler = new UserPositionHandler();
 1041            markersContainer = overlayContainer;
 42
 1043            fetchScenesHandler.OnScenesFetched += OnScenesFetched;
 1044            userPositionHandler.OnPlayerCoordsChanged += OnPlayerCoordsChanged;
 1045            CommonScriptableObjects.rendererState.OnChange += OnRenderStateChanged;
 46
 1047            KernelConfig.i.EnsureConfigInitialized()
 48                        .Then(config =>
 49                        {
 950                            commsRadius = (int) config.comms.commRadius + COMMS_RADIUS_THRESHOLD;
 951                            OnPlayerCoordsChanged(userPositionHandler.playerCoords);
 952                        });
 1053            OnRenderStateChanged(CommonScriptableObjects.rendererState.Get(), false);
 1054        }
 55
 56        /// <summary>
 57        /// Set update mode. Scene's fetch intervals will smaller when updating in FOREGROUND than when updating in BACK
 58        /// </summary>
 59        /// <param name="updateMode">update mode</param>
 60        public void SetUpdateMode(UpdateMode updateMode)
 61        {
 1062            fetchScenesHandler.SetUpdateMode(updateMode);
 1063            markersContainer.gameObject.SetActive(updateMode == UpdateMode.FOREGROUND);
 1064        }
 65
 66        public void Dispose()
 67        {
 1268            fetchScenesHandler.OnScenesFetched -= OnScenesFetched;
 1269            userPositionHandler.OnPlayerCoordsChanged -= OnPlayerCoordsChanged;
 1270            CommonScriptableObjects.rendererState.OnChange -= OnRenderStateChanged;
 71
 1272            fetchScenesHandler.Dispose();
 1273            markersHandler.Dispose();
 1274            userPositionHandler.Dispose();
 1275        }
 76
 077        private void OnScenesFetched(List<HotScenesController.HotSceneInfo> sceneList) { markersHandler.SetMarkers(scene
 78
 1879        private void OnPlayerCoordsChanged(Vector2Int coords) { markersHandler.SetExclusionArea(coords, commsRadius); }
 80
 81        private void OnRenderStateChanged(bool current, bool prev)
 82        {
 1083            if (!current)
 084                return;
 85
 86            // NOTE: we start fetching scenes after the renderer is activated for the first time
 1087            CommonScriptableObjects.rendererState.OnChange -= OnRenderStateChanged;
 1088            fetchScenesHandler.Init();
 1089        }
 90    }
 91}