< Summary

Class:ECSSystems.InputSenderSystem.ECSInputSenderSystem
Assembly:ECS7Plugin.Systems.InputSender
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/InputSenderSystem/ECSInputSenderSystem.cs
Covered lines:39
Uncovered lines:3
Coverable lines:42
Total lines:101
Line coverage:92.8% (39 of 42)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ECSInputSenderSystem(...)0%110100%
Update()0%9.019094.44%
IsValidInputForRestrictedActions(...)0%5.935066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/InputSenderSystem/ECSInputSenderSystem.cs

#LineLine coverage
 1using DCL.ECS7;
 2using DCL.ECS7.ComponentWrapper.Generic;
 3using DCL.ECS7.InternalComponents;
 4using DCL.ECSComponents;
 5using DCL.Models;
 6using System;
 7using System.Collections.Generic;
 8
 9namespace ECSSystems.InputSenderSystem
 10{
 11    public class ECSInputSenderSystem
 12    {
 13        private readonly IInternalECSComponent<InternalInputEventResults> inputResultComponent;
 14        private readonly IInternalECSComponent<InternalEngineInfo> engineInfoComponent;
 15        private readonly IReadOnlyDictionary<int, ComponentWriter> componentsWriter;
 16        private readonly WrappedComponentPool<IWrappedComponent<PBPointerEventsResult>> componentPool;
 17        private readonly Func<int> getCurrentSceneNumber;
 18        private uint lastTimestamp = 0;
 19
 420        public ECSInputSenderSystem(
 21            IInternalECSComponent<InternalInputEventResults> inputResultComponent,
 22            IInternalECSComponent<InternalEngineInfo> engineInfoComponent,
 23            IReadOnlyDictionary<int, ComponentWriter> componentsWriter,
 24            WrappedComponentPool<IWrappedComponent<PBPointerEventsResult>> componentPool,
 25            Func<int> getCurrentSceneNumber)
 26        {
 427            this.inputResultComponent = inputResultComponent;
 428            this.engineInfoComponent = engineInfoComponent;
 429            this.componentsWriter = componentsWriter;
 430            this.componentPool = componentPool;
 431            this.getCurrentSceneNumber = getCurrentSceneNumber;
 432        }
 33
 34        public void Update()
 35        {
 336            var inputResults = inputResultComponent.GetForAll();
 337            int currentSceneNumber = getCurrentSceneNumber();
 338            bool restrictedActionEnabled = false;
 39
 1240            for (int i = 0; i < inputResults.Count; i++)
 41            {
 342                var model = inputResults[i].value.model;
 43
 344                if (!model.dirty)
 45                    continue;
 46
 247                var scene = inputResults[i].value.scene;
 248                var entity = inputResults[i].value.entity;
 249                long entityId = entity.entityId;
 250                InternalEngineInfo engineInfoModel = engineInfoComponent.GetFor(scene, SpecialEntityId.SCENE_ROOT_ENTITY
 251                bool checkRestrictedAction = scene.isPersistent || scene.sceneData.sceneNumber == currentSceneNumber;
 52
 253                if (!componentsWriter.TryGetValue(scene.sceneData.sceneNumber, out var writer))
 54                    continue;
 55
 256                int count = model.events.Count;
 57
 1658                for (int j = 0; j < count; j++)
 59                {
 660                    InternalInputEventResults.EventData inputEvent = model.events[j];
 61
 662                    InputAction actionButton = inputEvent.button;
 663                    PointerEventType evtType = inputEvent.type;
 664                    RaycastHit hit = inputEvent.hit;
 65
 666                    if (checkRestrictedAction && !restrictedActionEnabled)
 67                    {
 668                        if (IsValidInputForRestrictedActions(entityId, actionButton, evtType, hit))
 69                        {
 070                            restrictedActionEnabled = true;
 071                            engineInfoComponent.PutFor(currentSceneNumber, SpecialEntityId.SCENE_ROOT_ENTITY, engineInfo
 72                        }
 73                    }
 74
 675                    var componentPooled = componentPool.Get();
 676                    var componentModel = componentPooled.WrappedComponent.Model;
 677                    componentModel.Button = inputEvent.button;
 678                    componentModel.Hit = inputEvent.hit;
 679                    componentModel.State = inputEvent.type;
 680                    componentModel.Timestamp = lastTimestamp++;
 681                    componentModel.TickNumber = engineInfoModel.SceneTick;
 82
 683                    writer.Append(entityId, ComponentID.POINTER_EVENTS_RESULT, componentPooled);
 84                }
 85
 286                model.events.Clear();
 87            }
 388        }
 89
 90        private static bool IsValidInputForRestrictedActions(long entityId, InputAction actionButton,
 91            PointerEventType evtType, RaycastHit hit)
 92        {
 693            if (entityId == SpecialEntityId.SCENE_ROOT_ENTITY)
 694                return false;
 95
 096            return hit != null
 97                   && (evtType == PointerEventType.PetDown || evtType == PointerEventType.PetUp)
 98                   && actionButton != InputAction.IaAny;
 99        }
 100    }
 101}