< Summary

Class:DCL.RuntimeComponentFactory
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/RuntimeComponentFactory/RuntimeComponentFactory.cs
Covered lines:57
Uncovered lines:3
Coverable lines:60
Total lines:122
Line coverage:95% (57 of 60)
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        protected delegate IComponent ComponentBuilder(int classId);
 15
 71816        protected Dictionary<int, ComponentBuilder> builders = new Dictionary<int, ComponentBuilder>();
 17
 018        public IPoolableComponentFactory poolableComponentFactory { get; private set; }
 19
 143620        public void Initialize() { CoroutineStarter.Start(InitializeCoroutine()); }
 21
 22        IEnumerator InitializeCoroutine()
 23        {
 71824            yield return null;
 71825            poolableComponentFactory.PrewarmPools();
 71826        }
 27
 71828        public RuntimeComponentFactory(IPoolableComponentFactory poolableComponentFactory = null)
 29        {
 71830            this.poolableComponentFactory = poolableComponentFactory ?? PoolableComponentFactory.Create();
 31
 32            // Transform
 71833            builders.Add((int) CLASS_ID_COMPONENT.TRANSFORM, BuildComponent<DCLTransform>);
 71834            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_ATTACH, BuildComponent<AvatarAttachComponent>);
 35
 36            // Shapes
 71837            builders.Add((int) CLASS_ID.BOX_SHAPE, BuildComponent<BoxShape>);
 71838            builders.Add((int) CLASS_ID.SPHERE_SHAPE, BuildComponent<SphereShape>);
 71839            builders.Add((int) CLASS_ID.CYLINDER_SHAPE, BuildComponent<CylinderShape>);
 71840            builders.Add((int) CLASS_ID.CONE_SHAPE, BuildComponent<ConeShape>);
 71841            builders.Add((int) CLASS_ID.PLANE_SHAPE, BuildComponent<PlaneShape>);
 71842            builders.Add((int) CLASS_ID.GLTF_SHAPE, BuildComponent<GLTFShape>);
 71843            builders.Add((int) CLASS_ID.NFT_SHAPE, BuildComponent<NFTShape>);
 71844            builders.Add((int) CLASS_ID.OBJ_SHAPE, BuildComponent<OBJShape>);
 71845            builders.Add((int) CLASS_ID_COMPONENT.TEXT_SHAPE, BuildPoolableComponent);
 46
 71847            builders.Add((int) CLASS_ID_COMPONENT.BILLBOARD, BuildPoolableComponent);
 71848            builders.Add((int) CLASS_ID_COMPONENT.SMART_ITEM, BuildPoolableComponent);
 49
 50            // Materials
 71851            builders.Add((int) CLASS_ID.BASIC_MATERIAL, BuildComponent<BasicMaterial>);
 71852            builders.Add((int) CLASS_ID.PBR_MATERIAL, BuildComponent<PBRMaterial>);
 71853            builders.Add((int) CLASS_ID.TEXTURE, BuildComponent<DCLTexture>);
 54
 55            // Audio
 71856            builders.Add((int) CLASS_ID.AUDIO_CLIP, BuildComponent<DCLAudioClip>);
 71857            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_SOURCE, BuildPoolableComponent);
 71858            builders.Add((int) CLASS_ID_COMPONENT.AUDIO_STREAM, BuildPoolableComponent);
 59
 60            // UI
 71861            builders.Add((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>);
 71862            builders.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>);
 71863            builders.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>);
 71864            builders.Add((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>);
 71865            builders.Add((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>);
 71866            builders.Add((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>);
 71867            builders.Add((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>);
 71868            builders.Add((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>);
 71869            builders.Add((int) CLASS_ID.FONT, BuildComponent<DCLFont>);
 70
 71            // Video
 71872            builders.Add((int) CLASS_ID.VIDEO_CLIP, BuildComponent<DCLVideoClip>);
 71873            builders.Add((int) CLASS_ID.VIDEO_TEXTURE, BuildComponent<DCLVideoTexture>);
 74
 75            // Builder in world
 71876            builders.Add((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 71877            builders.Add((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 71878            builders.Add((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 79
 80            // Events
 71881            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_UP, BuildUUIDComponent<OnPointerUp>);
 71882            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, BuildUUIDComponent<OnPointerDown>);
 71883            builders.Add((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, BuildUUIDComponent<OnClick>);
 84
 85            // Others
 71886            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_SHAPE, BuildPoolableComponent);
 71887            builders.Add((int) CLASS_ID_COMPONENT.ANIMATOR, BuildPoolableComponent);
 71888            builders.Add((int) CLASS_ID_COMPONENT.GIZMOS, BuildPoolableComponent);
 71889            builders.Add((int) CLASS_ID_COMPONENT.AVATAR_MODIFIER_AREA, BuildPoolableComponent);
 71890            builders.Add((int) CLASS_ID_COMPONENT.QUEST_TRACKING_INFORMATION, BuildPoolableComponent);
 71891        }
 92
 4693        private IComponent BuildPoolableComponent(int classId) { return poolableComponentFactory.CreateItemFromId<BaseCo
 94
 95        protected T BuildComponent<T>(int classId)
 96            where T : IComponent, new()
 97        {
 71798            return new T();
 99        }
 100
 101        private T BuildUUIDComponent<T>(int classId)
 102            where T : UnityEngine.Component
 103        {
 34104            var go = new GameObject("UUID Component");
 34105            T newComponent = go.GetOrCreateComponent<T>();
 34106            return newComponent;
 107        }
 108
 109        public IComponent CreateComponent(int classId)
 110        {
 797111            if (!builders.ContainsKey(classId))
 112            {
 0113                Debug.LogError($"Unknown classId");
 0114                return null;
 115            }
 116
 797117            IComponent newComponent = builders[classId](classId);
 118
 797119            return newComponent;
 120        }
 121    }
 122}