< 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.
 83815        public Dictionary<int, IRuntimeComponentFactory.CreateCondition> createConditions { get; set; } =
 59616            new Dictionary<int, IRuntimeComponentFactory.CreateCondition>();
 17
 119118        public Dictionary<int, IRuntimeComponentFactory.CreateOverride> createOverrides { get; set; } =
 59619            new Dictionary<int, IRuntimeComponentFactory.CreateOverride>();
 20
 21        protected delegate IComponent ComponentBuilder(int classId);
 22
 59623        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 24
 25        public void RegisterBuilder(int classId, Func<IComponent> builder)
 26        {
 991527            if (builders.ContainsKey(classId))
 028                builders[classId] = (id) => builder();
 29            else
 1077230                builders.Add(classId, (id) => builder());
 991531        }
 32
 33        public void UnregisterBuilder(int classId)
 34        {
 1074035            if (!builders.ContainsKey(classId))
 95136                return;
 37
 978938            builders.Remove(classId);
 978939        }
 40
 41        public IComponent CreateComponent(int classId)
 42        {
 85743            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
 85750            IComponent newComponent = builders[classId](classId);
 51
 85752            return newComponent;
 53        }
 54
 59655        public RuntimeComponentFactory()
 56        {
 59657        }
 58
 59        public void Initialize()
 60        {
 59661        }
 62
 63        public void Dispose()
 64        {
 59665        }
 66    }
 67}