< Summary

Class:DCLServices.MapRendererV2.MapLayers.PlayerMarker.PlayerMarkerController
Assembly:MapRendererV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapLayers/PlayerMarker/PlayerMarkerController.cs
Covered lines:13
Uncovered lines:23
Coverable lines:36
Total lines:101
Line coverage:36.1% (13 of 36)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:12
Method coverage:33.3% (4 of 12)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerMarkerController(...)0%110100%
Initialize()0%110100%
Enable(...)0%2100%
Disable(...)0%110100%
SetParameter(...)0%6200%
SetPosition()0%2100%
OnPlayerRotationChange(...)0%2100%
SetRotation()0%2100%
ApplyCameraZoom(...)0%2100%
ResetToBaseScale()0%2100%
OnPlayerWorldPositionChange(...)0%2100%
DisposeImpl()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapLayers/PlayerMarker/PlayerMarkerController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Helpers;
 3using DCLServices.MapRendererV2.CoordsUtils;
 4using DCLServices.MapRendererV2.Culling;
 5using System;
 6using System.Threading;
 7using UnityEngine;
 8
 9namespace DCLServices.MapRendererV2.MapLayers.PlayerMarker
 10{
 11    internal class PlayerMarkerController : MapLayerControllerBase, IMapLayerController<PlayerMarkerParameter>, IZoomSca
 12    {
 13        internal delegate IPlayerMarker PlayerMarkerBuilder(Transform parent);
 14
 15        private readonly PlayerMarkerBuilder builder;
 16        private readonly BaseVariable<Vector3> playerWorldPosition;
 17        private readonly Vector3Variable playerRotation;
 18
 19        private IPlayerMarker playerMarker;
 20
 21        public PlayerMarkerController(
 22            PlayerMarkerBuilder builder,
 23            BaseVariable<Vector3> playerWorldPosition, Vector3Variable playerRotation,
 24            Transform instantiationParent, ICoordsUtils coordsUtils, IMapCullingController cullingController)
 9625            : base(instantiationParent, coordsUtils, cullingController)
 26        {
 9627            this.builder = builder;
 9628            this.playerWorldPosition = playerWorldPosition;
 9629            this.playerRotation = playerRotation;
 9630        }
 31
 32        public void Initialize()
 33        {
 9634            playerMarker = builder(instantiationParent);
 9635        }
 36
 37        public UniTask Enable(CancellationToken cancellationToken)
 38        {
 039            playerMarker.SetActive(true);
 40
 041            SetRotation();
 042            SetPosition();
 43
 044            playerWorldPosition.OnChange += OnPlayerWorldPositionChange;
 045            playerRotation.OnChange += OnPlayerRotationChange;
 046            return UniTask.CompletedTask;
 47        }
 48
 49        public UniTask Disable(CancellationToken cancellationToken)
 50        {
 8851            playerMarker.SetActive(false);
 52
 8853            playerWorldPosition.OnChange -= OnPlayerWorldPositionChange;
 8854            playerRotation.OnChange -= OnPlayerRotationChange;
 8855            return UniTask.CompletedTask;
 56        }
 57
 58        public void SetParameter(PlayerMarkerParameter param)
 59        {
 060            playerMarker?.SetBackgroundVisibility(param.BackgroundIsActive);
 061        }
 62
 63        private void SetPosition()
 64        {
 065            var gridPosition = Utils.WorldToGridPositionUnclamped(playerWorldPosition.Get());
 066            playerMarker.SetPosition(coordsUtils.PivotPosition(playerMarker, coordsUtils.CoordsToPositionWithOffset(grid
 067        }
 68
 69        private void OnPlayerRotationChange(Vector3 current, Vector3 previous)
 70        {
 071            SetRotation();
 072        }
 73
 74        private void SetRotation()
 75        {
 076            var playerRot = playerRotation.Get();
 077            var markerRot = Quaternion.Euler(0, 0, Mathf.Atan2(-playerRot.x, playerRot.z) * Mathf.Rad2Deg);
 078            playerMarker.SetRotation(markerRot);
 079        }
 80
 81        public void ApplyCameraZoom(float baseZoom, float zoom)
 82        {
 083            playerMarker.SetZoom(baseZoom, zoom);
 084        }
 85
 86        public void ResetToBaseScale()
 87        {
 088            playerMarker.ResetToBaseScale();
 089        }
 90
 91        private void OnPlayerWorldPositionChange(Vector3 current, Vector3 previous)
 92        {
 093            SetPosition();
 094        }
 95
 96        protected override void DisposeImpl()
 97        {
 698            playerMarker?.Dispose();
 699        }
 100    }
 101}