< Summary

Class:DCL.Builder.NewProjectSecondStepView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectSecondStepView.cs
Covered lines:30
Uncovered lines:13
Coverable lines:43
Total lines:117
Line coverage:69.7% (30 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NewProjectSecondStepView()0%110100%
Start()0%2100%
RefreshControl()0%2100%
RowsChanged(...)0%3.073080%
ColumnsChanged(...)0%3.073080%
ValueChanged()0%2.062075%
ShowError()0%110100%
ShowGrid()0%110100%
NextPressed()0%3.143075%
BackPressed()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/NewProject/NewProjectSecondStepView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6
 7namespace DCL.Builder
 8{
 9    public class NewProjectSecondStepView : BaseComponentView
 10    {
 11        private const int MAX_PARCELS = 32;
 12
 13        private const string MAX_PARCELS_TEXT = " parcels";
 14
 15        public event Action OnBackPressed;
 16        public event Action<int, int> OnNextPressed;
 17
 18        [Header("Design variables")]
 19        [SerializeField] internal Color normalTextColor;
 20        [SerializeField] internal Color errorTextColor;
 21        [SerializeField] private GridContainerComponentModel gridModel;
 22        [SerializeField] private BaseComponentView parcelImagePrefab;
 23
 24        [Header("References")]
 25        [SerializeField] private LimitInputField rowsInputField;
 26        [SerializeField] private LimitInputField columsInputField;
 27        [SerializeField] internal TextMeshProUGUI parcelText;
 28        [SerializeField] internal GameObject errorGameObject;
 29        [SerializeField] internal GameObject gridGameObject;
 30        [SerializeField] private GridContainerComponentView gridView;
 31
 32        [SerializeField] internal ButtonComponentView nextButton;
 33        [SerializeField] private ButtonComponentView backButton;
 34
 1235        internal int rows = 2;
 1236        internal int colums = 2;
 37
 38        public override void Start()
 39        {
 040            base.Start();
 41
 042            rowsInputField.OnInputChange += RowsChanged;
 043            columsInputField.OnInputChange += ColumnsChanged;
 44
 045            backButton.onClick.AddListener(BackPressed);
 046            nextButton.onClick.AddListener(NextPressed);
 047            gridView.Configure(gridModel);
 048        }
 49
 050        public override void RefreshControl() {  }
 51
 52        internal void RowsChanged(string value)
 53        {
 54            //We ensure that the minimum size of the row is 1
 155            if (string.IsNullOrEmpty(value) || value == "0")
 056                rows = 1;
 57            else
 158                rows = Mathf.Abs(Int32.Parse(value));
 159            ValueChanged();
 160        }
 61
 62        internal void ColumnsChanged(string value)
 63        {
 64            //We ensure that the minimum size of the column is 1
 165            if (string.IsNullOrEmpty(value) || value == "0")
 066                colums = 1;
 67            else
 168                colums = Mathf.Abs(Int32.Parse(value));
 169            ValueChanged();
 170        }
 71
 72        private void ValueChanged()
 73        {
 274            if (rows * colums > MAX_PARCELS)
 75            {
 076                ShowError();
 077            }
 78            else
 79            {
 280                gridModel.constraintCount = rows;
 281                gridView.SetItems(parcelImagePrefab, rows * colums);
 282                gridView.Configure(gridModel);
 283                ShowGrid();
 84            }
 285        }
 86
 87        internal void ShowError()
 88        {
 189            errorGameObject.SetActive(true);
 190            gridGameObject.SetActive(false);
 91
 192            parcelText.color = errorTextColor;
 93
 194            parcelText.text = (rows * colums) + MAX_PARCELS_TEXT;
 195        }
 96
 97        internal void ShowGrid()
 98        {
 399            errorGameObject.SetActive(false);
 3100            gridGameObject.SetActive(true);
 101
 3102            parcelText.color = normalTextColor;
 103
 3104            parcelText.text = $"{(rows * colums)} parcels = {(rows * DCL.Configuration.ParcelSettings.PARCEL_SIZE)}x{col
 3105        }
 106
 107        internal void NextPressed()
 108        {
 1109            if (!nextButton.IsInteractable())
 0110                return;
 111
 1112            OnNextPressed?.Invoke(rows, colums);
 1113        }
 114
 2115        internal void BackPressed() { OnBackPressed?.Invoke(); }
 116    }
 117}