< Summary

Class:BuilderInWorldPlugin
Assembly:BIWPlugin
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Plugin/BuilderInWorldPlugin.cs
Covered lines:54
Uncovered lines:15
Coverable lines:69
Total lines:149
Line coverage:78.2% (54 of 69)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BuilderInWorldPlugin()0%6200%
BuilderInWorldPlugin(...)0%110100%
Initialize()0%110100%
Dispose()0%22092.86%
Update()0%110100%
LateUpdate()0%110100%
OnGUI()0%110100%
UnregisterRuntimeComponents()0%110100%
RegisterRuntimeComponents()0%110100%
BuildComponent[T]()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Plugin/BuilderInWorldPlugin.cs

#LineLine coverage
 1using DCL;
 2using DCL.Builder;
 3using DCL.Components;
 4using DCL.Models;
 5
 6public class BuilderInWorldPlugin : IPlugin
 7{
 8    private const string DEV_FLAG_NAME = "builder-dev";
 9    internal IBIWEditor editor;
 10    internal IBuilderMainPanelController panelController;
 11    internal IBuilderAPIController builderAPIController;
 12    internal ISceneManager sceneManager;
 13    internal ICameraController cameraController;
 14    internal IPublisher publisher;
 15    internal ICommonHUD commonHUD;
 16
 17    internal IContext context;
 18
 019    public BuilderInWorldPlugin()
 20    {
 021        if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(DEV_FLAG_NAME))
 022            DataStore.i.builderInWorld.isDevBuild.Set(true);
 23
 024        RegisterRuntimeComponents();
 25
 026        panelController = new BuilderMainPanelController();
 027        editor = new BuilderInWorldEditor();
 028        builderAPIController = new BuilderAPIController();
 029        sceneManager = new SceneManager();
 030        cameraController = new CameraController();
 031        publisher = new Publisher();
 032        commonHUD = new CommonHUD();
 33
 034        context = new Context(editor,
 35            panelController,
 36            builderAPIController,
 37            sceneManager,
 38            cameraController,
 39            publisher,
 40            commonHUD,
 41            new BuilderEditorHUDController(),
 42            new BIWOutlinerController(),
 43            new BIWInputHandler(),
 44            new BIWInputWrapper(),
 45            new BIWPublishController(),
 46            new BIWCreatorController(),
 47            new BIWModeController(),
 48            new BIWFloorHandler(),
 49            new BIWEntityHandler(),
 50            new BIWActionController(),
 51            new BIWSaveController(),
 52            new BIWRaycastController(),
 53            new BIWGizmosController(),
 54            SceneReferences.i);
 55
 056        Initialize();
 057    }
 58
 759    public BuilderInWorldPlugin(IContext context)
 60    {
 761        this.context = context;
 762        sceneManager = context.sceneManager;
 763        panelController = context.panelHUD;
 764        editor = context.editor;
 765        builderAPIController = context.builderAPIController;
 766        cameraController = context.cameraController;
 767        publisher = context.publisher;
 768        commonHUD = context.commonHUD;
 69
 770        Initialize();
 771    }
 72
 73    private void Initialize()
 74    {
 75        //We init the lands so we don't have a null reference
 776        DataStore.i.builderInWorld.landsWithAccess.Set(new LandWithAccess[0]);
 77
 778        BIWCatalogManager.Init();
 79
 780        panelController.Initialize(context);
 781        editor.Initialize(context);
 782        builderAPIController.Initialize(context);
 783        sceneManager.Initialize(context);
 784        cameraController.Initialize(context);
 785        publisher.Initialize(context);
 786        commonHUD.Initialize(context);
 87
 788        DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update);
 789        DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate);
 790        DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.OnGui, OnGUI);
 91
 792        DataStore.i.builderInWorld.isInitialized.Set(true);
 793    }
 94
 95    public void Dispose()
 96    {
 797        if (DataStore.i.common.isApplicationQuitting.Get())
 098            return;
 99
 7100        editor.Dispose();
 7101        panelController.Dispose();
 7102        sceneManager.Dispose();
 7103        cameraController.Dispose();
 7104        publisher.Dispose();
 7105        commonHUD.Dispose();
 7106        context.Dispose();
 107
 7108        Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update);
 7109        Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate);
 7110        Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.OnGui, OnGUI);
 111
 7112        UnregisterRuntimeComponents();
 7113    }
 114
 115    public void Update()
 116    {
 2117        editor.Update();
 2118        sceneManager.Update();
 2119    }
 120
 4121    public void LateUpdate() { editor.LateUpdate(); }
 122
 2123    public void OnGUI() { editor.OnGUI(); }
 124
 125    public static void UnregisterRuntimeComponents()
 126    {
 127        // Builder in world
 82128        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 82129        factory.UnregisterBuilder((int) CLASS_ID.NAME);
 82130        factory.UnregisterBuilder((int) CLASS_ID.LOCKED_ON_EDIT);
 82131        factory.UnregisterBuilder((int) CLASS_ID.VISIBLE_ON_EDIT);
 82132    }
 133
 134    public static void RegisterRuntimeComponents()
 135    {
 136        // Builder in world
 75137        IRuntimeComponentFactory factory = Environment.i.world.componentFactory;
 75138        factory.RegisterBuilder((int) CLASS_ID.NAME, BuildComponent<DCLName>);
 75139        factory.RegisterBuilder((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>);
 75140        factory.RegisterBuilder((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>);
 75141    }
 142
 143    private static T BuildComponent<T>()
 144        where T : IComponent, new()
 145    {
 71146        return new T();
 147    }
 148
 149}