< 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

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.
 93815        public Dictionary<int, IRuntimeComponentFactory.CreateCondition> createConditions { get; set; } =
 77216            new Dictionary<int, IRuntimeComponentFactory.CreateCondition>();
 17
 138618        public Dictionary<int, IRuntimeComponentFactory.CreateOverride> createOverrides { get; set; } =
 77219            new Dictionary<int, IRuntimeComponentFactory.CreateOverride>();
 20
 21        protected delegate IComponent ComponentBuilder(int classId);
 22
 77223        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 24
 25        public void RegisterBuilder(int classId, Func<IComponent> builder)
 26        {
 1240427            if (builders.ContainsKey(classId))
 028                builders[classId] = (id) => builder();
 29            else
 1339930                builders.Add(classId, (id) => builder());
 1240431        }
 32
 33        public void UnregisterBuilder(int classId)
 34        {
 1343535            if (!builders.ContainsKey(classId))
 119136                return;
 37
 1224438            builders.Remove(classId);
 1224439        }
 40
 41        public IComponent CreateComponent(int classId)
 42        {
 99543            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
 99550            IComponent newComponent = builders[classId](classId);
 51
 99552            return newComponent;
 53        }
 54
 77255        public RuntimeComponentFactory()
 56        {
 77257        }
 58
 59        public void Initialize()
 60        {
 77261        }
 62
 63        public void Dispose()
 64        {
 77265        }
 66    }
 67}