< Summary

Class:BIWPublishController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWPublishController.cs
Covered lines:29
Uncovered lines:41
Coverable lines:70
Total lines:161
Line coverage:41.4% (29 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%220100%
Update()0%6200%
Dispose()0%220100%
EnterEditMode(...)0%110100%
ExitEditMode()0%2100%
HasUnpublishChanges()0%2100%
CheckIfThereAreUnpublishChanges()0%6200%
CanPublish()0%4.054085.71%
CheckPublishConditions()0%6.815058.33%
StartPublishFlow()0%6200%
PublishFinish(...)0%6200%

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    private IBIWActionController actionController;
 11
 12    private int checkerSceneLimitsOptimizationCounter = 0;
 13    private bool hasUnpublishedChanges = false;
 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    internal float publishTimeStamp = 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;
 428        actionController = context.editorContext.actionController;
 29
 430        if (context.editorContext.editorHUD != null)
 431            context.editorContext.editorHUD.OnPublishAction += StartPublishFlow;
 32
 433        context.publisher.OnPublishFinish += PublishFinish;
 434    }
 35
 36    public override void Update()
 37    {
 038        base.Update();
 039        if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES)
 40        {
 041            checkerSceneLimitsOptimizationCounter = 0;
 042            CheckPublishConditions();
 043        }
 44        else
 45        {
 046            checkerSceneLimitsOptimizationCounter++;
 47        }
 048    }
 49
 50    public override void Dispose()
 51    {
 452        base.Dispose();
 53
 454        context.publisher.OnPublishFinish -= PublishFinish;
 455        if ( context.editorContext.editorHUD != null)
 456            context.editorContext.editorHUD.OnPublishAction -= StartPublishFlow;
 457    }
 58
 59    public override void EnterEditMode(IBuilderScene scene)
 60    {
 461        base.EnterEditMode(scene);
 462        publishTimeStamp = 0;
 463    }
 64
 65    public override void ExitEditMode()
 66    {
 067        base.ExitEditMode();
 068        CheckIfThereAreUnpublishChanges();
 069    }
 70
 71    public bool HasUnpublishChanges()
 72    {
 073        CheckIfThereAreUnpublishChanges();
 074        return hasUnpublishedChanges;
 75    }
 76
 77    internal void CheckIfThereAreUnpublishChanges()
 78    {
 079        hasUnpublishedChanges = actionController.HasApplyAnyActionThisSession();
 080        if (hasUnpublishedChanges)
 81        {
 082            hasUnpublishedChanges = actionController.GetLastActionTimestamp() > publishTimeStamp;
 83        }
 084    }
 85
 86    public bool CanPublish()
 87    {
 488        if (creatorController.IsAnyErrorOnEntities())
 089            return false;
 90
 491        if (!sceneToEdit.metricsCounter.IsInsideTheLimits())
 192            return false;
 93
 394        if (!entityHandler.AreAllEntitiesInsideBoundaries())
 195            return false;
 96
 297        return true;
 98    }
 99
 100    /// <summary>
 101    /// This function will check if you are able to publish the scene to the content server. If no error are present, an
 102    /// </summary>
 103    /// <returns>A message the with the reason telling you why you can't publish. If you can publish an empty message wi
 104    public string CheckPublishConditions()
 105    {
 1106        string feedbackMessage = "";
 1107        if (creatorController.IsAnyErrorOnEntities())
 108        {
 0109            feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR;
 0110        }
 1111        else if (!entityHandler.AreAllEntitiesInsideBoundaries())
 112        {
 0113            feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES;
 0114        }
 1115        else if (!sceneToEdit.metricsCounter.IsInsideTheLimits())
 116        {
 0117            feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES;
 118        }
 119
 1120        if ( context.editorContext.editorHUD != null)
 1121            context.editorContext.editorHUD.SetPublishBtnAvailability(CanPublish(), feedbackMessage);
 122
 1123        return feedbackMessage;
 124    }
 125
 126    private void StartPublishFlow()
 127    {
 0128        if (!CanPublish())
 0129            return;
 130
 131        // We update the manifest with the current scene to send the last state to publish
 0132        builderScene.UpdateManifestFromScene();
 133
 0134        context.cameraController.TakeSceneScreenshot((sceneSnapshot) =>
 135        {
 0136            builderScene.sceneScreenshotTexture = sceneSnapshot;
 0137            if (builderScene.sceneType == IBuilderScene.SceneType.PROJECT)
 138            {
 139                //If it is a project, we took an aerial view of the scene too for the rotation of the scene
 0140                context.cameraController.TakeSceneAerialScreenshot( sceneToEdit, (aerialSceenshot) =>
 141                {
 0142                    builderScene.aerialScreenshotTexture = aerialSceenshot;
 0143                    context.publisher.StartPublish(builderScene);
 0144                });
 0145            }
 146            else
 147            {
 0148                context.publisher.StartPublish(builderScene);
 149            }
 0150        });
 0151    }
 152
 153    private void PublishFinish(bool isOk)
 154    {
 0155        if(!isEditModeActive)
 0156            return;
 157
 0158        hasUnpublishedChanges = false;
 0159        publishTimeStamp = Time.unscaledTime;
 0160    }
 161}