< Summary

Class:DCL.Components.CameraModeAreasController
Assembly:DCL.Components.CameraModeArea
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/CameraModeArea/CameraModeAreasController.cs
Covered lines:30
Uncovered lines:4
Coverable lines:34
Total lines:124
Line coverage:88.2% (30 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CameraModeAreasController()0%110100%
CameraModeAreasController()0%110100%
AddInsideArea(...)0%220100%
RemoveInsideArea(...)0%4.024090%
ChangeAreaMode(...)0%220100%
IsPlayerInsideAnyArea()0%110100%
ResetCameraMode()0%110100%
IsTheActivelyAffectingArea(...)0%2.062075%
ShowCameraModeLockedNotification()0%2.52050%
HideCameraModeLockedNotification()0%2.52050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/CameraModeArea/CameraModeAreasController.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using DCL.CameraTool;
 3using DCL.NotificationModel;
 4
 5namespace DCL.Components
 6{
 7    public interface ICameraModeAreasController
 8    {
 9        /// <summary>
 10        /// This will change the camera to the passed mode,
 11        /// </summary>
 12        /// <param name="area"></param>
 13        /// <param name="mode"></param>
 14        void ChangeAreaMode(in ICameraModeArea area);
 15
 16        /// <summary>
 17        /// Adds an area
 18        /// </summary>
 19        /// <param name="area"></param>
 20        void AddInsideArea(in ICameraModeArea area);
 21
 22        /// <summary>
 23        /// Remove an area
 24        /// </summary>
 25        /// <param name="area"></param>
 26        void RemoveInsideArea(in ICameraModeArea area);
 27    }
 28
 29    public class CameraModeAreasController : ICameraModeAreasController
 30    {
 31        private const string NOTIFICATION_GROUP = "CameraModeLockedByScene";
 32        private const float NOTIFICATION_TIME = 3;
 33
 134        private static readonly Model notificationModel = new Model()
 35        {
 36            type = Type.CAMERA_MODE_LOCKED_BY_SCENE,
 37            groupID = NOTIFICATION_GROUP,
 38            timer = NOTIFICATION_TIME
 39        };
 40
 41        private CameraMode.ModeId initialCameraMode;
 1242        private readonly List<ICameraModeArea> insideAreasList = new List<ICameraModeArea>();
 43
 44        public void AddInsideArea(in ICameraModeArea area)
 45        {
 1746            if (!IsPlayerInsideAnyArea())
 47            {
 1048                initialCameraMode = CommonScriptableObjects.cameraMode.Get();
 1049                CommonScriptableObjects.cameraModeInputLocked.Set(true);
 1050                ShowCameraModeLockedNotification();
 51            }
 52
 1753            CommonScriptableObjects.cameraMode.Set(area.cameraMode);
 1754            insideAreasList.Add(area);
 1755        }
 56
 57        public void RemoveInsideArea(in ICameraModeArea area)
 58        {
 1759            int affectingAreasCount = insideAreasList.Count;
 60
 1761            if (affectingAreasCount == 0)
 62            {
 063                return;
 64            }
 65
 1766            if (affectingAreasCount == 1)
 67            {
 68                // reset to initial state of camera mode
 1069                ResetCameraMode();
 70
 71                //remove notification
 1072                HideCameraModeLockedNotification();
 73            }
 774            else if (IsTheActivelyAffectingArea(area))
 75            {
 76                // set camera mode to the previous area the player is in
 177                CommonScriptableObjects.cameraMode.Set(insideAreasList[affectingAreasCount - 2].cameraMode);
 78            }
 79
 1780            insideAreasList.Remove(area);
 1781        }
 82
 83        public void ChangeAreaMode(in ICameraModeArea area)
 84        {
 285            if (IsTheActivelyAffectingArea(area))
 86            {
 287                CommonScriptableObjects.cameraMode.Set(area.cameraMode);
 88            }
 289        }
 90
 91        private bool IsPlayerInsideAnyArea()
 92        {
 1793            return insideAreasList.Count > 0;
 94        }
 95
 96        private void ResetCameraMode()
 97        {
 1098            CommonScriptableObjects.cameraMode.Set(initialCameraMode);
 1099            CommonScriptableObjects.cameraModeInputLocked.Set(false);
 10100        }
 101
 102        private bool IsTheActivelyAffectingArea(in ICameraModeArea area)
 103        {
 9104            int affectingAreasCount = insideAreasList.Count;
 105
 9106            if (affectingAreasCount == 0)
 107            {
 0108                return false;
 109            }
 110
 9111            return insideAreasList[affectingAreasCount - 1] == area;
 112        }
 113
 114        internal virtual void ShowCameraModeLockedNotification()
 115        {
 10116            NotificationsController.i?.ShowNotification(notificationModel);
 0117        }
 118
 119        internal virtual void HideCameraModeLockedNotification()
 120        {
 10121            NotificationsController.i?.DismissAllNotifications(NOTIFICATION_GROUP);
 0122        }
 123    }
 124}