< Summary

Class:DCL.RuntimeComponentFactory
Assembly:DCL.Runtime
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/RuntimeComponentFactory/RuntimeComponentFactory.cs
Covered lines:19
Uncovered lines:3
Coverable lines:22
Total lines:67
Line coverage:86.3% (19 of 22)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:10
Method coverage:100% (10 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RuntimeComponentFactory()0%110100%
RegisterBuilder(...)0%2.062075%
UnregisterBuilder(...)0%220100%
CreateComponent(...)0%2.262060%
Initialize()0%110100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/RuntimeComponentFactory/RuntimeComponentFactory.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL.Components;
 5using DCL.Controllers;
 6using DCL.Helpers;
 7using DCL.Models;
 8using UnityEngine;
 9
 10namespace DCL
 11{
 12    public class RuntimeComponentFactory : IRuntimeComponentFactory
 13    {
 14        // Temporal delegate for special behaviours. Should be deleted or refactored later.
 88915        public Dictionary<int, IRuntimeComponentFactory.CreateCondition> createConditions { get; set; } =
 51916            new Dictionary<int, IRuntimeComponentFactory.CreateCondition>();
 17
 114318        public Dictionary<int, IRuntimeComponentFactory.CreateOverride> createOverrides { get; set; } =
 51919            new Dictionary<int, IRuntimeComponentFactory.CreateOverride>();
 20
 21        protected delegate IComponent ComponentBuilder(int classId);
 22
 51923        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 24
 25        public void RegisterBuilder(int classId, Func<IComponent> builder)
 26        {
 929227            if (builders.ContainsKey(classId))
 028                builders[classId] = (id) => builder();
 29            else
 1015230                builders.Add(classId, (id) => builder());
 929231        }
 32
 33        public void UnregisterBuilder(int classId)
 34        {
 1008135            if (!builders.ContainsKey(classId))
 91236                return;
 37
 916938            builders.Remove(classId);
 916939        }
 40
 41        public IComponent CreateComponent(int classId)
 42        {
 86043            if (!builders.ContainsKey(classId))
 44            {
 045                Debug.LogError(
 46                    $"Unknown classId: {classId} - Make sure the component is registered! (You forgot to add a plugin?)"
 047                return null;
 48            }
 49
 86050            IComponent newComponent = builders[classId](classId);
 51
 86052            return newComponent;
 53        }
 54
 51955        public RuntimeComponentFactory()
 56        {
 51957        }
 58
 59        public void Initialize()
 60        {
 51961        }
 62
 63        public void Dispose()
 64        {
 51965        }
 66    }
 67}