< Summary

Class:BIWInputHandler
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWInputHandler.cs
Covered lines:0
Uncovered lines:84
Coverable lines:84
Total lines:179
Line coverage:0% (0 of 84)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%6200%
Dispose()0%6200%
Update()0%20400%
CheckEditModeInput()0%6200%
StartMultiSelection()0%2100%
EndMultiSelection()0%2100%
MouseClick(...)0%56700%
MouseClickOnUI(...)0%2100%
IsMultiSelectionActive()0%2100%
RedoAction()0%2100%
UndoAction()0%6200%
MouseClickDetected()0%2100%
InputDone()0%2100%
StopInput()0%2100%
ResumeInput()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWInputHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using System.Collections;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using System;
 7using DCL.Builder;
 8
 9public class BIWInputHandler : BIWController, IBIWInputHandler
 10{
 11    private const float MS_BETWEEN_INPUT_INTERACTION = 200;
 12
 13    private IBIWActionController actionController;
 14    private IBIWModeController modeController;
 15    private IBIWInputWrapper inputWrapper;
 16    private IBIWOutlinerController outlinerController;
 17    private IBIWEntityHandler entityHandler;
 18
 19    private InputAction_Trigger toggleRedoActionInputAction;
 20    private InputAction_Trigger toggleUndoActionInputAction;
 21    private InputAction_Hold multiSelectionInputAction;
 22
 23    private InputAction_Hold.Started multiSelectionStartDelegate;
 24    private InputAction_Hold.Finished multiSelectionFinishedDelegate;
 25
 26    private InputAction_Trigger.Triggered redoDelegate;
 27    private InputAction_Trigger.Triggered undoDelegate;
 28
 29    private bool isMultiSelectionActive = false;
 30
 31    private float nexTimeToReceiveInput;
 32
 33    public override void Initialize(IContext context)
 34    {
 035        base.Initialize(context);
 36
 037        actionController = context.editorContext.actionController;
 038        modeController = context.editorContext.modeController;
 039        inputWrapper = context.editorContext.inputWrapper;
 040        outlinerController = context.editorContext.outlinerController;
 041        entityHandler = context.editorContext.entityHandler;
 42
 043        toggleRedoActionInputAction = context.inputsReferencesAsset.toggleRedoActionInputAction;
 044        toggleUndoActionInputAction = context.inputsReferencesAsset.toggleUndoActionInputAction;
 045        multiSelectionInputAction = context.inputsReferencesAsset.multiSelectionInputAction;
 46
 047        if ( context.editorContext.editorHUD != null)
 48        {
 049            context.editorContext.editorHUD.OnStopInput += StopInput;
 050            context.editorContext.editorHUD.OnResumeInput += ResumeInput;
 51        }
 52
 053        redoDelegate = (action) => RedoAction();
 054        undoDelegate = (action) => UndoAction();
 55
 056        toggleRedoActionInputAction.OnTriggered += redoDelegate;
 057        toggleUndoActionInputAction.OnTriggered += undoDelegate;
 58
 059        multiSelectionStartDelegate = (action) => StartMultiSelection();
 060        multiSelectionFinishedDelegate = (action) => EndMultiSelection();
 61
 062        BIWInputWrapper.OnMouseClick += MouseClick;
 063        BIWInputWrapper.OnMouseClickOnUI += MouseClickOnUI;
 064        modeController.OnInputDone += InputDone;
 65
 066        multiSelectionInputAction.OnStarted += multiSelectionStartDelegate;
 067        multiSelectionInputAction.OnFinished += multiSelectionFinishedDelegate;
 068    }
 69
 70    public override void Dispose()
 71    {
 072        base.Dispose();
 73
 074        toggleRedoActionInputAction.OnTriggered -= redoDelegate;
 075        toggleUndoActionInputAction.OnTriggered -= undoDelegate;
 76
 077        multiSelectionInputAction.OnStarted -= multiSelectionStartDelegate;
 078        multiSelectionInputAction.OnFinished -= multiSelectionFinishedDelegate;
 79
 080        BIWInputWrapper.OnMouseClick -= MouseClick;
 081        BIWInputWrapper.OnMouseClickOnUI -= MouseClickOnUI;
 082        modeController.OnInputDone -= InputDone;
 083        if ( context.editorContext.editorHUD != null)
 84        {
 085            context.editorContext.editorHUD.OnStopInput -= StopInput;
 086            context.editorContext.editorHUD.OnResumeInput -= ResumeInput;
 87        }
 088    }
 89
 90    public override void Update()
 91    {
 092        base.Update();
 93
 094        if (Time.timeSinceLevelLoad < nexTimeToReceiveInput)
 095            return;
 96
 097        if (Utils.IsCursorLocked || modeController.IsGodModeActive())
 098            CheckEditModeInput();
 099        modeController.CheckInput();
 0100    }
 101
 102    private void CheckEditModeInput()
 103    {
 0104        outlinerController.CheckOutline();
 105
 0106        if (entityHandler.IsAnyEntitySelected())
 107        {
 0108            modeController.CheckInputSelectedEntities();
 109        }
 0110    }
 111
 112    private void StartMultiSelection()
 113    {
 0114        isMultiSelectionActive = true;
 0115        entityHandler.SetMultiSelectionActive(isMultiSelectionActive);
 0116        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
 0117        modeController.StartMultiSelection();
 0118    }
 119
 120    private void EndMultiSelection()
 121    {
 0122        isMultiSelectionActive = false;
 0123        entityHandler.SetMultiSelectionActive(isMultiSelectionActive);
 0124        modeController.EndMultiSelection();
 0125        outlinerController.CancelUnselectedOutlines();
 0126    }
 127
 128    private void MouseClick(int buttonID, Vector3 position)
 129    {
 0130        if (!isEditModeActive)
 0131            return;
 132
 0133        if (Time.timeSinceLevelLoad < nexTimeToReceiveInput)
 0134            return;
 135
 0136        if (!BIWUtils.IsPointerOverUIElement())
 0137            context.editorContext.editorHUD.HideExtraBtns();
 138
 0139        if (Utils.IsCursorLocked || modeController.IsGodModeActive())
 140        {
 0141            if (buttonID == 0)
 142            {
 0143                MouseClickDetected();
 0144                InputDone();
 0145                return;
 146            }
 147
 0148            outlinerController.CheckOutline();
 149        }
 0150    }
 151
 0152    private void MouseClickOnUI(int buttonID, Vector3 position) {  context.editorContext.editorHUD.HideExtraBtns(); }
 153
 0154    public bool IsMultiSelectionActive() => isMultiSelectionActive;
 155
 156    private void RedoAction()
 157    {
 0158        actionController.TryToRedoAction();
 0159        InputDone();
 0160    }
 161
 162    private void UndoAction()
 163    {
 0164        InputDone();
 165
 0166        if (modeController.ShouldCancelUndoAction())
 0167            return;
 168
 0169        actionController.TryToUndoAction();
 0170    }
 171
 0172    private void MouseClickDetected() { modeController.MouseClickDetected(); }
 173
 0174    private void InputDone() { nexTimeToReceiveInput = Time.timeSinceLevelLoad + MS_BETWEEN_INPUT_INTERACTION / 1000; }
 175
 0176    private void StopInput() { inputWrapper.StopInput(); }
 177
 0178    private void ResumeInput() { inputWrapper.ResumeInput(); }
 179}