< Summary

Class:UnpublishPopupController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Unpublish/UnpublishPopupController.cs
Covered lines:33
Uncovered lines:4
Coverable lines:37
Total lines:87
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/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Unpublish/UnpublishPopupController.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL;
 4using DCL.Builder;
 5using DCL.Interface;
 6using UnityEngine;
 7
 8internal class UnpublishPopupController : IDisposable
 9{
 10    private const string TITLE = "Unpublish Scene";
 11    private const string DESCRIPTION = "Are you sure you want to unpublish this scene?";
 12    private const string SUCCESS_DESCRIPTION = "Scene unpublished";
 13    private const string ERROR_TITLE = "Error";
 14    private const string PROGRESS_TITLE = "Unpublishing...";
 15
 16    private IUnpublishPopupView view;
 17    private Vector2Int coordinates;
 18    private Scene.Source source;
 19    private Coroutine fakeProgressRoutine = null;
 20
 2321    public UnpublishPopupController(IUnpublishPopupView view)
 22    {
 2323        this.view = view;
 2324        view.OnCancelPressed += OnCancel;
 2325        view.OnConfirmPressed += OnConfirmUnpublish;
 2326        view.Hide();
 2327    }
 28
 29    public void Dispose()
 30    {
 2331        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 2332        CoroutineStarter.Stop(fakeProgressRoutine);
 2333        if (view != null)
 34        {
 2335            view.OnCancelPressed -= OnCancel;
 2336            view.OnConfirmPressed -= OnConfirmUnpublish;
 2337            view.Dispose();
 38        }
 2339    }
 40
 41    public void Show(Vector2Int coordinates, Scene.Source source = Scene.Source.BUILDER_IN_WORLD)
 42    {
 343        this.coordinates = coordinates;
 344        this.source = source;
 345        view.Show(TITLE, DESCRIPTION);
 346    }
 47
 48    void OnConfirmUnpublish()
 49    {
 250        BIWAnalytics.PlayerUnpublishScene(source.ToString(), coordinates);
 251        DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished;
 252        WebInterface.UnpublishScene(coordinates);
 253        fakeProgressRoutine = CoroutineStarter.Start(ProgressRoutine());
 254    }
 55
 56    void OnCancel()
 57    {
 058        view.Hide();
 059        CoroutineStarter.Stop(fakeProgressRoutine);
 060    }
 61
 62    IEnumerator ProgressRoutine()
 63    {
 264        float progress = 0;
 065        while (true)
 66        {
 267            progress = Mathf.Clamp(progress + UnityEngine.Random.Range(0.01f, 0.03f), 0, 0.99f);
 268            view.SetProgress(PROGRESS_TITLE, progress);
 269            yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f));
 70        }
 71    }
 72
 73    private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous)
 74    {
 275        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 276        CoroutineStarter.Stop(fakeProgressRoutine);
 77
 278        if (current.ok)
 79        {
 180            view.SetSuccess(TITLE, SUCCESS_DESCRIPTION);
 181        }
 82        else
 83        {
 184            view.SetError(ERROR_TITLE, current.error);
 85        }
 186    }
 87}