< 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:36
Uncovered lines:25
Coverable lines:61
Total lines:132
Line coverage:59% (36 of 61)
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%56700%
OnHide()0%2100%
SetScenes(...)0%220100%
SceneAdded(...)0%2100%
SceneRemoved(...)0%2100%
OnSearchResult(...)0%14.6613078.57%

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();
 420        private Dictionary<string, ISceneCardView> scenesViews = new Dictionary<string, ISceneCardView>();
 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
 42        protected override void OnShow()
 43        {
 044            view.SetActive(true);
 045            if (scenesViews != null && scenesViews.Count == 0)
 46            {
 047                if (isLoading)
 48                {
 049                    view.SetLoading();
 050                    OnNotEmptyContent?.Invoke();
 051                }
 52                else
 53                {
 054                    view.SetEmpty();
 055                    OnEmptyContent?.Invoke();
 56                }
 057            }
 58            else
 59            {
 060                OnNotEmptyContent?.Invoke();
 61            }
 062        }
 63
 064        protected override void OnHide() { view.SetActive(false); }
 65
 66        void ISceneListener.SetScenes(Dictionary<string, ISceneCardView> scenes)
 67        {
 568            scenesViews = new Dictionary<string, ISceneCardView>(scenes);
 1869            sceneSearchHandler.SetSearchableList(scenes.Values.Select(scene => scene.searchInfo).ToList());
 570        }
 71
 72        void ISceneListener.SceneAdded(ISceneCardView scene)
 73        {
 074            scenesViews.Add(scene.SceneData.id, scene);
 075            sceneSearchHandler.AddItem(scene.searchInfo);
 076        }
 77
 78        void ISceneListener.SceneRemoved(ISceneCardView scene)
 79        {
 080            scenesViews.Remove(scene.SceneData.id);
 081            scene.SetActive(false);
 082        }
 83
 84        private void OnSearchResult(List<ISearchInfo> searchInfoScenes)
 85        {
 686            if (scenesViews == null || searchInfoScenes == null)
 187                return;
 88
 589            using (var iterator = scenesViews.GetEnumerator())
 90            {
 1891                while (iterator.MoveNext())
 92                {
 1393                    iterator.Current.Value.SetParent(view.GetCardsContainer());
 1394                    iterator.Current.Value.SetActive(false);
 95                }
 596            }
 97
 3698            for (int i = 0; i < searchInfoScenes.Count; i++)
 99            {
 13100                if (!scenesViews.TryGetValue(searchInfoScenes[i].id, out ISceneCardView cardView))
 101                    continue;
 102
 10103                cardView.SetActive(true);
 10104                cardView.SetSiblingIndex(i);
 105            }
 106
 5107            if (scenesViews.Count == 0)
 108            {
 2109                if (isLoading)
 110                {
 1111                    view.SetLoading();
 1112                    OnNotEmptyContent?.Invoke();
 0113                }
 114                else
 115                {
 1116                    view.SetEmpty();
 1117                    OnEmptyContent?.Invoke();
 118                }
 0119            }
 3120            else if (searchInfoScenes.Count == 0)
 121            {
 0122                view.SetNoSearchResult();
 0123                OnNotEmptyContent?.Invoke();
 0124            }
 125            else
 126            {
 3127                view.SetFilled();
 3128                OnNotEmptyContent?.Invoke();
 129            }
 0130        }
 131    }
 132}