< Summary

Class:SectionDeployedScenesController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/SectionController/MenuSections/SectionDeployedScenesController.cs
Covered lines:37
Uncovered lines:9
Coverable lines:46
Total lines:105
Line coverage:80.4% (37 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionDeployedScenesController(...)0%110100%
SectionDeployedScenesController()0%110100%
SetViewContainer(...)0%110100%
Dispose()0%110100%
OnShow()0%110100%
OnHide()0%2100%
OnSetScenes(...)0%220100%
OnSceneAdded(...)0%2100%
OnSceneRemoved(...)0%2100%
OnSearchResult(...)0%8.048091.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/SectionController/MenuSections/SectionDeployedScenesController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7internal class SectionDeployedScenesController : SectionBase, IDeployedSceneListener, ISectionHideContextMenuRequester
 8{
 9    public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionDeployedScenesView";
 10
 11    public event Action OnRequestContextMenuHide;
 12
 213    public override ISectionSearchHandler searchHandler => sceneSearchHandler;
 14
 15    private readonly SectionDeployedScenesView view;
 16
 517    private readonly ISectionSearchHandler sceneSearchHandler = new SectionSearchHandler();
 18    private Dictionary<string, ISceneCardView> scenesViews;
 19
 320    public SectionDeployedScenesController() : this(
 21        Object.Instantiate(Resources.Load<SectionDeployedScenesView>(VIEW_PREFAB_PATH))
 322    ) { }
 23
 524    public SectionDeployedScenesController(SectionDeployedScenesView view)
 25    {
 526        this.view = view;
 27
 528        view.OnScrollRectValueChanged += OnRequestContextMenuHide;
 529        sceneSearchHandler.OnResult += OnSearchResult;
 530    }
 31
 232    public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 33
 34    public override void Dispose()
 35    {
 336        view.OnScrollRectValueChanged -= OnRequestContextMenuHide;
 337        view.Dispose();
 338    }
 39
 240    protected override void OnShow() { view.SetActive(true); }
 41
 042    protected override void OnHide() { view.SetActive(false); }
 43
 44    void IDeployedSceneListener.OnSetScenes(Dictionary<string, ISceneCardView> scenes)
 45    {
 646        scenesViews = new Dictionary<string, ISceneCardView>(scenes);
 1947        sceneSearchHandler.SetSearchableList(scenes.Values.Select(scene => scene.searchInfo).ToList());
 648    }
 49
 50    void IDeployedSceneListener.OnSceneAdded(ISceneCardView scene)
 51    {
 052        scenesViews.Add(scene.sceneData.id, scene);
 053        sceneSearchHandler.AddItem(scene.searchInfo);
 054    }
 55
 56    void IDeployedSceneListener.OnSceneRemoved(ISceneCardView scene)
 57    {
 058        scenesViews.Remove(scene.sceneData.id);
 059        scene.SetActive(false);
 060    }
 61
 62    private void OnSearchResult(List<ISearchInfo> searchInfoScenes)
 63    {
 764        if (scenesViews == null)
 165            return;
 66
 667        using (var iterator = scenesViews.GetEnumerator())
 68        {
 1969            while (iterator.MoveNext())
 70            {
 1371                iterator.Current.Value.SetParent(view.GetCardsContainer());
 1372                iterator.Current.Value.SetActive(false);
 73            }
 674        }
 75
 3876        for (int i = 0; i < searchInfoScenes.Count; i++)
 77        {
 1378            if (!scenesViews.TryGetValue(searchInfoScenes[i].id, out ISceneCardView cardView))
 79                continue;
 80
 1081            cardView.SetActive(true);
 1082            cardView.SetSiblingIndex(i);
 83        }
 84
 685        if (scenesViews.Count == 0)
 86        {
 387            if (isLoading)
 88            {
 289                view.SetLoading();
 290            }
 91            else
 92            {
 193                view.SetEmpty();
 94            }
 195        }
 396        else if (searchInfoScenes.Count == 0)
 97        {
 098            view.SetNoSearchResult();
 099        }
 100        else
 101        {
 3102            view.SetFilled();
 103        }
 3104    }
 105}