< 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
 68216        private Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 136420        public void Initialize() { CoroutineStarter.Start(InitializeCoroutine()); }
 21
 22        IEnumerator InitializeCoroutine()
 23        {
 68224            yield return null;
 68225            poolableComponentFactory.PrewarmPools();
 68226        }
 27
 68228        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 29        {
 68230            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 31
 32            // Transform
 68233            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 34
 35            // Shapes
 68236            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 68237            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 68238            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 68239            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 68240            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 68241            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 68242            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 68243            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 68244            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 45
 68246            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 68247            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 48
 49            // Materials
 68250            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 68251            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 68252            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 53
 54            // Audio
 68255            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 68256            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 68257            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 58
 59            // UI
 68260            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 68261            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 68262            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 68263            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 68264            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 68265            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 68266            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 68267            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 68268            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 69
 70            // Video
 68271            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 68272            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 73
 74            // Builder in world
 68275            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 68276            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 68277            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 78
 79            // Events
 68280            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 68281            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 68282            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 83
 84            // Others
 68285            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 68286            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 68287            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 68288            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 68289            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 68290        }
 91
 4492        private IComponent BuildPoolableComponent(int classId) { return poolableComponentFactory.CreateItemFromId<BaseCo
 93
 94        private T BuildComponent<T>(int classId)
 95            where T : IComponent, new()
 96        {
 70397            return new T();
 98        }
 99
 100        private T BuildUUIDComponent<T>(int classId)
 101            where T : UnityEngine.Component
 102        {
 31103            var go = new GameObject("UUID Component");
 31104            T newComponent = go.GetOrCreateComponent<T>();
 31105            return newComponent;
 106        }
 107
 108        public IComponent CreateComponent(int classId)
 109        {
 778110            if (!builders.ContainsKey(classId))
 111            {
 0112                Debug.LogError($"Unknown classId");
 0113                return null;
 114            }
 115
 778116            IComponent newComponent = builders[classId](classId);
 117
 778118            return newComponent;
 119        }
 120    }
 121}