< 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
 73416        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 20        public void Initialize()
 21        {
 73422            CoroutineStarter.Start(InitializeCoroutine());
 73423        }
 24
 25        IEnumerator InitializeCoroutine()
 26        {
 146827            yield return null;
 146828            poolableComponentFactory.PrewarmPools();
 146829        }
 30
 73431        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 32        {
 73433            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 34
 35            // Transform
 73436            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 73437            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_ATTACH, BuildComponent<AvatarAttachComponent>);
 38
 39            // Shapes
 73440            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 73441            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 73442            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 73443            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 73444            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 73445            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 73446            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 73447            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 73448            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 49
 73450            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 73451            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 52
 53            // Materials
 73454            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 73455            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 73456            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 73457            builders.Add((int) CLASS_ID.AVATAR_TEXTURE, BuildComponent<DCLAvatarTexture>);
 58
 59            // Audio
 73460            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 73461            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 73462            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 63
 64            // UI
 73465            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 73466            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 73467            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 73468            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 73469            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 73470            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 73471            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 73472            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 73473            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 74
 75            // Video
 73476            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 73477            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 78
 79            // Builder in world
 73480            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 73481            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 73482            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 83
 84            // Events
 73485            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 73486            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 73487            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 73488            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER, BuildUUIDComponent<OnPointerHoverEnter>);
 73489            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT, BuildUUIDComponent<OnPointerHoverExit>);
 90
 91            // Others
 73492            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 73493            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 73494            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 73495            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 73496            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 73497            builders.Add((int) CLASS_ID_COMPONENT.CAMERA_MODE_AREA, BuildComponent<CameraModeArea>);
 98
 73499            CoroutineStarter.Start(InitializeCoroutine());
 734100        }
 101
 47102        private IComponent BuildPoolableComponent(int classId) { return poolableComponentFactory.CreateItemFromId<BaseCo
 103
 104        protected T BuildComponent<T>(int classId)
 105            where T : IComponent, new()
 106        {
 834107            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        {
 934120            if (!builders.ContainsKey(classId))
 121            {
 0122                Debug.LogError($"Unknown classId");
 0123                return null;
 124            }
 125
 934126            IComponent newComponent = builders[classId](classId);
 127
 934128            return newComponent;
 129        }
 130
 131        public void Dispose()
 132        {
 734133        }
 134    }
 135}