< 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
 67916        private Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 135820        public void Initialize() { CoroutineStarter.Start(InitializeCoroutine()); }
 21
 22        IEnumerator InitializeCoroutine()
 23        {
 67924            yield return null;
 67925            poolableComponentFactory.PrewarmPools();
 67926        }
 27
 67928        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 29        {
 67930            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 31
 32            // Transform
 67933            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 34
 35            // Shapes
 67936            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 67937            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 67938            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 67939            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 67940            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 67941            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 67942            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 67943            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 67944            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 45
 67946            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 67947            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 48
 49            // Materials
 67950            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 67951            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 67952            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 53
 54            // Audio
 67955            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 67956            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 67957            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 58
 59            // UI
 67960            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 67961            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 67962            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 67963            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 67964            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 67965            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 67966            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 67967            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 67968            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 69
 70            // Video
 67971            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 67972            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 73
 74            // Builder in world
 67975            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 67976            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 67977            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 78
 79            // Events
 67980            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 67981            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 67982            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 83
 84            // Others
 67985            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 67986            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 67987            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 67988            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 67989            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 67990        }
 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        {
 69797            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        {
 772110            if (!builders.ContainsKey(classId))
 111            {
 0112                Debug.LogError($"Unknown classId");
 0113                return null;
 114            }
 115
 772116            IComponent newComponent = builders[classId](classId);
 117
 772118            return newComponent;
 119        }
 120    }
 121}