< Summary

Class:UnpublishPopupController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Unpublish/UnpublishPopupController.cs
Covered lines:35
Uncovered lines:4
Coverable lines:39
Total lines:91
Line coverage:89.7% (35 of 39)
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 Vector2Int size;
 19    private Scene.Source source;
 20    private Coroutine fakeProgressRoutine = null;
 21    private IContext context;
 22
 2223    public UnpublishPopupController(IContext context,IUnpublishPopupView view)
 24    {
 2225        this.context = context;
 2226        this.view = view;
 2227        view.OnCancelPressed += OnCancel;
 2228        view.OnConfirmPressed += OnConfirmUnpublish;
 2229        view.Hide();
 2230    }
 31
 32    public void Dispose()
 33    {
 2234        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 2235        CoroutineStarter.Stop(fakeProgressRoutine);
 2236        if (view != null)
 37        {
 2238            view.OnCancelPressed -= OnCancel;
 2239            view.OnConfirmPressed -= OnConfirmUnpublish;
 2240            view.Dispose();
 41        }
 2242    }
 43
 44    public void Show(Vector2Int coordinates, Vector2Int sceneSize, Scene.Source source = Scene.Source.BUILDER_IN_WORLD)
 45    {
 346        this.coordinates = coordinates;
 347        this.source = source;
 348        this.size = sceneSize;
 349        view.Show(TITLE, DESCRIPTION);
 350    }
 51
 52    void OnConfirmUnpublish()
 53    {
 254        context.publisher.Unpublish(coordinates,size);
 255        BIWAnalytics.PlayerUnpublishScene(source.ToString(), coordinates);
 256        DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished;
 257        fakeProgressRoutine = CoroutineStarter.Start(ProgressRoutine());
 258    }
 59
 60    void OnCancel()
 61    {
 062        view.Hide();
 063        CoroutineStarter.Stop(fakeProgressRoutine);
 064    }
 65
 66    IEnumerator ProgressRoutine()
 67    {
 268        float progress = 0;
 069        while (true)
 70        {
 271            progress = Mathf.Clamp(progress + UnityEngine.Random.Range(0.01f, 0.03f), 0, 0.99f);
 272            view.SetProgress(PROGRESS_TITLE, progress);
 273            yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f));
 74        }
 75    }
 76
 77    private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous)
 78    {
 279        DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished;
 280        CoroutineStarter.Stop(fakeProgressRoutine);
 81
 282        if (current.ok)
 83        {
 184            view.SetSuccess(TITLE, SUCCESS_DESCRIPTION);
 185        }
 86        else
 87        {
 188            view.SetError(ERROR_TITLE, current.error);
 89        }
 190    }
 91}