< Summary

Class:DCL.Builder.SectionSceneGeneralSettingsController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionSceneGeneralSettingsController.cs
Covered lines:19
Uncovered lines:22
Coverable lines:41
Total lines:87
Line coverage:46.3% (19 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneGeneralSettingsController(...)0%110100%
SectionSceneGeneralSettingsController()0%2100%
Dispose()0%110100%
SetViewContainer(...)0%2100%
SetSceneData(...)0%440100%
OnShow()0%2100%
OnHide()0%2100%
OnSelectScene(...)0%2100%
OnApplyChanges()0%42600%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Linq;
 3using UnityEngine;
 4using Object = UnityEngine.Object;
 5
 6namespace DCL.Builder
 7{
 8    internal class SectionSceneGeneralSettingsController : SectionBase, ISelectSceneListener, ISectionUpdateSceneDataReq
 9    {
 10        public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionSceneGeneralSettingsView";
 11
 12        internal const string PERMISSION_MOVE_PLAYER = "ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE";
 13        internal const string PERMISSION_TRIGGER_EMOTES = "ALLOW_TO_TRIGGER_AVATAR_EMOTE";
 14
 15        private ISceneData sceneData;
 16
 317        private readonly SceneDataUpdatePayload sceneDataUpdatePayload = new SceneDataUpdatePayload();
 18        private readonly SectionSceneGeneralSettingsView view;
 19
 20        public event Action<string, SceneDataUpdatePayload> OnRequestUpdateSceneData;
 21
 022        public SectionSceneGeneralSettingsController() : this(
 23            Object.Instantiate(Resources.Load<SectionSceneGeneralSettingsView>(VIEW_PREFAB_PATH))
 024        ) { }
 25
 326        public SectionSceneGeneralSettingsController(SectionSceneGeneralSettingsView view)
 27        {
 328            this.view = view;
 329            view.OnApplyChanges += OnApplyChanges;
 330        }
 31
 32        public override void Dispose()
 33        {
 334            view.OnApplyChanges -= OnApplyChanges;
 335            Object.Destroy(view.gameObject);
 336        }
 37
 038        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 39
 40        public void SetSceneData(ISceneData sceneData)
 41        {
 342            this.sceneData = sceneData;
 43
 344            view.SetName(sceneData.name);
 345            view.SetDescription(sceneData.description);
 346            view.SetConfigurationActive(sceneData.isDeployed);
 347            view.SetPermissionsActive(sceneData.isDeployed);
 48
 349            if (sceneData.isDeployed)
 50            {
 251                view.SetAllowMovePlayer(sceneData.requiredPermissions != null && sceneData.requiredPermissions.Contains(
 252                view.SetAllowTriggerEmotes(sceneData.requiredPermissions != null && sceneData.requiredPermissions.Contai
 253                view.SetAllowVoiceChat(sceneData.allowVoiceChat);
 254                view.SetMatureContent(sceneData.isMatureContent);
 55            }
 356        }
 57
 058        protected override void OnShow() { view.SetActive(true); }
 59
 060        protected override void OnHide() { view.SetActive(false); }
 061        void ISelectSceneListener.OnSelectScene(ISceneCardView sceneCardView) { SetSceneData(sceneCardView.SceneData); }
 62
 63        void OnApplyChanges()
 64        {
 065            sceneDataUpdatePayload.name = view.GetName();
 066            sceneDataUpdatePayload.description = view.GetDescription();
 067            sceneDataUpdatePayload.allowVoiceChat = view.GetAllowVoiceChat();
 068            sceneDataUpdatePayload.isMatureContent = view.GetMatureContent();
 69
 070            string[] permissions = null;
 071            if (view.GetAllowMovePlayer() && view.GetAllowTriggerEmotes())
 72            {
 073                permissions = new [] { PERMISSION_MOVE_PLAYER, PERMISSION_TRIGGER_EMOTES };
 074            }
 075            else if (view.GetAllowMovePlayer())
 76            {
 077                permissions = new [] { PERMISSION_MOVE_PLAYER };
 078            }
 079            else if (view.GetAllowTriggerEmotes())
 80            {
 081                permissions = new [] { PERMISSION_TRIGGER_EMOTES };
 82            }
 083            sceneDataUpdatePayload.requiredPermissions = permissions;
 084            OnRequestUpdateSceneData?.Invoke(sceneData.id, sceneDataUpdatePayload);
 085        }
 86    }
 87}