< 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:32
Uncovered lines:4
Coverable lines:36
Total lines:83
Line coverage:88.8% (32 of 36)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UnpublishPopupController(...)0%110100%
Dispose()0%110100%
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
 1820    public UnpublishPopupController(IUnpublishPopupView view)
 21    {
 1822        this.view = view;
 1823        view.OnCancelPressed += OnCancel;
 1824        view.OnConfirmPressed += OnConfirmUnpublish;
 1825        view.Hide();
 1826    }
 27
 28    public void Dispose()
 29    {
 1830        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 1831        CoroutineStarter.Stop(fakeProgressRoutine);
 1832        view.OnCancelPressed -= OnCancel;
 1833        view.OnConfirmPressed -= OnConfirmUnpublish;
 1834        view.Dispose();
 1835    }
 36
 37    public void Show(Vector2Int coordinates, DeployedScene.Source source = DeployedScene.Source.BUILDER_IN_WORLD)
 38    {
 339        this.coordinates = coordinates;
 340        this.source = source;
 341        view.Show(TITLE, DESCRIPTION);
 342    }
 43
 44    void OnConfirmUnpublish()
 45    {
 246        BIWAnalytics.PlayerUnpublishScene(source.ToString(), coordinates);
 247        DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished;
 248        WebInterface.UnpublishScene(coordinates);
 249        fakeProgressRoutine = CoroutineStarter.Start(ProgressRoutine());
 250    }
 51
 52    void OnCancel()
 53    {
 054        view.Hide();
 055        CoroutineStarter.Stop(fakeProgressRoutine);
 056    }
 57
 58    IEnumerator ProgressRoutine()
 59    {
 260        float progress = 0;
 061        while (true)
 62        {
 263            progress = Mathf.Clamp(progress + UnityEngine.Random.Range(0.01f, 0.03f), 0, 0.99f);
 264            view.SetProgress(PROGRESS_TITLE, progress);
 265            yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f));
 66        }
 67    }
 68
 69    private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous)
 70    {
 271        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 272        CoroutineStarter.Stop(fakeProgressRoutine);
 73
 274        if (current.ok)
 75        {
 176            view.SetSuccess(TITLE, SUCCESS_DESCRIPTION);
 177        }
 78        else
 79        {
 180            view.SetError(ERROR_TITLE, current.error);
 81        }
 182    }
 83}