< Summary

Class:DCL.RuntimeComponentFactory
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/RuntimeComponentFactory/RuntimeComponentFactory.cs
Covered lines:56
Uncovered lines:3
Coverable lines:59
Total lines:121
Line coverage:94.9% (56 of 59)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RuntimeComponentFactory(...)0%220100%
Initialize()0%110100%
InitializeCoroutine()0%330100%
BuildPoolableComponent(...)0%110100%
BuildComponent[T](...)0%110100%
BuildUUIDComponent[T](...)0%110100%
CreateComponent(...)0%2.262060%

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        private delegate IComponent ComponentBuilder(int classId);
 15
 68916        private Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 137820        public void Initialize() { CoroutineStarter.Start(InitializeCoroutine()); }
 21
 22        IEnumerator InitializeCoroutine()
 23        {
 68924            yield return null;
 68925            poolableComponentFactory.PrewarmPools();
 68926        }
 27
 68928        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 29        {
 68930            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 31
 32            // Transform
 68933            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 34
 35            // Shapes
 68936            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 68937            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 68938            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 68939            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 68940            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 68941            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 68942            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 68943            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 68944            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 45
 68946            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 68947            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 48
 49            // Materials
 68950            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 68951            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 68952            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 53
 54            // Audio
 68955            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 68956            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 68957            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 58
 59            // UI
 68960            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 68961            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 68962            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 68963            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 68964            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 68965            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 68966            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 68967            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 68968            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 69
 70            // Video
 68971            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 68972            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 73
 74            // Builder in world
 68975            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 68976            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 68977            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 78
 79            // Events
 68980            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 68981            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 68982            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 83
 84            // Others
 68985            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 68986            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 68987            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 68988            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 68989            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 68990        }
 91
 4592        private IComponent BuildPoolableComponent(int classId) { return poolableComponentFactory.CreateItemFromId<BaseCo
 93
 94        private T BuildComponent<T>(int classId)
 95            where T : IComponent, new()
 96        {
 71297            return new T();
 98        }
 99
 100        private T BuildUUIDComponent<T>(int classId)
 101            where T : UnityEngine.Component
 102        {
 32103            var go = new GameObject("UUID Component");
 32104            T newComponent = go.GetOrCreateComponent<T>();
 32105            return newComponent;
 106        }
 107
 108        public IComponent CreateComponent(int classId)
 109        {
 789110            if (!builders.ContainsKey(classId))
 111            {
 0112                Debug.LogError($"Unknown classId");
 0113                return null;
 114            }
 115
 789116            IComponent newComponent = builders[classId](classId);
 117
 789118            return newComponent;
 119        }
 120    }
 121}