< Summary

Class:DCL.Builder.LeftMenuSettingsViewHandler
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Handlers/LeftMenuSettingsViewHandler.cs
Covered lines:30
Uncovered lines:20
Coverable lines:50
Total lines:126
Line coverage:60% (30 of 50)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LeftMenuSettingsViewHandler(...)0%110100%
Dispose()0%3.143075%
SetProjectData(...)0%330100%
SetThumbnails(...)0%13.015031.58%
SelectProject(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Handlers/LeftMenuSettingsViewHandler.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7namespace DCL.Builder
 8{
 9    [Serializable]
 10    internal class LeftMenuSettingsViewReferences
 11    {
 12        public TextMeshProUGUI titleLabel;
 13        public RawImageFillParent thumbnail;
 14        public GameObject coordsContainer;
 15        public GameObject sizeContainer;
 16        public GameObject entitiesCountContainer;
 17        public TextMeshProUGUI coordsText;
 18        public TextMeshProUGUI sizeText;
 19        public TextMeshProUGUI entitiesCountText;
 20        public GameObject avatarThumbnailContainer;
 21        public RawImage avatarImage;
 22        public TextMeshProUGUI authorNameText;
 23        public LeftMenuButtonToggleView adminsMenuToggle;
 24    }
 25
 26    internal class LeftMenuSettingsViewHandler : IDisposable
 27    {
 28        internal const string PROJECT_TITLE = "Project settings";
 29        internal const string SCENE_TITLE = "Scene settings";
 30
 31        private readonly LeftMenuSettingsViewReferences viewReferences;
 32        private readonly IScenesViewController scenesViewController;
 33        private readonly Texture defaultThumbnail;
 34
 35        private AssetPromise_Texture promiseAvatarThumbnail;
 36        private AssetPromise_Texture promiseSceneThumbnail;
 37
 1738        public LeftMenuSettingsViewHandler(LeftMenuSettingsViewReferences viewReferences, IScenesViewController scenesVi
 39        {
 1740            this.viewReferences = viewReferences;
 1741            this.scenesViewController = scenesViewController;
 42
 1743            defaultThumbnail = viewReferences.thumbnail.texture;
 44
 1745            scenesViewController.OnProjectSelected += SelectProject;
 1746        }
 47
 48        public void Dispose()
 49        {
 1750            scenesViewController.OnProjectSelected -= SelectProject;
 51
 1752            if (promiseAvatarThumbnail != null)
 53            {
 054                AssetPromiseKeeper_Texture.i.Forget(promiseAvatarThumbnail);
 55            }
 1756            if (promiseSceneThumbnail != null)
 57            {
 058                AssetPromiseKeeper_Texture.i.Forget(promiseSceneThumbnail);
 59            }
 60
 1761            promiseAvatarThumbnail = null;
 1762            promiseSceneThumbnail = null;
 1763        }
 64
 65        void SetProjectData(ISceneData sceneData)
 66        {
 267            viewReferences.titleLabel.text = sceneData.isDeployed ? SCENE_TITLE : PROJECT_TITLE;
 268            viewReferences.coordsContainer.SetActive(sceneData.isDeployed);
 269            viewReferences.sizeContainer.SetActive(!sceneData.isDeployed);
 270            viewReferences.entitiesCountContainer.SetActive(!sceneData.isDeployed);
 271            viewReferences.coordsText.text = $"{sceneData.coords.x},{sceneData.coords.y}";
 272            viewReferences.sizeText.text = $"{sceneData.size.x},{sceneData.size.y}m";
 273            viewReferences.entitiesCountText.text = sceneData.entitiesCount.ToString();
 274            viewReferences.authorNameText.text = sceneData.authorName;
 275            viewReferences.adminsMenuToggle.gameObject.SetActive(sceneData.isDeployed);
 76
 277            SetThumbnails(sceneData);
 278        }
 79
 80        void SetThumbnails(ISceneData sceneData)
 81        {
 282            if (string.IsNullOrEmpty(sceneData.authorThumbnail))
 83            {
 284                viewReferences.avatarThumbnailContainer.SetActive(false);
 285            }
 86            else
 87            {
 088                if (promiseAvatarThumbnail != null)
 89                {
 090                    AssetPromiseKeeper_Texture.i.Forget(promiseAvatarThumbnail);
 91                }
 92
 093                promiseAvatarThumbnail = new AssetPromise_Texture(sceneData.authorThumbnail);
 094                promiseAvatarThumbnail.OnFailEvent += (asset, error) => viewReferences.avatarThumbnailContainer.SetActiv
 095                promiseAvatarThumbnail.OnSuccessEvent += asset =>
 96                {
 097                    viewReferences.avatarThumbnailContainer.SetActive(true);
 098                    viewReferences.avatarImage.texture = asset.texture;
 099                };
 0100                AssetPromiseKeeper_Texture.i.Keep(promiseAvatarThumbnail);
 101            }
 102
 2103            if (string.IsNullOrEmpty(sceneData.thumbnailUrl))
 104            {
 2105                viewReferences.thumbnail.texture = defaultThumbnail;
 2106            }
 107            else
 108            {
 0109                if (promiseSceneThumbnail != null)
 110                {
 0111                    AssetPromiseKeeper_Texture.i.Forget(promiseSceneThumbnail);
 112                }
 113
 0114                promiseSceneThumbnail = new AssetPromise_Texture(sceneData.thumbnailUrl);
 0115                promiseSceneThumbnail.OnFailEvent += (asset, error) => viewReferences.thumbnail.texture = defaultThumbna
 0116                promiseSceneThumbnail.OnSuccessEvent += asset =>
 117                {
 0118                    viewReferences.thumbnail.texture = asset.texture;
 0119                };
 0120                AssetPromiseKeeper_Texture.i.Keep(promiseSceneThumbnail);
 121            }
 0122        }
 123
 4124        private void SelectProject(ISceneCardView sceneCardView) { SetProjectData(sceneCardView.SceneData); }
 125    }
 126}