< Summary

Class:AirdroppingHUDController
Assembly:AirdroppingHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AirdroppingHUD/AirdroppingHUDController.cs
Covered lines:55
Uncovered lines:1
Coverable lines:56
Total lines:142
Line coverage:98.2% (55 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AirdroppingHUDController()0%110100%
AirdroppingRequested(...)0%3.013090%
MoveToNextState()0%110100%
SetNextState()0%12120100%
ApplyState()0%880100%
SetVisibility(...)0%110100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AirdroppingHUD/AirdroppingHUDController.cs

#LineLine coverage
 1using DCL.Interface;
 2using System;
 3
 4public class AirdroppingHUDController : IHUD
 5{
 6
 7    [Serializable]
 8    public class Model
 9    {
 10        public string id;
 11        public string title;
 12        public string subtitle;
 13        public ItemModel[] items;
 14    }
 15
 16    [Serializable]
 17    public class ItemModel
 18    {
 19        public string name;
 20        public string thumbnailURL;
 21        public string type;
 22        public string rarity;
 23        public string subtitle;
 24    }
 25
 26    public enum State
 27    {
 28        Hidden,
 29        Initial,
 30        SingleItem,
 31        Summary,
 32        Summary_NoItems,
 33        Finish
 34    }
 35
 36    internal AirdroppingHUDView view;
 37    internal State currentState;
 38    internal Model model;
 839    internal int currentItemShown = -1;
 740    internal int totalItems => model?.items?.Length ?? 0;
 41
 42    public static event System.Action OnAirdropFinished = null;
 43
 844    public AirdroppingHUDController()
 45    {
 846        view = AirdroppingHUDView.Create();
 847        view.Initialize(MoveToNextState);
 848        currentState = State.Hidden;
 849        ApplyState();
 850    }
 51
 52    public void AirdroppingRequested(Model model)
 53    {
 354        if (model == null)
 055            return;
 56
 357        this.model = model;
 58
 1459        for (var i = 0; i < this.model.items.Length; i++)
 60        {
 461            ThumbnailsManager.PreloadThumbnail(this.model.items[i].thumbnailURL);
 62        }
 63
 364        currentState = State.Initial;
 365        ApplyState();
 366    }
 67
 68    public void MoveToNextState()
 69    {
 770        SetNextState();
 771        ApplyState();
 772    }
 73
 74    public void SetNextState()
 75    {
 776        switch (currentState)
 77        {
 78            case State.Initial:
 279                if (currentItemShown > totalItems - 1)
 180                    currentState = totalItems != 0 ? State.Summary : State.Summary_NoItems;
 81                else
 182                    currentState = State.SingleItem;
 183                break;
 84            case State.SingleItem:
 285                currentItemShown++;
 286                if (currentItemShown > totalItems - 1)
 187                    currentState = totalItems != 0 ? State.Summary : State.Summary_NoItems;
 188                break;
 89            case State.Summary:
 190                currentState = State.Finish;
 191                break;
 92            case State.Summary_NoItems:
 193                currentState = State.Hidden;
 194                break;
 95            case State.Finish:
 96            default:
 197                currentState = State.Hidden;
 98                break;
 99        }
 2100    }
 101
 102    public void ApplyState()
 103    {
 18104        switch (currentState)
 105        {
 106            case State.Initial:
 3107                currentItemShown = 0;
 3108                view.SetContentActive(true);
 3109                view.ShowInitialScreen(model.title, model.subtitle);
 3110                break;
 111            case State.SingleItem:
 2112                view.ShowItemScreen(model.items[currentItemShown], model.items.Length - (currentItemShown + 1));
 2113                break;
 114            case State.Summary:
 1115                view.ShowSummaryScreen(model.items);
 1116                break;
 117            case State.Summary_NoItems:
 1118                view.ShowSummaryNoItemsScreen();
 1119                break;
 120            case State.Finish:
 1121                WebInterface.SendUserAcceptedCollectibles(model.id);
 122
 1123                OnAirdropFinished?.Invoke();
 124
 1125                MoveToNextState();
 1126                break;
 127            case State.Hidden:
 128            default:
 10129                model = null;
 10130                view.SetContentActive(false);
 131                break;
 132        }
 10133    }
 134
 2135    public void SetVisibility(bool visible) { view.SetVisibility(visible); }
 136
 137    public void Dispose()
 138    {
 8139        if (view != null)
 8140            UnityEngine.Object.Destroy(view.gameObject);
 8141    }
 142}