< Summary

Class:ActionEventAdapter
Assembly:BuilderInWorldEntityInformation
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/EntityInformation/SmartItems/Parameters/Actions/ActionEventAdapter.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:102
Line coverage:0% (0 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ActionEventAdapter()0%2100%
Start()0%2100%
SetContent(...)0%2100%
SelectedEntity(...)0%6200%
GenerateParametersFromSelectedOption()0%2100%
GenerateParametersFromIndex(...)0%12300%
GenerateActionDropdownContent(...)0%6200%
GenerateEntityDropdownContent()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/BuilderMode/EntityInformation/SmartItems/Parameters/Actions/ActionEventAdapter.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Models;
 4using System.Collections;
 5using System.Collections.Generic;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class ActionEventAdapter : MonoBehaviour
 11{
 12    public TMP_Dropdown entityDropDown;
 13    public TMP_Dropdown actionDropDown;
 14    public Button addActionBtn;
 15    public SmartItemListView smartItemListView;
 16
 17    List<DCLBuilderInWorldEntity> entityList;
 18
 19    SmartItemComponent selectedComponent;
 20    DCLBuilderInWorldEntity selectedEntity;
 021    List<DCLBuilderInWorldEntity> filteredList = new List<DCLBuilderInWorldEntity>();
 22
 23    private void Start()
 24    {
 025        entityDropDown.onValueChanged.AddListener(SelectedEntity);
 026        actionDropDown.onValueChanged.AddListener(GenerateParametersFromIndex);
 027    }
 28
 29    public void SetContent(List<DCLBuilderInWorldEntity> entityList)
 30    {
 031        this.entityList = entityList;
 032        filteredList = BuilderInWorldUtils.FilterEntitiesBySmartItemComponentAndActions(entityList);
 33
 034        GenerateEntityDropdownContent();
 035        SelectedEntity(0);
 036    }
 37
 38    void SelectedEntity(int number)
 39    {
 040        if (!filteredList[number].rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent com
 41        {
 042            return;
 43        }
 44
 045        selectedEntity = filteredList[number];
 046        selectedComponent = (SmartItemComponent) component;
 047        GenerateActionDropdownContent(filteredList[number].GetSmartItemActions());
 48
 049        GenerateParametersFromSelectedOption();
 050    }
 51
 052    void GenerateParametersFromSelectedOption() { GenerateParametersFromIndex(actionDropDown.value); }
 53
 54    void GenerateParametersFromIndex(int index)
 55    {
 056        string label = actionDropDown.options[index].text;
 57
 058        SmartItemAction selectedAction = null;
 059        foreach (SmartItemAction action in selectedEntity.GetSmartItemActions())
 60        {
 061            if (action.label == label)
 62            {
 063                selectedAction = action;
 064                break;
 65            }
 66        }
 67
 068        smartItemListView.SetEntityList(entityList);
 069        smartItemListView.SetSmartItemParameters(selectedAction.parameters, selectedComponent.GetValues());
 070    }
 71
 72    void GenerateActionDropdownContent(SmartItemAction[] actions)
 73    {
 074        actionDropDown.ClearOptions();
 75
 076        actionDropDown.options = new List<TMP_Dropdown.OptionData>();
 77
 78
 079        List<string> optionsLabelList = new List<string>();
 080        foreach (SmartItemAction action in actions)
 81        {
 082            optionsLabelList.Add(action.label);
 83        }
 84
 085        actionDropDown.AddOptions(optionsLabelList);
 086    }
 87
 88    void GenerateEntityDropdownContent()
 89    {
 090        entityDropDown.ClearOptions();
 91
 092        entityDropDown.options = new List<TMP_Dropdown.OptionData>();
 93
 094        List<string> optionsLabelList = new List<string>();
 095        foreach (DCLBuilderInWorldEntity entity in filteredList)
 96        {
 097            optionsLabelList.Add(entity.GetDescriptiveName());
 98        }
 99
 0100        entityDropDown.AddOptions(optionsLabelList);
 0101    }
 102}