< Summary

Class:DCL.Builder.SectionScenesController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionScenesController.cs
Covered lines:35
Uncovered lines:11
Coverable lines:46
Total lines:108
Line coverage:76% (35 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionScenesController(...)0%110100%
SectionScenesController()0%110100%
SetViewContainer(...)0%2100%
Dispose()0%110100%
OnShow()0%2100%
OnHide()0%2100%
SetScenes(...)0%220100%
SceneAdded(...)0%2100%
SceneRemoved(...)0%2100%
OnSearchResult(...)0%8.048091.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionScenesController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7namespace DCL.Builder
 8{
 9    internal class SectionScenesController : SectionBase, ISceneListener, ISectionHideContextMenuRequester
 10    {
 11        public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionDeployedScenesView";
 12
 13        public event Action OnRequestContextMenuHide;
 14
 115        public override ISectionSearchHandler searchHandler => sceneSearchHandler;
 16
 17        private readonly SectionPlacesView view;
 18
 419        private readonly ISectionSearchHandler sceneSearchHandler = new SectionSearchHandler();
 20        private Dictionary<string, ISceneCardView> scenesViews;
 21
 222        public SectionScenesController() : this(
 23            Object.Instantiate(Resources.Load<SectionPlacesView>(VIEW_PREFAB_PATH))
 224        ) { }
 25
 426        public SectionScenesController(SectionPlacesView view)
 27        {
 428            this.view = view;
 29
 430            view.OnScrollRectValueChanged += OnRequestContextMenuHide;
 431            sceneSearchHandler.OnResult += OnSearchResult;
 432        }
 33
 034        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 35
 36        public override void Dispose()
 37        {
 238            view.OnScrollRectValueChanged -= OnRequestContextMenuHide;
 239            view.Dispose();
 240        }
 41
 042        protected override void OnShow() { view.SetActive(true); }
 43
 044        protected override void OnHide() { view.SetActive(false); }
 45
 46        void ISceneListener.SetScenes(Dictionary<string, ISceneCardView> scenes)
 47        {
 548            scenesViews = new Dictionary<string, ISceneCardView>(scenes);
 1849            sceneSearchHandler.SetSearchableList(scenes.Values.Select(scene => scene.searchInfo).ToList());
 550        }
 51
 52        void ISceneListener.SceneAdded(ISceneCardView scene)
 53        {
 054            scenesViews.Add(scene.SceneData.id, scene);
 055            sceneSearchHandler.AddItem(scene.searchInfo);
 056        }
 57
 58        void ISceneListener.SceneRemoved(ISceneCardView scene)
 59        {
 060            scenesViews.Remove(scene.SceneData.id);
 061            scene.SetActive(false);
 062        }
 63
 64        private void OnSearchResult(List<ISearchInfo> searchInfoScenes)
 65        {
 666            if (scenesViews == null)
 167                return;
 68
 569            using (var iterator = scenesViews.GetEnumerator())
 70            {
 1871                while (iterator.MoveNext())
 72                {
 1373                    iterator.Current.Value.SetParent(view.GetCardsContainer());
 1374                    iterator.Current.Value.SetActive(false);
 75                }
 576            }
 77
 3678            for (int i = 0; i < searchInfoScenes.Count; i++)
 79            {
 1380                if (!scenesViews.TryGetValue(searchInfoScenes[i].id, out ISceneCardView cardView))
 81                    continue;
 82
 1083                cardView.SetActive(true);
 1084                cardView.SetSiblingIndex(i);
 85            }
 86
 587            if (scenesViews.Count == 0)
 88            {
 289                if (isLoading)
 90                {
 191                    view.SetLoading();
 192                }
 93                else
 94                {
 195                    view.SetEmpty();
 96                }
 197            }
 398            else if (searchInfoScenes.Count == 0)
 99            {
 0100                view.SetNoSearchResult();
 0101            }
 102            else
 103            {
 3104                view.SetFilled();
 105            }
 3106        }
 107    }
 108}