< Summary

Class:MinimapHUDController
Assembly:MinimapHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Minimap/MinimapHUDController.cs
Covered lines:42
Uncovered lines:15
Coverable lines:57
Total lines:126
Line coverage:73.6% (42 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MinimapHUDController(...)0%110100%
MinimapHUDController()0%110100%
CreateView()0%110100%
Initialize()0%110100%
Dispose()0%220100%
OnPlayerCoordsChange(...)0%4.054085.71%
UpdateData(...)0%220100%
UpdateSceneName(...)0%220100%
UpdatePlayerPosition(...)0%110100%
UpdatePlayerPosition(...)0%220100%
AddZoomDelta(...)0%2100%
ToggleOptions()0%2100%
AddBookmark()0%6200%
ReportScene()0%6200%
ChangeVisibilityForBuilderInWorld(...)0%2100%
SetVisibility(...)0%110100%
AddUsersAroundIndicator(...)0%110100%
OnOnSceneInfoUpdated(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Minimap/MinimapHUDController.cs

#LineLine coverage
 1using DCL.Interface;
 2using UnityEngine;
 3
 4public class MinimapHUDController : IHUD
 5{
 6    private static bool VERBOSE = false;
 7
 8    public MinimapHUDView view;
 109    private FloatVariable minimapZoom => CommonScriptableObjects.minimapZoom;
 010    private StringVariable currentSceneId => CommonScriptableObjects.sceneID;
 11
 1012    public MinimapHUDModel model { get; private set; } = new MinimapHUDModel();
 13
 2014    public MinimapHUDController() : this(new MinimapHUDModel()) { }
 15
 1016    public MinimapHUDController(MinimapHUDModel model)
 17    {
 1018        CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoordsChange;
 1019        CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.OnChange += ChangeVisibilityForBuilderInWor
 1020        minimapZoom.Set(1f);
 1021        UpdateData(model);
 1022    }
 23
 924    protected internal virtual MinimapHUDView CreateView() { return MinimapHUDView.Create(this); }
 25
 26    public void Initialize()
 27    {
 928        view = CreateView();
 929        UpdateData(model);
 930    }
 31
 32    public void Dispose()
 33    {
 1034        if (view != null)
 935            UnityEngine.Object.Destroy(view.gameObject);
 36
 1037        CommonScriptableObjects.playerCoords.OnChange -= OnPlayerCoordsChange;
 1038        CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.OnChange -= ChangeVisibilityForBuilderInWor
 1039        MinimapMetadata.GetMetadata().OnSceneInfoUpdated -= OnOnSceneInfoUpdated;
 1040    }
 41
 42    private void OnPlayerCoordsChange(Vector2Int current, Vector2Int previous)
 43    {
 144        UpdatePlayerPosition(current);
 45
 146        MinimapMetadata.GetMetadata().OnSceneInfoUpdated -= OnOnSceneInfoUpdated;
 147        MinimapMetadata.MinimapSceneInfo sceneInfo = MinimapMetadata.GetMetadata().GetSceneInfo(current.x, current.y);
 148        UpdateSceneName(sceneInfo?.name);
 49
 50        // NOTE: in some cases playerCoords OnChange is triggered before kernel's message with the scene info arrives.
 51        // so in that scenario we subscribe to MinimapMetadata event to wait for the scene info.
 152        if (sceneInfo == null)
 53        {
 054            MinimapMetadata.GetMetadata().OnSceneInfoUpdated += OnOnSceneInfoUpdated;
 55        }
 156    }
 57
 58    public void UpdateData(MinimapHUDModel model)
 59    {
 1960        this.model = model;
 1961        view?.UpdateData(this.model);
 962    }
 63
 64    public void UpdateSceneName(string sceneName)
 65    {
 266        model.sceneName = sceneName;
 267        view?.UpdateData(model);
 168    }
 69
 70    public void UpdatePlayerPosition(Vector2 position)
 71    {
 72        const string format = "{0},{1}";
 273        UpdatePlayerPosition(string.Format(format, position.x, position.y));
 274    }
 75
 76    public void UpdatePlayerPosition(string position)
 77    {
 378        model.playerPosition = position;
 379        view?.UpdateData(model);
 280    }
 81
 082    public void AddZoomDelta(float delta) { minimapZoom.Set(Mathf.Clamp01(minimapZoom.Get() + delta)); }
 83
 084    public void ToggleOptions() { view.ToggleOptions(); }
 85
 86    public void AddBookmark()
 87    {
 88        //TODO:
 089        if (VERBOSE)
 90        {
 091            Debug.Log("Add bookmark pressed");
 92        }
 093    }
 94
 95    public void ReportScene()
 96    {
 097        if (!string.IsNullOrEmpty(currentSceneId))
 098            WebInterface.SendReportScene(currentSceneId);
 099    }
 100
 0101    public void ChangeVisibilityForBuilderInWorld(bool current, bool previus) { view.gameObject.SetActive(current); }
 102
 2103    public void SetVisibility(bool visible) { view.SetVisibility(visible); }
 104
 105    /// <summary>
 106    /// Enable user's around button/indicator that shows the amount of users around player
 107    /// and toggle the list of players' visibility when pressed
 108    /// </summary>
 109    /// <param name="controller">Controller for the players' list HUD</param>
 110    public void AddUsersAroundIndicator(UsersAroundListHUDController controller)
 111    {
 1112        view.usersAroundListHudButton.gameObject.SetActive(true);
 1113        controller.SetButtonView(view.usersAroundListHudButton);
 1114        controller.ToggleUsersCount(false);
 1115        KernelConfig.i.EnsureConfigInitialized().Then(kc => controller.ToggleUsersCount(kc.features.enablePeopleCounter)
 1116    }
 117
 118    private void OnOnSceneInfoUpdated(MinimapMetadata.MinimapSceneInfo sceneInfo)
 119    {
 0120        if (sceneInfo.parcels.Contains(CommonScriptableObjects.playerCoords.Get()))
 121        {
 0122            MinimapMetadata.GetMetadata().OnSceneInfoUpdated -= OnOnSceneInfoUpdated;
 0123            UpdateSceneName(sceneInfo.name);
 124        }
 0125    }
 126}