< Summary

Class:EmotesHUDController
Assembly:EmotesHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesHUD/EmotesHUDController.cs
Covered lines:31
Uncovered lines:2
Coverable lines:33
Total lines:69
Line coverage:93.9% (31 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmotesHUDController()0%110100%
SetVisibility(...)0%110100%
OnEmoteVisibleChanged(...)0%110100%
SetVisibility_Internal(...)0%220100%
Dispose()0%220100%
EmoteCalled(...)0%110100%
OnViewClosed()0%2100%
OnAvatarEmoteSet(...)0%110100%
OnCloseWindowPressed(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesHUD/EmotesHUDController.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using UnityEngine;
 4
 5public class EmotesHUDController : IHUD
 6{
 7    internal EmotesHUDView view;
 208    private BaseVariable<bool> emotesVisible => DataStore.i.HUDs.emotesVisible;
 9
 2610    private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile();
 11    private InputAction_Trigger closeWindow;
 12
 613    public EmotesHUDController()
 14    {
 615        closeWindow = Resources.Load<InputAction_Trigger>("CloseWindow");
 616        closeWindow.OnTriggered += OnCloseWindowPressed;
 617        view = EmotesHUDView.Create();
 618        view.Initialize(EmoteCalled);
 619        view.OnClose += OnViewClosed;
 20
 621        ownUserProfile.OnAvatarEmoteSet += OnAvatarEmoteSet;
 622        emotesVisible.OnChange += OnEmoteVisibleChanged;
 623        OnEmoteVisibleChanged(emotesVisible.Get(), false);
 624    }
 25
 26    public void SetVisibility(bool visible)
 27    {
 28        //TODO once kernel sends visible properly
 29        //expressionsVisible.Set(visible);
 230    }
 1631    private void OnEmoteVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 32    public void SetVisibility_Internal(bool visible)
 33    {
 834        view.SetVisiblity(visible);
 35
 836        if ( visible )
 37        {
 138            DCL.Helpers.Utils.UnlockCursor();
 139            ownUserProfile.snapshotObserver.AddListener(view.UpdateAvatarSprite);
 140        }
 41        else
 42        {
 43            // Avoid locking cursor. It produces undesired mouse locking the first time you gain focus in the window
 44            // during loading screen or first avatar creation
 45            //DCL.Helpers.Utils.LockCursor();
 746            ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite);
 47        }
 748    }
 49
 50    public void Dispose()
 51    {
 652        ownUserProfile.snapshotObserver.RemoveListener(view.UpdateAvatarSprite);
 653        closeWindow.OnTriggered -= OnCloseWindowPressed;
 654        ownUserProfile.OnAvatarEmoteSet -= OnAvatarEmoteSet;
 655        emotesVisible.OnChange -= OnEmoteVisibleChanged;
 56
 657        if (view != null)
 58        {
 659            view.CleanUp();
 660            UnityEngine.Object.Destroy(view.gameObject);
 61        }
 662    }
 63
 464    public void EmoteCalled(string id) { UserProfile.GetOwnUserProfile().SetAvatarExpression(id); }
 65
 066    private void OnViewClosed() { emotesVisible.Set(false); }
 467    private void OnAvatarEmoteSet(string id, long timestamp) { emotesVisible.Set(false); }
 068    private void OnCloseWindowPressed(DCLAction_Trigger action) { emotesVisible.Set(false); }
 69}