< Summary

Class:LandPublisherController
Assembly:BuilderPublisher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/Lands/LandPublisherController.cs
Covered lines:15
Uncovered lines:17
Coverable lines:32
Total lines:114
Line coverage:46.8% (15 of 32)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize()0%2100%
Initialize(...)0%110100%
Dispose()0%110100%
SetActive(...)0%110100%
Cancel()0%220100%
StartPublishFlow(...)0%2100%
Publish()0%6200%
SetDefaultPublicationInfo()0%110100%
SetCustomPublicationInfo(...)0%2100%
SetPublicationScreenshot(...)0%2100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.Builder;
 3using UnityEngine;
 4
 5public interface ILandPublisherController
 6{
 7    /// <summary>
 8    /// When the publish button has been pressed
 9    /// </summary>
 10    event Action<IBuilderScene> OnPublishPressed;
 11
 12    /// <summary>
 13    /// When the publish action is canceled
 14    /// </summary>
 15    event Action OnPublishCancel;
 16
 17    /// <summary>
 18    /// Init the controller with the default view
 19    /// </summary>
 20    void Initialize();
 21
 22    /// <summary>
 23    /// Init the view with an specific view
 24    /// </summary>
 25    /// <param name="landPublisherView"></param>
 26    void Initialize(ILandPublisherView landPublisherView);
 27
 28    /// <summary>
 29    /// Set the view active
 30    /// </summary>
 31    /// <param name="isActive"></param>
 32    void SetActive(bool isActive);
 33
 34    /// <summary>
 35    /// This will start the flow of the publishing
 36    /// </summary>
 37    /// <param name="scene"></param>
 38    void StartPublishFlow(IBuilderScene scene);
 39    void Dispose();
 40}
 41
 42public class LandPublisherController : ILandPublisherController
 43{
 44    public event Action OnPublishCancel;
 45    public event Action<IBuilderScene> OnPublishPressed;
 46
 47    internal const string PREFAB_PATH = "Land/LandPublisherView";
 48    internal const string DEFAULT_SCENE_NAME = "My new place";
 49    internal const string DEFAULT_SCENE_DESC = "";
 50
 51    internal ILandPublisherView landPublisherView;
 52    internal IBuilderScene sceneToPublish;
 53
 54    public void Initialize()
 55    {
 056        var template = Resources.Load<LandPublisherView>(PREFAB_PATH);
 057        Initialize(GameObject.Instantiate(template));
 058    }
 59
 60    public void Initialize(ILandPublisherView landPublisherView)
 61    {
 362        this.landPublisherView = landPublisherView;
 63
 364        landPublisherView.OnCancel += Cancel;
 365        landPublisherView.OnPublish += Publish;
 66
 367        SetDefaultPublicationInfo();
 368    }
 69
 70    public void Dispose()
 71    {
 372        landPublisherView.OnCancel -= Cancel;
 373        landPublisherView.OnPublish -= Publish;
 374    }
 75
 676    public void SetActive(bool isActive) { landPublisherView.SetActive(isActive); }
 77
 78    public void Cancel()
 79    {
 180        SetActive(false);
 181        OnPublishCancel?.Invoke();
 182    }
 83
 84    public void StartPublishFlow(IBuilderScene scene)
 85    {
 086        sceneToPublish = scene;
 087        SetCustomPublicationInfo(scene);
 088        SetActive(true);
 089    }
 90
 91    public void Publish()
 92    {
 093        sceneToPublish.manifest.project.title = landPublisherView.GetSceneName();
 094        sceneToPublish.manifest.project.description = landPublisherView.GetSceneDescription();
 95
 096        SetActive(false);
 097        OnPublishPressed?.Invoke(sceneToPublish);
 098    }
 99
 100    public void SetDefaultPublicationInfo()
 101    {
 3102        landPublisherView.SetSceneName(DEFAULT_SCENE_NAME);
 3103        landPublisherView.SetSceneDescription(DEFAULT_SCENE_DESC);
 3104    }
 105
 106    public void SetCustomPublicationInfo(IBuilderScene scene)
 107    {
 0108        landPublisherView.SetSceneName(scene.manifest.project.title);
 0109        landPublisherView.SetSceneDescription(scene.manifest.project.description);
 0110        SetPublicationScreenshot(scene.sceneScreenshotTexture);
 0111    }
 112
 0113    public void SetPublicationScreenshot(Texture2D sceneScreenshot) { landPublisherView.SetPublicationScreenshot(sceneSc
 114}