< Summary

Class:BIWPublishController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWPublishController.cs
Covered lines:30
Uncovered lines:27
Coverable lines:57
Total lines:138
Line coverage:52.6% (30 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%330100%
Update()0%6200%
Dispose()0%330100%
CanPublish()0%4.054085.71%
CheckPublishConditions()0%6.815058.33%
StartPublishFlow()0%12300%
StartPublishScene(...)0%2100%
PublishEnd(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWPublishController.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Builder;
 4using UnityEngine;
 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 Initialize(IContext context)
 23    {
 424        base.Initialize(context);
 25
 426        entityHandler = context.editorContext.entityHandler;
 427        creatorController = context.editorContext.creatorController;
 28
 429        if (context.editorContext.editorHUD != null)
 30        {
 431            context.editorContext.editorHUD.OnPublishAction += StartPublishFlow;
 432            context.editorContext.editorHUD.OnConfirmPublishAction += StartPublishScene;
 33        }
 34
 435        builderInWorldBridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>();
 36
 437        if (builderInWorldBridge != null)
 438            builderInWorldBridge.OnPublishEnd += PublishEnd;
 439    }
 40
 41    public override void Update()
 42    {
 043        base.Update();
 044        if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES)
 45        {
 046            checkerSceneLimitsOptimizationCounter = 0;
 047            CheckPublishConditions();
 048        }
 49        else
 50        {
 051            checkerSceneLimitsOptimizationCounter++;
 52        }
 053    }
 54
 55    public override void Dispose()
 56    {
 457        base.Dispose();
 58
 459        if ( context.editorContext.editorHUD != null)
 60        {
 461            context.editorContext.editorHUD.OnPublishAction -= StartPublishFlow;
 462            context.editorContext.editorHUD.OnConfirmPublishAction -= StartPublishScene;
 63        }
 64
 465        if (builderInWorldBridge != null)
 466            builderInWorldBridge.OnPublishEnd -= PublishEnd;
 467    }
 68
 69    public bool CanPublish()
 70    {
 471        if (creatorController.IsAnyErrorOnEntities())
 072            return false;
 73
 474        if (!sceneToEdit.metricsCounter.IsInsideTheLimits())
 175            return false;
 76
 377        if (!entityHandler.AreAllEntitiesInsideBoundaries())
 178            return false;
 79
 280        return true;
 81    }
 82
 83    /// <summary>
 84    /// This function will check if you are able to publish the scene to the content server. If no error are present, an
 85    /// </summary>
 86    /// <returns>A message the with the reason telling you why you can't publish. If you can publish an empty message wi
 87    public string CheckPublishConditions()
 88    {
 189        string feedbackMessage = "";
 190        if (creatorController.IsAnyErrorOnEntities())
 91        {
 092            feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR;
 093        }
 194        else if (!entityHandler.AreAllEntitiesInsideBoundaries())
 95        {
 096            feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES;
 097        }
 198        else if (!sceneToEdit.metricsCounter.IsInsideTheLimits())
 99        {
 0100            feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES;
 101        }
 102
 1103        if ( context.editorContext.editorHUD != null)
 1104            context.editorContext.editorHUD.SetPublishBtnAvailability(CanPublish(), feedbackMessage);
 105
 1106        return feedbackMessage;
 107    }
 108
 109    private void StartPublishFlow()
 110    {
 0111        if (!CanPublish())
 0112            return;
 113
 0114        if (DataStore.i.builderInWorld.isDevBuild.Get())
 115        {
 116            //TODO: Implement project publish
 117        }
 118        else
 119        {
 0120            context.editorContext.editorHUD.PublishStart();
 121        }
 0122    }
 123
 124    private void StartPublishScene(string sceneName, string sceneDescription, string sceneScreenshot)
 125    {
 0126        startPublishingTimestamp = Time.realtimeSinceStartup;
 0127        BIWAnalytics.StartScenePublish(sceneToEdit.metricsCounter.currentCount);
 0128        builderInWorldBridge.PublishScene(sceneToEdit, sceneName, sceneDescription, sceneScreenshot);
 0129    }
 130
 131    private void PublishEnd(bool isOk, string message)
 132    {
 0133        if ( context.editorContext.editorHUD != null)
 0134            context.editorContext.editorHUD.PublishEnd(isOk, message);
 0135        string successString = isOk ? "Success" : message;
 0136        BIWAnalytics.EndScenePublish(sceneToEdit.metricsCounter.currentCount, successString, Time.realtimeSinceStartup -
 0137    }
 138}