< Summary

Class:BIWPublishController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Controllers/BIWPublishController.cs
Covered lines:33
Uncovered lines:23
Coverable lines:56
Total lines:130
Line coverage:58.9% (33 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Init(...)0%550100%
Update()0%2.312057.14%
Dispose()0%330100%
CanPublish()0%4.054085.71%
CheckPublishConditions()0%8.125050%
StartPublishFlow()0%6200%
StartPublishScene(...)0%2100%
PublishEnd(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/Controllers/BIWPublishController.cs

#LineLine coverage
 1using DCL;
 2using UnityEngine;
 3
 4public interface IBIWPublishController { }
 5
 6public class BIWPublishController : BIWController, IBIWPublishController
 7{
 8    private IBIWEntityHandler entityHandler;
 9    private IBIWCreatorController creatorController;
 10
 11    private BuilderInWorldBridge builderInWorldBridge;
 12
 13    private int checkerSceneLimitsOptimizationCounter = 0;
 14
 15    private const int FRAMES_BEETWEN_UPDATES = 10;
 16    private const string FEEDBACK_MESSAGE_ENTITY_ERROR = "Some entities have errors (marked as pink cubes).";
 17    private const string FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES = "Some entities are outside of the Scene boundaries.";
 18    private const string FEEDBACK_MESSAGE_TOO_MANY_ENTITIES = "Too many entities in the scene. Check scene limits.";
 19
 20    private float startPublishingTimestamp = 0;
 21
 22    public override void Init(BIWContext context)
 23    {
 3024        base.Init(context);
 25
 3026        entityHandler = context.entityHandler;
 3027        creatorController = context.creatorController;
 28
 3029        if (HUDController.i?.builderInWorldMainHud != null)
 30        {
 2631            HUDController.i.builderInWorldMainHud.OnPublishAction += StartPublishFlow;
 2632            HUDController.i.builderInWorldMainHud.OnConfirmPublishAction += StartPublishScene;
 33        }
 34
 3035        builderInWorldBridge = context.sceneReferences.builderInWorldBridge;
 36
 3037        if (builderInWorldBridge != null)
 2638            builderInWorldBridge.OnPublishEnd += PublishEnd;
 3039    }
 40
 41    public override void Update()
 42    {
 243        base.Update();
 244        if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES)
 45        {
 046            checkerSceneLimitsOptimizationCounter = 0;
 047            CheckPublishConditions();
 048        }
 49        else
 50        {
 251            checkerSceneLimitsOptimizationCounter++;
 52        }
 253    }
 54
 55    public override void Dispose()
 56    {
 3157        base.Dispose();
 58
 3159        if (HUDController.i.builderInWorldMainHud != null)
 60        {
 2761            HUDController.i.builderInWorldMainHud.OnPublishAction -= StartPublishFlow;
 2762            HUDController.i.builderInWorldMainHud.OnConfirmPublishAction -= StartPublishScene;
 63        }
 3164        if (builderInWorldBridge != null)
 2765            builderInWorldBridge.OnPublishEnd -= PublishEnd;
 3166    }
 67
 68    public bool CanPublish()
 69    {
 370        if (creatorController.IsAnyErrorOnEntities())
 071            return false;
 72
 373        if (!sceneToEdit.metricsController.IsInsideTheLimits())
 174            return false;
 75
 276        if (!entityHandler.AreAllEntitiesInsideBoundaries())
 177            return false;
 78
 179        return true;
 80    }
 81
 82    /// <summary>
 83    /// This function will check if you are able to publish the scene to the content server. If no error are present, an
 84    /// </summary>
 85    /// <returns>A message the with the reason telling you why you can't publish. If you can publish an empty message wi
 86    public string CheckPublishConditions()
 87    {
 188        string feedbackMessage = "";
 189        if (creatorController.IsAnyErrorOnEntities())
 90        {
 091            feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR;
 092        }
 193        else if (!entityHandler.AreAllEntitiesInsideBoundaries())
 94        {
 095            feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES;
 096        }
 197        else if (!sceneToEdit.metricsController.IsInsideTheLimits())
 98        {
 099            feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES;
 100        }
 101
 1102        if (HUDController.i.builderInWorldMainHud != null)
 0103            HUDController.i.builderInWorldMainHud.SetPublishBtnAvailability(CanPublish(), feedbackMessage);
 104
 1105        return feedbackMessage;
 106    }
 107
 108    private void StartPublishFlow()
 109    {
 0110        if (!CanPublish())
 0111            return;
 112
 0113        HUDController.i.builderInWorldMainHud.PublishStart();
 0114    }
 115
 116    private void StartPublishScene(string sceneName, string sceneDescription, string sceneScreenshot)
 117    {
 0118        startPublishingTimestamp = Time.realtimeSinceStartup;
 0119        BIWAnalytics.StartScenePublish(sceneToEdit.metricsController.GetModel());
 0120        builderInWorldBridge.PublishScene(sceneToEdit, sceneName, sceneDescription, sceneScreenshot);
 0121    }
 122
 123    private void PublishEnd(bool isOk, string message)
 124    {
 0125        if (HUDController.i.builderInWorldMainHud != null)
 0126            HUDController.i.builderInWorldMainHud.PublishEnd(isOk, message);
 0127        string successString = isOk ? "Success" : message;
 0128        BIWAnalytics.EndScenePublish(sceneToEdit.metricsController.GetModel(), successString, Time.realtimeSinceStartup 
 0129    }
 130}