< 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:32
Uncovered lines:3
Coverable lines:35
Total lines:101
Line coverage:91.4% (32 of 35)
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.014090.91%
ChangeAreaMode(...)0%220100%
IsPlayerInsideAnyArea()0%2100%
ResetCameraMode()0%110100%
IsTheActivelyAffectingArea(...)0%2.062075%
ShowCameraModeLockedNotification()0%220100%
HideCameraModeLockedNotification()0%220100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using DCL.NotificationModel;
 3
 4namespace DCL.Components
 5{
 6    internal class CameraModeAreasController
 7    {
 8        private const string NOTIFICATION_GROUP = "CameraModeLockedByScene";
 9        private const float NOTIFICATION_TIME = 3;
 10
 111        private static readonly Model notificationModel = new Model()
 12        {
 13            type = Type.CAMERA_MODE_LOCKED_BY_SCENE,
 14            groupID = NOTIFICATION_GROUP,
 15            timer = NOTIFICATION_TIME
 16        };
 17
 18        private CameraMode.ModeId initialCameraMode;
 419        private readonly List<ICameraModeArea> insideAreasList = new List<ICameraModeArea>();
 20
 21        public void AddInsideArea(in ICameraModeArea area)
 22        {
 1723            if (!IsPlayerInsideAnyArea())
 24            {
 1025                initialCameraMode = CommonScriptableObjects.cameraMode.Get();
 1026                CommonScriptableObjects.cameraModeInputLocked.Set(true);
 1027                ShowCameraModeLockedNotification();
 28            }
 29
 1730            CommonScriptableObjects.cameraMode.Set(area.cameraMode);
 1731            insideAreasList.Add(area);
 1732        }
 33
 34        public void RemoveInsideArea(in ICameraModeArea area)
 35        {
 1736            int affectingAreasCount = insideAreasList.Count;
 37
 1738            if (affectingAreasCount == 0)
 39            {
 040                return;
 41            }
 42
 1743            if (affectingAreasCount == 1)
 44            {
 45                // reset to initial state of camera mode
 1046                ResetCameraMode();
 47
 48                //remove notification
 1049                HideCameraModeLockedNotification();
 1050            }
 751            else if (IsTheActivelyAffectingArea(area))
 52            {
 53                // set camera mode to the previous area the player is in
 154                CommonScriptableObjects.cameraMode.Set(insideAreasList[affectingAreasCount - 2].cameraMode);
 55            }
 56
 1757            insideAreasList.Remove(area);
 1758        }
 59
 60        public void ChangeAreaMode(in ICameraModeArea area, in CameraMode.ModeId mode)
 61        {
 262            if (IsTheActivelyAffectingArea(area))
 63            {
 264                CommonScriptableObjects.cameraMode.Set(mode);
 65            }
 266        }
 67
 68        private bool IsPlayerInsideAnyArea()
 69        {
 070            return insideAreasList.Count > 0;
 71        }
 72
 73        private void ResetCameraMode()
 74        {
 1075            CommonScriptableObjects.cameraMode.Set(initialCameraMode);
 1076            CommonScriptableObjects.cameraModeInputLocked.Set(false);
 1077        }
 78
 79        private bool IsTheActivelyAffectingArea(in ICameraModeArea area)
 80        {
 981            int affectingAreasCount = insideAreasList.Count;
 82
 983            if (affectingAreasCount == 0)
 84            {
 085                return false;
 86            }
 87
 988            return insideAreasList[affectingAreasCount - 1] == area;
 89        }
 90
 91        internal virtual void ShowCameraModeLockedNotification()
 92        {
 1093            NotificationsController.i?.ShowNotification(notificationModel);
 1094        }
 95
 96        internal virtual void HideCameraModeLockedNotification()
 97        {
 1098            NotificationsController.i?.DismissAllNotifications(NOTIFICATION_GROUP);
 1099        }
 100    }
 101}