< Summary

Class:ControlsHUDController
Assembly:ControlsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ControlsHUD/ControlsHUDController.cs
Covered lines:29
Uncovered lines:18
Coverable lines:47
Total lines:100
Line coverage:61.7% (29 of 47)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ControlsHUDController()0%2.022081.82%
SetVisibility(...)0%110100%
OnControlsVisibleChanged(...)0%110100%
SetVisibility_Internal(...)0%12.478058.82%
Dispose()0%3.043083.33%
IsVisible()0%2.152066.67%
Hide(...)0%6200%
OnKernelConfigChanged(...)0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ControlsHUD/ControlsHUDController.cs

#LineLine coverage
 1using DCL;
 2using UnityEngine;
 3using DCL.Helpers;
 4
 5public class ControlsHUDController : IHUD
 6{
 7    internal ControlsHUDView view;
 8
 9    private bool prevMouseLockState = false;
 10
 11    public event System.Action OnControlsOpened;
 12    public event System.Action OnControlsClosed;
 13
 1114    public BaseVariable<bool> controlsVisible => DataStore.i.HUDs.controlsVisible;
 15
 316    public ControlsHUDController()
 17    {
 318        view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("ControlsHUD")).GetComponent<ControlsHUDView>()
 319        view.name = "_ControlsHUD";
 320        view.gameObject.SetActive(false);
 21
 322        controlsVisible.OnChange += OnControlsVisibleChanged;
 323        OnControlsVisibleChanged(controlsVisible.Get(), false);
 24
 325        view.onCloseActionTriggered += Hide;
 26
 327        if (!DCL.Configuration.EnvironmentSettings.RUNNING_TESTS)
 28        {
 029            KernelConfig.i.EnsureConfigInitialized().Then(config => OnKernelConfigChanged(config, null));
 030            KernelConfig.i.OnChange += OnKernelConfigChanged;
 31        }
 332    }
 33
 434    public void SetVisibility(bool visible) { controlsVisible.Set(visible); }
 35
 1036    private void OnControlsVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 37
 38    private void SetVisibility_Internal(bool visible)
 39    {
 540        if (!view)
 041            return;
 42
 543        if (IsVisible() && !visible)
 44        {
 045            if (prevMouseLockState)
 46            {
 047                Utils.LockCursor();
 48            }
 49
 050            view.showHideAnimator.Hide();
 051            OnControlsClosed?.Invoke();
 52
 053            AudioScriptableObjects.fadeOut.Play(true);
 054        }
 555        else if (!IsVisible() && visible)
 56        {
 257            prevMouseLockState = Utils.IsCursorLocked;
 258            Utils.UnlockCursor();
 259            view.gameObject.SetActive(true);
 260            view.showHideAnimator.Show();
 261            OnControlsOpened?.Invoke();
 262            AudioScriptableObjects.fadeIn.Play(true);
 63        }
 564    }
 65
 66    public void Dispose()
 67    {
 368        controlsVisible.OnChange -= OnControlsVisibleChanged;
 369        if (view)
 70        {
 371            Object.Destroy(view.gameObject);
 72        }
 73
 374        if (!DCL.Configuration.EnvironmentSettings.RUNNING_TESTS)
 75        {
 076            KernelConfig.i.OnChange -= OnKernelConfigChanged;
 77        }
 378    }
 79
 80    public bool IsVisible()
 81    {
 1082        if (!view)
 083            return false;
 84
 1085        return view.showHideAnimator.isVisible;
 86    }
 87
 88    public void Hide(bool restorePointerLockStatus)
 89    {
 090        if (!restorePointerLockStatus)
 091            prevMouseLockState = false;
 092        controlsVisible.Set(false);
 093    }
 94
 95    private void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel previous)
 96    {
 097        view?.voiceChatButton.SetActive(current.comms.voiceChatEnabled);
 098        view?.builderInWorldButton.SetActive(current.features.enableBuilderInWorld);
 099    }
 100}