< Summary

Class:InternalECSComponent[T]
Assembly:ECS7Plugin.InternalECSComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/InternalECSComponents/InternalECSComponent.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:95
Line coverage:100% (26 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InternalECSComponent(...)0%220100%
PutFor(...)0%110100%
PutFor(...)0%110100%
RemoveFor(...)0%110100%
RemoveFor(...)0%220100%
GetFor(...)0%110100%
GetFor(...)0%110100%
GetForAll()0%110100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/InternalECSComponents/InternalECSComponent.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Controllers;
 4using DCL.ECS7.InternalComponents;
 5using DCL.ECSRuntime;
 6using DCL.Models;
 7
 8public readonly struct InternalComponentWriteData
 9{
 10    public readonly IParcelScene scene;
 11    public readonly long entityId;
 12    public readonly int componentId;
 13    public readonly InternalComponent data;
 14
 15    public InternalComponentWriteData(IParcelScene scene, long entityId, int componentId, InternalComponent data)
 16    {
 17        this.scene = scene;
 18        this.entityId = entityId;
 19        this.componentId = componentId;
 20        this.data = data;
 21    }
 22}
 23
 24public class InternalECSComponent<T> : IInternalECSComponent<T> where T : InternalComponent
 25{
 26    private readonly ECSComponentsFactory componentsFactory;
 27    private readonly int componentId;
 28    private readonly ECSComponent<T> component;
 29    private readonly IList<InternalComponentWriteData> scheduledWrite;
 30
 86031    public InternalECSComponent(InternalECSComponentsId id,
 32        ECSComponentsManager componentsManager,
 33        ECSComponentsFactory componentsFactory,
 34        Func<IECSComponentHandler<T>> handlerBuilder,
 35        IList<InternalComponentWriteData> scheduledWrite)
 36    {
 86037        this.componentId = (int)id;
 86038        this.componentsFactory = componentsFactory;
 86039        this.scheduledWrite = scheduledWrite;
 40
 120241        componentsFactory.AddOrReplaceComponent<T>(componentId, x => (T)x, handlerBuilder);
 86042        component = (ECSComponent<T>)componentsManager.GetOrCreateComponent(componentId);
 86043    }
 44
 45    public void PutFor(IParcelScene scene, IDCLEntity entity, T model)
 46    {
 24147        PutFor(scene, entity.entityId, model);
 24148    }
 49
 50    public void PutFor(IParcelScene scene, long entityId, T model)
 51    {
 34052        model._dirty = true;
 34053        scene.crdtExecutor.ExecuteWithoutStoringState(entityId, componentId, model);
 34054        scheduledWrite.Add(new InternalComponentWriteData(scene, entityId, componentId, model));
 34055    }
 56
 57    public void RemoveFor(IParcelScene scene, IDCLEntity entity, T defaultModel = null)
 58    {
 6659        RemoveFor(scene, entity.entityId, defaultModel);
 6660    }
 61
 62    public void RemoveFor(IParcelScene scene, long entityId, T defaultModel = null)
 63    {
 6964        if (defaultModel != null)
 65        {
 266            defaultModel._dirty = true;
 267            scene.crdtExecutor.ExecuteWithoutStoringState(entityId, componentId, defaultModel);
 268            scheduledWrite.Add(new InternalComponentWriteData(scene, entityId, componentId, null));
 69        }
 70        else
 71        {
 6772            scene.crdtExecutor.ExecuteWithoutStoringState(entityId, componentId, null);
 73        }
 6774    }
 75
 76    public IECSReadOnlyComponentData<T> GetFor(IParcelScene scene, IDCLEntity entity)
 77    {
 32978        return component.Get(scene, entity);
 79    }
 80
 81    public IECSReadOnlyComponentData<T> GetFor(IParcelScene scene, long entityId)
 82    {
 10183        return component.Get(scene, entityId);
 84    }
 85
 86    public IReadOnlyList<KeyValueSetTriplet<IParcelScene, long, ECSComponentData<T>>> GetForAll()
 87    {
 11388        return component.Get();
 89    }
 90
 91    public void Dispose()
 92    {
 1693        componentsFactory.RemoveComponent(componentId);
 1694    }
 95}