< Summary

Class:UnpublishPopupController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Unpublish/UnpublishPopupController.cs
Covered lines:33
Uncovered lines:4
Coverable lines:37
Total lines:86
Line coverage:89.1% (33 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UnpublishPopupController(...)0%110100%
Dispose()0%220100%
Show(...)0%110100%
OnConfirmUnpublish()0%110100%
OnCancel()0%2100%
ProgressRoutine()0%3.073080%
OnSceneUnpublished(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Unpublish/UnpublishPopupController.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL;
 4using DCL.Interface;
 5using UnityEngine;
 6
 7internal class UnpublishPopupController : IDisposable
 8{
 9    private const string TITLE = "Unpublish Scene";
 10    private const string DESCRIPTION = "Are you sure you want to unpublish this scene?";
 11    private const string SUCCESS_DESCRIPTION = "Scene unpublished";
 12    private const string ERROR_TITLE = "Error";
 13    private const string PROGRESS_TITLE = "Unpublishing...";
 14
 15    private IUnpublishPopupView view;
 16    private Vector2Int coordinates;
 17    private DeployedScene.Source source;
 18    private Coroutine fakeProgressRoutine = null;
 19
 2220    public UnpublishPopupController(IUnpublishPopupView view)
 21    {
 2222        this.view = view;
 2223        view.OnCancelPressed += OnCancel;
 2224        view.OnConfirmPressed += OnConfirmUnpublish;
 2225        view.Hide();
 2226    }
 27
 28    public void Dispose()
 29    {
 2230        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 2231        CoroutineStarter.Stop(fakeProgressRoutine);
 2232        if (view != null)
 33        {
 2234            view.OnCancelPressed -= OnCancel;
 2235            view.OnConfirmPressed -= OnConfirmUnpublish;
 2236            view.Dispose();
 37        }
 2238    }
 39
 40    public void Show(Vector2Int coordinates, DeployedScene.Source source = DeployedScene.Source.BUILDER_IN_WORLD)
 41    {
 342        this.coordinates = coordinates;
 343        this.source = source;
 344        view.Show(TITLE, DESCRIPTION);
 345    }
 46
 47    void OnConfirmUnpublish()
 48    {
 249        BIWAnalytics.PlayerUnpublishScene(source.ToString(), coordinates);
 250        DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished;
 251        WebInterface.UnpublishScene(coordinates);
 252        fakeProgressRoutine = CoroutineStarter.Start(ProgressRoutine());
 253    }
 54
 55    void OnCancel()
 56    {
 057        view.Hide();
 058        CoroutineStarter.Stop(fakeProgressRoutine);
 059    }
 60
 61    IEnumerator ProgressRoutine()
 62    {
 263        float progress = 0;
 064        while (true)
 65        {
 266            progress = Mathf.Clamp(progress + UnityEngine.Random.Range(0.01f, 0.03f), 0, 0.99f);
 267            view.SetProgress(PROGRESS_TITLE, progress);
 268            yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f));
 69        }
 70    }
 71
 72    private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous)
 73    {
 274        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 275        CoroutineStarter.Stop(fakeProgressRoutine);
 76
 277        if (current.ok)
 78        {
 179            view.SetSuccess(TITLE, SUCCESS_DESCRIPTION);
 180        }
 81        else
 82        {
 183            view.SetError(ERROR_TITLE, current.error);
 84        }
 185    }
 86}