< Summary

Class:DCL.NavMapLocationControlsController
Assembly:Navmap
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NavMap/NavMapLocationControlsController.cs
Covered lines:37
Uncovered lines:3
Coverable lines:40
Total lines:112
Line coverage:92.5% (37 of 40)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:8
Method coverage:87.5% (7 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NavMapLocationControlsController(...)0%110100%
Dispose()0%220100%
Activate(...)0%4.034087.5%
Deactivate()0%330100%
Hide()0%110100%
FocusOnHomeLocation()0%220100%
CenterToPlayerLocation()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NavMap/NavMapLocationControlsController.cs

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.Tasks;
 3using DCLServices.MapRendererV2.ConsumerUtils;
 4using DCLServices.MapRendererV2.MapCameraController;
 5using ExploreV2Analytics;
 6using System;
 7using System.Threading;
 8using UnityEngine;
 9using UnityEngine.EventSystems;
 10
 11namespace DCL
 12{
 13    public class NavMapLocationControlsController : IDisposable
 14    {
 15        public const float TRANSLATION_DURATION = 0.5f;
 16
 17        internal readonly BaseVariable<Vector2Int> homePoint;
 18        internal readonly BaseVariable<Vector3> playerPlayerWorldPosition;
 19
 20        private readonly INavMapLocationControlsView view;
 21        private readonly IExploreV2Analytics exploreV2Analytics;
 22        private readonly INavmapZoomViewController navmapZoomViewController;
 23        private readonly INavmapToastViewController toastViewController;
 24
 25        private IMapCameraController mapCamera;
 26
 27        private bool active;
 28        private CancellationTokenSource cts;
 29
 030        private MapRenderImage.ParcelClickData homeParcel => new()
 31        {
 32            Parcel = homePoint.Get(),
 33            WorldPosition = new Vector2(Screen.width / 2f, Screen.height / 2f),
 34        };
 35
 736        public NavMapLocationControlsController(INavMapLocationControlsView view, IExploreV2Analytics exploreV2Analytics
 37            INavmapToastViewController toastViewController, BaseVariable<Vector2Int> homePoint,
 38            BaseVariable<Vector3> playerPlayerWorldPosition)
 39        {
 740            this.view = view;
 741            this.exploreV2Analytics = exploreV2Analytics;
 742            this.navmapZoomViewController = navmapZoomViewController;
 743            this.toastViewController = toastViewController;
 744            this.homePoint = homePoint;
 745            this.playerPlayerWorldPosition = playerPlayerWorldPosition;
 746        }
 47
 48        public void Dispose()
 49        {
 650            cts?.SafeCancelAndDispose();
 651            cts = null;
 652        }
 53
 54        public void Activate(IMapCameraController mapCameraController)
 55        {
 456            if (active && mapCamera == mapCameraController)
 057                return;
 58
 459            cts ??= new CancellationTokenSource();
 60
 461            mapCamera = mapCameraController;
 62
 463            view.HomeButtonClicked += FocusOnHomeLocation;
 464            view.CenterToPlayerButtonClicked += CenterToPlayerLocation;
 65
 466            active = true;
 467        }
 68
 69        public void Deactivate()
 70        {
 371            if (!active) return;
 72
 173            cts?.SafeRestart();
 74
 175            view.HomeButtonClicked -= FocusOnHomeLocation;
 176            view.CenterToPlayerButtonClicked -= CenterToPlayerLocation;
 77
 178            active = false;
 179        }
 80
 81        public void Hide()
 82        {
 183            Deactivate();
 184            view.Hide();
 185        }
 86
 87        private void FocusOnHomeLocation()
 88        {
 289            EventSystem.current?.SetSelectedGameObject(null);
 290            toastViewController.CloseCurrentToast();
 91
 292            mapCamera.TranslateTo(
 93                coordinates: homePoint.Get(),
 94                duration: TRANSLATION_DURATION,
 095                onComplete: () => toastViewController.ShowPlaceToast(homeParcel, showUntilClick: true));
 96
 297            exploreV2Analytics.SendCenterMapToHome();
 298        }
 99
 100        private void CenterToPlayerLocation()
 101        {
 2102            EventSystem.current?.SetSelectedGameObject(null);
 2103            toastViewController.CloseCurrentToast();
 104
 2105            mapCamera.TranslateTo(
 106                coordinates: Utils.WorldToGridPosition(playerPlayerWorldPosition.Get()),
 107                duration: TRANSLATION_DURATION);
 108
 2109            exploreV2Analytics.SendCenterMapToPlayer();
 2110        }
 111    }
 112}