< Summary

Class:DCL.Builder.PublishProjectController
Assembly:BuilderPublisher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectController.cs
Covered lines:0
Uncovered lines:57
Coverable lines:57
Total lines:144
Line coverage:0% (0 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PublishProjectController()0%2100%
Initialize()0%2100%
Dipose()0%2100%
StartPublishFlow(...)0%6200%
ViewClosed()0%2100%
PublishButtonPressedButtonPressed()0%2100%
StartPublish()0%2100%
DeploySuccess()0%2100%
DeployError(...)0%2100%
DeployScene(...)0%2100%
MockedDelay()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectController.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using UnityEngine;
 5
 6namespace DCL.Builder
 7{
 8    public interface IPublishProjectController
 9    {
 10        /// <summary>
 11        /// Start the publish flow for a project
 12        /// </summary>
 13        /// <param name="builderScene"></param>
 14        void StartPublishFlow(IBuilderScene builderScene);
 15    }
 16
 17    public class PublishProjectController : IPublishProjectController
 18    {
 19        private const string DETAIL_PREFAB_PATH = "PublishDetailView";
 20        private const string PROGRESS_PREFAB_PATH = "PublishProgressView";
 21        private const string SUCCESS_PREFAB_PATH = "PublishSuccessView";
 22
 23        private const string GENERIC_DEPLOY_ERROR = "Error deploying the scene";
 24
 25        public enum ProjectPublishState
 26        {
 27            IDLE = 0,
 28            PUBLISH_CONFIRM = 1,
 29            PUBLISH_IN_PROGRESS = 2,
 30            PUBLISH_END = 3
 31        }
 32
 33        internal IPublishProjectDetailView detailView;
 34        internal IPublishProjectProgressView progressView;
 35        internal IPublishProjectSuccesView succesView;
 36
 37        internal ProjectPublishState projectPublishState = ProjectPublishState.IDLE;
 38        internal BuilderScene sceneToPublish;
 39
 040        public PublishProjectController()
 41        {
 042            detailView = Object.Instantiate(Resources.Load<PublishProjectDetailView>(DETAIL_PREFAB_PATH));
 043            progressView = Object.Instantiate(Resources.Load<PublishProjectProgressView>(PROGRESS_PREFAB_PATH));
 044            succesView = Object.Instantiate(Resources.Load<PublishProjectSuccesView>(SUCCESS_PREFAB_PATH));
 045            Initialize();
 046        }
 47
 48        public void Initialize()
 49        {
 050            detailView.OnCancel += ViewClosed;
 051            detailView.OnPublishButtonPressed += PublishButtonPressedButtonPressed;
 52
 053            progressView.OnViewClosed += ViewClosed;
 054            progressView.OnPublishConfirmButtonPressed += StartPublish;
 55
 056            succesView.OnViewClose += ViewClosed;
 057        }
 58
 59        public void Dipose()
 60        {
 061            detailView.OnCancel -= ViewClosed;
 062            detailView.OnPublishButtonPressed -= PublishButtonPressedButtonPressed;
 63
 064            progressView.OnViewClosed -= ViewClosed;
 065            progressView.OnPublishConfirmButtonPressed -= StartPublish;
 66
 067            succesView.OnViewClose -= ViewClosed;
 68
 069            detailView.Dispose();
 070            progressView.Dispose();
 071            succesView.Dispose();
 072        }
 73
 74        public void StartPublishFlow(IBuilderScene builderScene)
 75        {
 076            if (projectPublishState != ProjectPublishState.IDLE)
 077                return;
 78
 79            //Note: in a future PR we will use IBuilderScene directly
 080            sceneToPublish = (BuilderScene) builderScene;
 081            projectPublishState = ProjectPublishState.PUBLISH_CONFIRM;
 82
 083            detailView.SetProjectToPublish(sceneToPublish);
 084            detailView.Show();
 085        }
 86
 87        private void ViewClosed()
 88        {
 089            projectPublishState = ProjectPublishState.IDLE;
 90
 091            detailView.Hide();
 092            progressView.Hide();
 093            succesView.Hide();
 094        }
 95
 096        private void PublishButtonPressedButtonPressed() { progressView.ShowConfirmPopUp(); }
 97
 98        private void StartPublish()
 99        {
 0100            projectPublishState = ProjectPublishState.PUBLISH_IN_PROGRESS;
 101
 0102            progressView.PublishStarted();
 103
 0104            Promise<bool> deploymentPromise = DeployScene(sceneToPublish);
 0105            deploymentPromise.Then(success =>
 106            {
 0107                if (success)
 0108                    DeploySuccess();
 109                else
 0110                    DeployError(GENERIC_DEPLOY_ERROR);
 0111            });
 0112            deploymentPromise.Catch(DeployError);
 0113        }
 114
 115        private void DeploySuccess()
 116        {
 0117            projectPublishState = ProjectPublishState.PUBLISH_END;
 0118            progressView.Hide();
 0119            succesView.ProjectPublished(sceneToPublish);
 0120        }
 121
 122        private void DeployError(string error)
 123        {
 0124            projectPublishState = ProjectPublishState.PUBLISH_END;
 0125            progressView.PublishError(error);
 0126        }
 127
 128        Promise<bool> DeployScene(BuilderScene scene)
 129        {
 0130            Promise<bool> scenePromise = new Promise<bool>();
 131
 132            //TODO: We need to implement the deployment functionality, for now we just mocked a delay to test the functi
 0133            CoroutineStarter.Start(MockedDelay(scenePromise));
 0134            return scenePromise;
 135        }
 136
 137        // This will be deleted in the future, this just simulate a deploy after 3 seconds to test functionality
 138        IEnumerator MockedDelay(Promise<bool> promise)
 139        {
 0140            yield return new WaitForSeconds(3f);
 0141            promise.Resolve(true);
 0142        }
 143    }
 144}