< Summary

Class:DCL.RuntimeComponentFactory
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/RuntimeComponentFactory/RuntimeComponentFactory.cs
Covered lines:64
Uncovered lines:3
Coverable lines:67
Total lines:135
Line coverage:95.5% (64 of 67)
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%
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        protected delegate IComponent ComponentBuilder(int classId);
 15
 73516        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 20        public void Initialize()
 21        {
 73522            CoroutineStarter.Start(InitializeCoroutine());
 73523        }
 24
 25        IEnumerator InitializeCoroutine()
 26        {
 147027            yield return null;
 147028            poolableComponentFactory.PrewarmPools();
 147029        }
 30
 73531        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 32        {
 73533            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 34
 35            // Transform
 73536            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 73537            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_ATTACH, BuildComponent<AvatarAttachComponent>);
 38
 39            // Shapes
 73540            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 73541            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 73542            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 73543            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 73544            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 73545            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 73546            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 73547            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 73548            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 49
 73550            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 73551            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 52
 53            // Materials
 73554            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 73555            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 73556            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 73557            builders.Add((int) CLASS_ID.AVATAR_TEXTURE, BuildComponent<DCLAvatarTexture>);
 58
 59            // Audio
 73560            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 73561            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 73562            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 63
 64            // UI
 73565            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 73566            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 73567            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 73568            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 73569            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 73570            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 73571            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 73572            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 73573            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 74
 75            // Video
 73576            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 73577            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 78
 79            // Builder in world
 73580            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 73581            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 73582            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 83
 84            // Events
 73585            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 73586            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 73587            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 73588            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER, BuildUUIDComponent<OnPointerHoverEnter>);
 73589            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT, BuildUUIDComponent<OnPointerHoverExit>);
 90
 91            // Others
 73592            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 73593            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 73594            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 73595            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 73596            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 73597            builders.Add((int) CLASS_ID_COMPONENT.CAMERA_MODE_AREA, BuildComponent<CameraModeArea>);
 98
 73599            CoroutineStarter.Start(InitializeCoroutine());
 735100        }
 101
 48102        private IComponent BuildPoolableComponent(int classId) { return poolableComponentFactory.CreateItemFromId<BaseCo
 103
 104        protected T BuildComponent<T>(int classId)
 105            where T : IComponent, new()
 106        {
 836107            return new T();
 108        }
 109
 110        private T BuildUUIDComponent<T>(int classId)
 111            where T : UnityEngine.Component
 112        {
 53113            var go = new GameObject("UUID Component");
 53114            T newComponent = go.GetOrCreateComponent<T>();
 53115            return newComponent;
 116        }
 117
 118        public IComponent CreateComponent(int classId)
 119        {
 937120            if (!builders.ContainsKey(classId))
 121            {
 0122                Debug.LogError($"Unknown classId");
 0123                return null;
 124            }
 125
 937126            IComponent newComponent = builders[classId](classId);
 127
 937128            return newComponent;
 129        }
 130
 131        public void Dispose()
 132        {
 735133        }
 134    }
 135}