< Summary

Class:PluginSystem
Assembly:FeatureController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/FeatureController/PluginSystem.cs
Covered lines:38
Uncovered lines:1
Coverable lines:39
Total lines:105
Line coverage:97.4% (38 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PluginSystem()0%110100%
GetCurrentConfig()0%2100%
Start()0%110100%
OnGUI()0%220100%
Update()0%220100%
LateUpdate()0%220100%
OnDestroy()0%220100%
OnKernelConfigChanged(...)0%110100%
ApplyFeaturesConfig(...)0%110100%
HandleFeature[T](...)0%220100%
InitializeFeature[T]()0%330100%
RemoveFeature[T]()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/FeatureController/PluginSystem.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL;
 5using DCL.Tutorial;
 6using UnityEngine;
 7
 8/// <summary>
 9/// This class is used to handle a feature that needs the MonoBehaviour callbacks.
 10///
 11/// You need to add it as a feature toggle in gitlab so kernel will understand when to activate it and deactivate it.
 12/// After that, your feature manager should inherit from 'Feature' so it can start receiving MonoBehaviour callbacks whe
 13/// </summary>
 14public class PluginSystem
 15{
 12316    private List<PluginFeature> activeFeatures = new List<PluginFeature>();
 17
 18    private KernelConfigModel currentConfig;
 19
 020    public KernelConfigModel GetCurrentConfig() { return currentConfig; }
 21
 22    public void Start()
 23    {
 12324        KernelConfig.i.EnsureConfigInitialized().Then(ApplyFeaturesConfig);
 12325        KernelConfig.i.OnChange += OnKernelConfigChanged;
 12326    }
 27
 28    public void OnGUI()
 29    {
 1401630        foreach (PluginFeature feature in activeFeatures)
 31        {
 350432            feature.OnGUI();
 33        }
 350434    }
 35
 36    public void Update()
 37    {
 5094838        foreach (PluginFeature feature in activeFeatures)
 39        {
 668040            feature.Update();
 41        }
 1879442    }
 43
 44    public void LateUpdate()
 45    {
 5094646        foreach (PluginFeature feature in activeFeatures)
 47        {
 668048            feature.LateUpdate();
 49        }
 1879350    }
 51
 52    public void OnDestroy()
 53    {
 37254        foreach (PluginFeature feature in activeFeatures)
 55        {
 6456            feature.Dispose();
 57        }
 12258    }
 59
 59260    public void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel previous) { ApplyFeaturesConfig(curre
 61
 62    public void ApplyFeaturesConfig(KernelConfigModel config)
 63    {
 42164        HandleFeature<BIWMainController>(config.features.enableBuilderInWorld);
 42165        HandleFeature<TutorialController>(config.features.enableTutorial);
 42166        HandleFeature<DebugPluginFeature>(true);
 42167        currentConfig = config;
 42168    }
 69
 70    private void HandleFeature<T>(bool isActive) where T : PluginFeature, new ()
 71    {
 126372        if (isActive)
 59873            InitializeFeature<T>();
 74        else
 66575            RemoveFeature<T>();
 66576    }
 77
 78    private void InitializeFeature<T>() where T : PluginFeature, new ()
 79    {
 155080        for (int i = 0; i < activeFeatures.Count; i++)
 81        {
 53282            if (activeFeatures[i].GetType() == typeof(T))
 35583                return;
 84        }
 85
 86        //NOTE: We should revise this code on the future, because we'd want to use custom constructors to DI.
 87        //      So here we most likely need to use an abstract factory, or just pass the new Feature object by argument.
 24388        PluginFeature pluginFeature = new T();
 24389        pluginFeature.Initialize();
 24390        activeFeatures.Add(pluginFeature);
 24391    }
 92
 93    private void RemoveFeature<T>() where T : PluginFeature
 94    {
 275095        for (int i = 0; i < activeFeatures.Count; i++)
 96        {
 71097            if (activeFeatures[i].GetType() == typeof(T))
 98            {
 11899                activeFeatures[i].Dispose();
 118100                activeFeatures.Remove(activeFeatures[i]);
 101            }
 102        }
 665103    }
 104
 105}