< Summary

Class:DCLServices.MapRendererV2.MapCameraController.MapCameraInteractivityController
Assembly:MapRendererV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapCameraController/MapCameraInteractivityController.cs
Covered lines:0
Uncovered lines:35
Coverable lines:35
Total lines:101
Line coverage:0% (0 of 35)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:12
Method coverage:0% (0 of 12)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MapCameraInteractivityController(...)0%2100%
HighlightParcel(...)0%6200%
Initialize(...)0%6200%
RemoveHighlight()0%6200%
TryGetParcel(...)0%2100%
GetNormalizedPosition(...)0%12300%
GetLocalPosition(...)0%12300%
Dispose()0%2100%
Release()0%6200%
ApplyCameraZoom(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapCameraController/MapCameraInteractivityController.cs

#LineLine coverage
 1using DCLServices.MapRendererV2.CoordsUtils;
 2using DCLServices.MapRendererV2.MapLayers;
 3using DCLServices.MapRendererV2.MapLayers.ParcelHighlight;
 4using MainScripts.DCL.Helpers.Utils;
 5using UnityEngine;
 6using UnityEngine.Pool;
 7
 8namespace DCLServices.MapRendererV2.MapCameraController
 9{
 10    internal class MapCameraInteractivityController : IMapInteractivityControllerInternal
 11    {
 12        private readonly Transform cameraParent;
 13        private readonly IObjectPool<IParcelHighlightMarker> markersPool;
 14        private readonly ICoordsUtils coordsUtils;
 15        private readonly Camera camera;
 16
 17        private IParcelHighlightMarker marker;
 18
 019        public bool HighlightEnabled { get; private set; }
 20
 021        public MapCameraInteractivityController(
 22            Transform cameraParent,
 23            Camera camera,
 24            IObjectPool<IParcelHighlightMarker> markersPool,
 25            ICoordsUtils coordsUtils)
 26        {
 027            this.cameraParent = cameraParent;
 028            this.markersPool = markersPool;
 029            this.coordsUtils = coordsUtils;
 030            this.camera = camera;
 031        }
 32
 33        public void HighlightParcel(Vector2Int parcel)
 34        {
 035            if (marker == null)
 036                return;
 37
 38            // make position discrete
 039            var localPosition = coordsUtils.CoordsToPosition(parcel, marker);
 40
 041            marker.Activate();
 042            marker.SetCoordinates(parcel, localPosition);
 043        }
 44
 45        public void Initialize(MapLayer layers)
 46        {
 047            HighlightEnabled = EnumUtils.HasFlag(layers, MapLayer.ParcelHoverHighlight);
 48
 049            if (HighlightEnabled)
 050                marker = markersPool.Get();
 051        }
 52
 53        public void RemoveHighlight()
 54        {
 055            marker?.Deactivate();
 056        }
 57
 58        public bool TryGetParcel(Vector2 normalizedCoordinates, out Vector2Int parcel) =>
 059            coordsUtils.TryGetCoordsWithinInteractableBounds(GetLocalPosition(normalizedCoordinates), out parcel);
 60
 61        public Vector2 GetNormalizedPosition(Vector2Int parcel)
 62        {
 063            var discreteLocalPosition = coordsUtils.CoordsToPosition(parcel);
 64
 65            // Convert local Position to viewPort
 066            var worldPosition = cameraParent ? cameraParent.TransformPoint(discreteLocalPosition) : discreteLocalPositio
 067            var viewPortPosition = camera.WorldToViewportPoint(worldPosition);
 68
 069            return viewPortPosition;
 70        }
 71
 72        private Vector3 GetLocalPosition(Vector2 normalizedCoordinates)
 73        {
 74            // normalized position is equal to viewport position
 075            var worldPoint = camera.ViewportToWorldPoint(normalizedCoordinates);
 76
 077            var localPosition = cameraParent ? cameraParent.InverseTransformPoint(worldPoint) : worldPoint;
 078            localPosition.z = 0;
 079            return localPosition;
 80        }
 81
 82        public void Dispose()
 83        {
 84
 085        }
 86
 87        public void Release()
 88        {
 089            if (marker != null)
 90            {
 091                markersPool.Release(marker);
 092                marker = null;
 93            }
 094        }
 95
 96        public void ApplyCameraZoom(float baseZoom, float newZoom)
 97        {
 098            marker?.SetZoom(baseZoom, newZoom);
 099        }
 100    }
 101}