< Summary

Class:BIWSaveController
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWSaveController.cs
Covered lines:23
Uncovered lines:29
Coverable lines:52
Total lines:115
Line coverage:44.2% (23 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BIWSaveController()0%2100%
GetSaveTimes()0%2100%
Initialize(...)0%330100%
Dispose()0%12300%
ResetSaveTime()0%2100%
ResetNumberOfSaves()0%2100%
EnterEditMode(...)0%110100%
ExitEditMode()0%6200%
SetSaveActivation(...)0%6200%
CanSave()0%330100%
TryToSave()0%220100%
ForceSave()0%7.736063.64%
SetManifest(...)0%2100%
SaveSceneInfo(...)0%2100%
ConfirmPublishScene(...)0%2100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Builder;
 4using DCL.Builder.Manifest;
 5using DCL.Controllers;
 6using UnityEngine;
 7
 8public class BIWSaveController : BIWController, IBIWSaveController
 9{
 10    private const float MS_BETWEEN_SAVES = 5000f;
 11
 012    public int numberOfSaves { get; set; } = 0;
 13
 14    private BuilderInWorldBridge bridge;
 15    private Manifest sceneManifest;
 16
 17    private float nextTimeToSave;
 018    private bool canActivateSave = true;
 019    public int GetSaveTimes() { return numberOfSaves; }
 20
 21    public override void Initialize(IContext context)
 22    {
 323        base.Initialize(context);
 24
 325        bridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>();
 326        if (bridge != null)
 327            bridge.OnKernelUpdated += TryToSave;
 28
 329        if ( context.editorContext.editorHUD != null)
 30        {
 331            context.editorContext.editorHUD.OnSaveSceneInfoAction += SaveSceneInfo;
 332            context.editorContext.editorHUD.OnConfirmPublishAction += ConfirmPublishScene;
 33        }
 334    }
 35
 36    public override void Dispose()
 37    {
 038        base.Dispose();
 39
 040        if (bridge != null)
 041            bridge.OnKernelUpdated -= TryToSave;
 42
 043        if ( context.editorContext.editorHUD != null)
 44        {
 045            context.editorContext.editorHUD.OnSaveSceneInfoAction -= SaveSceneInfo;
 046            context.editorContext.editorHUD.OnConfirmPublishAction -= ConfirmPublishScene;
 47        }
 048    }
 49
 050    public void ResetSaveTime() { nextTimeToSave = 0; }
 51
 052    public void ResetNumberOfSaves() { numberOfSaves = 0; }
 53
 54    public override void EnterEditMode(IParcelScene scene)
 55    {
 356        base.EnterEditMode(scene);
 357        nextTimeToSave = DCLTime.realtimeSinceStartup + MS_BETWEEN_SAVES / 1000f;
 358        ResetNumberOfSaves();
 359    }
 60
 61    public override void ExitEditMode()
 62    {
 063        if (numberOfSaves > 0)
 64        {
 065            ForceSave();
 066            ResetNumberOfSaves();
 67        }
 68
 069        base.ExitEditMode();
 070    }
 71
 72    public void SetSaveActivation(bool isActive, bool tryToSave = false)
 73    {
 074        canActivateSave = isActive;
 075        if (tryToSave)
 076            TryToSave();
 077    }
 78
 479    public bool CanSave() { return DCLTime.realtimeSinceStartup >= nextTimeToSave && isEditModeActive && canActivateSave
 80
 81    public void TryToSave()
 82    {
 183        if (CanSave())
 184            ForceSave();
 185    }
 86
 87    public void ForceSave()
 88    {
 289        if (!isEditModeActive || !canActivateSave)
 090            return;
 91
 292        if (DataStore.i.builderInWorld.isDevBuild.Get() && sceneManifest != null)
 93        {
 094            sceneManifest.scene = ManifestTranslator.TranslateSceneToManifest(sceneToEdit);
 095            context.builderAPIController.SetManifest(sceneManifest);
 096        }
 97        else
 98        {
 299            bridge.SaveSceneState(sceneToEdit);
 100        }
 101
 2102        nextTimeToSave = DCLTime.realtimeSinceStartup + MS_BETWEEN_SAVES / 1000f;
 2103        context.editorContext.editorHUD?.SceneSaved();
 2104        numberOfSaves++;
 2105    }
 106
 107    public void SetManifest(Manifest manifest)
 108    {
 0109        sceneManifest = manifest;
 0110    }
 111
 0112    public void SaveSceneInfo(string sceneName, string sceneDescription, string sceneScreenshot) { bridge.SaveSceneInfo(
 113
 0114    internal void ConfirmPublishScene(string sceneName, string sceneDescription, string sceneScreenshot) { ResetNumberOf
 115}