< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2100%
RemoveActionable(...)0%30500%
SetEntityList(...)0%2100%
SetInfo()0%20400%
AddEventAction(...)0%12300%
CreateEventAction()0%12300%

File(s)

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

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using System;
 4using System.Collections;
 5using System.Collections.Generic;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class SmartItemActionParameter : SmartItemUIParameterAdapter, IEntityListHandler
 11{
 12    public ActionsListView actionsListView;
 13    public Button addActionBtn;
 14
 15    private List<DCLBuilderInWorldEntity> alreadyFilterList;
 16
 17    private void Start()
 18    {
 019        addActionBtn.onClick.AddListener(CreateEventAction);
 020        actionsListView.OnActionableRemove += RemoveActionable;
 021    }
 22
 23    private void RemoveActionable(SmartItemActionable actionable)
 24    {
 025        var actionsGeneric = GetParameterValue();
 026        if (actionsGeneric == null || !(actionsGeneric is List<SmartItemActionable>))
 027            return;
 28
 029        SmartItemActionable actionableToRemove = null;
 030        List<SmartItemActionable> actions = (List<SmartItemActionable>)actionsGeneric;
 031        foreach (SmartItemActionable actionableItem in actions)
 32        {
 033            if (actionable.actionableId == actionableItem.actionableId)
 034                actionableToRemove = actionableItem;
 35        }
 036        actions.Remove(actionableToRemove);
 37
 038        SetParameterValue(actions);
 039    }
 40
 041    public void SetEntityList(List<DCLBuilderInWorldEntity> entitiesList) { this.alreadyFilterList = entitiesList; }
 42
 43    public override void SetInfo()
 44    {
 045        base.SetInfo();
 46
 047        KEY_NAME = currentParameter.id;
 48
 049        var actionsGeneric = GetParameterValue();
 050        if (actionsGeneric == null || !(actionsGeneric is List<SmartItemActionable>))
 051            return;
 052        List<SmartItemActionable> actions = (List<SmartItemActionable>)actionsGeneric;
 53
 054        foreach (SmartItemActionable smartItemAction in actions)
 55        {
 056            AddEventAction(smartItemAction);
 57        }
 058    }
 59
 60    public void AddEventAction(SmartItemActionable action)
 61    {
 062        if (alreadyFilterList.Count <= 0)
 063            return;
 64
 065        SmartItemActionEvent actionEvent = new SmartItemActionEvent();
 066        actionEvent.entityList = alreadyFilterList;
 067        actionEvent.smartItemActionable = action;
 68
 069        if (currentValues.ContainsKey(action.actionableId))
 070            actionEvent.values = (Dictionary<object, object>) currentValues[action.actionableId];
 71        else
 072            actionEvent.values = new Dictionary<object, object>();
 73
 074        actionsListView.AddActionEventAdapter(actionEvent);
 075    }
 76
 77    public void CreateEventAction()
 78    {
 079        var actionsGeneric = GetParameterValue();
 80
 81        List<SmartItemActionable> actions;
 82
 083        if (actionsGeneric != null && (actionsGeneric is List<SmartItemActionable>))
 084            actions = (List<SmartItemActionable>)actionsGeneric;
 85        else
 086            actions = new List<SmartItemActionable>();
 87
 088        SmartItemActionable action = new SmartItemActionable();
 089        action.actionableId = Guid.NewGuid().ToString();
 090        actions.Add(action);
 091        AddEventAction(action);
 092        SetParameterValue(actions);
 093    }
 94}