< Summary

Class:InputController
Assembly:InputController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs
Covered lines:117
Uncovered lines:89
Coverable lines:206
Total lines:712
Line coverage:56.7% (117 of 206)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputController()0%110100%
InputController()0%110100%
Update()0%7.586064.71%
Update_Trigger(...)0%506.7465052.89%
Update_Hold(...)0%89.1223050%
Update_Measurable(...)0%8.018094.12%
Stop_Measurable(...)0%220100%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Linq;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.EventSystems;
 7using DCL.Configuration;
 8
 9/// <summary>
 10/// Mapping for Trigger actions
 11/// </summary>
 12public enum DCLAction_Trigger
 13{
 14    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 15    CameraChange = 100,
 16    CursorUnlock = 101,
 17
 18    ToggleNavMap = 110,
 19    ToggleFriends = 120,
 20    CloseWindow = 121,
 21    ToggleWorldChat = 122,
 22    ToggleUIVisibility = 123,
 23    ToggleControlsHud = 124,
 24    ToggleSettings = 125,
 25    ToggleStartMenu = 126,
 26    ToggleVoiceChatRecording = 127,
 27    ToggleAvatarEditorHud = 128,
 28    ToggleQuestsPanelHud = 129,
 29    ToggleAvatarNamesHud = 130,
 30    TogglePlacesAndEventsHud = 131,
 31
 32    OpenExpressions = 200,
 33    Expression_Wave = 201,
 34    Expression_FistPump = 202,
 35    Expression_Robot = 203,
 36    Expression_RaiseHand = 204,
 37    Expression_Clap = 205,
 38    Expression_ThrowMoney = 206,
 39    Expression_SendKiss = 207,
 40    Expression_Dance = 208,
 41    Expression_Hohoho = 209,
 42    Expression_Snowfall = 210,
 43
 44    //Builder In World 4xx
 45    BuildEditModeChange = 408,
 46    BuildEditModeToggleUI = 409,
 47    BuildEditModeToggleEntityList = 410,
 48    BuildEditModeToggleCatalog = 411,
 49    BuildEditModeToggleSceneInfo = 412,
 50    BuildEditModeToggleChangeCamera = 413,
 51    BuildEditModeToggleControls = 414,
 52    BuildEditModeToggleSnapMode = 415,
 53    BuildEditModeUndoAction = 417,
 54    BuildEditModeRedoAction = 418,
 55    BuildEditModeQuickBar1 = 419,
 56    BuildEditModeQuickBar2 = 420,
 57    BuildEditModeQuickBar3 = 421,
 58    BuildEditModeQuickBar4 = 422,
 59    BuildEditModeQuickBar5 = 423,
 60    BuildEditModeQuickBar6 = 424,
 61    BuildEditModeQuickBar7 = 425,
 62    BuildEditModeQuickBar8 = 426,
 63    BuildEditModeQuickBar9 = 427,
 64    BuildEditModeDuplicate = 428,
 65    BuildEditModeTranslate = 429,
 66    BuildEditModeRotate = 430,
 67    BuildEditModeScale = 431,
 68    BuildEditModeDelete = 434,
 69    BuildEditModeFocusSelectedEntities = 435,
 70    BuildEditModeReset = 443,
 71    BuildEditHideSelectedEntities = 444,
 72    BuildEditShowAllEntities = 445,
 73    BuildEditModeResetCamera = 446,
 74    BuildEditModeZoomIn = 447,
 75    BuildEditModeZoomOut = 448
 76}
 77
 78/// <summary>
 79/// Mapping for hold actions
 80/// </summary>
 81public enum DCLAction_Hold
 82{
 83    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 84    Sprint = 1,
 85    Jump = 2,
 86    ZoomIn = 3,
 87    ZoomOut = 4,
 88    FreeCameraMode = 101,
 89    VoiceChatRecording = 102,
 90    DefaultConfirmAction = 300,
 91    DefaultCancelAction = 301,
 92    BuildEditModeMultiSelection = 432,
 93    BuildEditModeSquareMultiSelection = 433,
 94    BuildEditModeFirstPersonRotation = 436,
 95    BuildEditModeCameraAdvanceFoward = 437,
 96    BuildEditModeCameraAdvanceBack = 438,
 97    BuildEditModeCameraAdvanceLeft = 439,
 98    BuildEditModeCameraAdvanceRight = 440,
 99    BuildEditModeCameraAdvanceUp = 441,
 100    BuildEditModeCameraAdvanceDown = 442,
 101    BuildEditModeCameraPan = 446
 102}
 103
 104/// <summary>
 105/// Mapping for measurable actions
 106/// </summary>
 107public enum DCLAction_Measurable
 108{
 109    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 110    CharacterXAxis = 1,
 111    CharacterYAxis = 2,
 112    CameraXAxis = 3,
 113    CameraYAxis = 4,
 114    MouseWheel = 5
 115}
 116
 117/// <summary>
 118/// Group of actions currently actived
 119/// </summary>
 120public enum InputTypeMode
 121{
 122    OFF,
 123    GENERAL,
 124    BUILD_MODE_LOADING,
 125    BUILD_MODE
 126}
 127
 128/// <summary>
 129/// Input Controller will map inputs(keys/mouse/axis) to DCL actions, check if they can be triggered (modifiers) and rai
 130/// </summary>
 131public class InputController : MonoBehaviour
 132{
 1133    public static bool ENABLE_THIRD_PERSON_CAMERA = true;
 134
 135    [Header("General Input")]
 136    public InputAction_Trigger[] triggerTimeActions;
 137
 138    public InputAction_Hold[] holdActions;
 139    public InputAction_Measurable[] measurableActions;
 140
 141    [Header("BuildMode Input")]
 142    public InputAction_Trigger[] builderTriggerTimeActions;
 143
 144    public InputAction_Hold[] builderHoldActions;
 145    public InputAction_Trigger[] loadingBuilderTriggerTimeActions;
 146
 5563147    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 33360148    bool allUIHidden => CommonScriptableObjects.allUIHidden.Get();
 598149    public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL;
 150
 151    private void Update()
 152    {
 5563153        if (!renderingEnabled)
 154        {
 1155            Stop_Measurable(measurableActions);
 1156            return;
 157        }
 158
 5562159        switch (inputTypeMode)
 160        {
 161            case InputTypeMode.OFF:
 0162                Stop_Measurable(measurableActions);
 0163                return;
 164            case InputTypeMode.GENERAL:
 5560165                Update_Trigger(triggerTimeActions);
 5560166                Update_Hold(holdActions);
 5560167                Update_Measurable(measurableActions);
 5560168                break;
 169            case InputTypeMode.BUILD_MODE_LOADING:
 2170                Update_Trigger(loadingBuilderTriggerTimeActions);
 2171                Stop_Measurable(measurableActions);
 2172                break;
 173            case InputTypeMode.BUILD_MODE:
 0174                Update_Trigger(builderTriggerTimeActions);
 0175                Update_Hold(builderHoldActions);
 0176                Update_Measurable(measurableActions);
 177                break;
 178        }
 0179    }
 180
 181    /// <summary>
 182    /// Map the trigger actions to inputs + modifiers and check if their events must be triggered
 183    /// </summary>
 184    public void Update_Trigger(InputAction_Trigger[] triggerTimeActions)
 185    {
 278008186        for (var i = 0; i < triggerTimeActions.Length; i++)
 187        {
 133442188            var action = triggerTimeActions[i];
 189
 133442190            if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get())
 191                continue;
 192
 133442193            switch (action.GetDCLAction())
 194            {
 195                case DCLAction_Trigger.CameraChange:
 5560196                    if (CommonScriptableObjects.cameraModeInputLocked.Get())
 197                        break;
 198
 199                    //Disable until the fine-tuning is ready
 5560200                    if (ENABLE_THIRD_PERSON_CAMERA)
 5560201                        InputProcessor.FromKey(action, KeyCode.V,
 202                            modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560203                    break;
 204                case DCLAction_Trigger.CursorUnlock:
 5560205                    InputProcessor.FromMouseButtonUp(action, 1, InputProcessor.Modifier.NeedsPointerLocked);
 206#if !WEB_PLATFORM
 5560207                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.NeedsPointerLocked
 208#endif
 5560209                    break;
 210                case DCLAction_Trigger.ToggleNavMap:
 5560211                    if (allUIHidden)
 212                        break;
 5470213                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5470214                    break;
 215                case DCLAction_Trigger.ToggleFriends:
 5560216                    if (allUIHidden)
 217                        break;
 5470218                    InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None);
 5470219                    break;
 220                case DCLAction_Trigger.ToggleWorldChat:
 5560221                    if (allUIHidden)
 222                        break;
 5470223                    InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None);
 5470224                    break;
 225                case DCLAction_Trigger.ToggleUIVisibility:
 5560226                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None);
 5560227                    break;
 228                case DCLAction_Trigger.CloseWindow:
 5560229                    if (allUIHidden || DataStore.i.common.isSignUpFlow.Get())
 230                        break;
 5470231                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None);
 5470232                    break;
 233                case DCLAction_Trigger.OpenExpressions:
 5560234                    if (allUIHidden)
 235                        break;
 5470236                    InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5470237                    break;
 238                case DCLAction_Trigger.ToggleControlsHud:
 5560239                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560240                    break;
 241                case DCLAction_Trigger.ToggleSettings:
 5560242                    InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560243                    break;
 244                case DCLAction_Trigger.ToggleStartMenu:
 5560245                    if (allUIHidden)
 246                        break;
 5470247                    InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.None);
 5470248                    break;
 249                case DCLAction_Trigger.TogglePlacesAndEventsHud:
 5560250                    InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560251                    break;
 252                case DCLAction_Trigger.Expression_Wave:
 5560253                    InputProcessor.FromKey(action, KeyCode.Alpha1,
 254                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560255                    break;
 256                case DCLAction_Trigger.Expression_FistPump:
 5560257                    InputProcessor.FromKey(action, KeyCode.Alpha2,
 258                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560259                    break;
 260                case DCLAction_Trigger.Expression_Robot:
 5560261                    InputProcessor.FromKey(action, KeyCode.Alpha3,
 262                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560263                    break;
 264                case DCLAction_Trigger.Expression_RaiseHand:
 5560265                    InputProcessor.FromKey(action, KeyCode.Alpha4,
 266                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560267                    break;
 268                case DCLAction_Trigger.Expression_Clap:
 5560269                    InputProcessor.FromKey(action, KeyCode.Alpha5,
 270                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560271                    break;
 272                case DCLAction_Trigger.Expression_ThrowMoney:
 5560273                    InputProcessor.FromKey(action, KeyCode.Alpha6,
 274                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560275                    break;
 276                case DCLAction_Trigger.Expression_SendKiss:
 5560277                    InputProcessor.FromKey(action, KeyCode.Alpha7,
 278                        modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560279                    break;
 280                case DCLAction_Trigger.BuildEditModeChange:
 5562281                    InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5562282                    break;
 283                case DCLAction_Trigger.ToggleVoiceChatRecording:
 5560284                    InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 5560285                    break;
 286                case DCLAction_Trigger.ToggleAvatarEditorHud:
 5560287                    InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560288                    break;
 289                case DCLAction_Trigger.BuildEditModeToggleUI:
 0290                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0291                    break;
 292                case DCLAction_Trigger.BuildEditModeToggleChangeCamera:
 0293                    InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0294                    break;
 295                case DCLAction_Trigger.BuildEditModeToggleControls:
 0296                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0297                    break;
 298                case DCLAction_Trigger.BuildEditModeToggleSnapMode:
 0299                    InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0300                    break;
 301                case DCLAction_Trigger.BuildEditModeRedoAction:
 0302                    InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0303                    break;
 304                case DCLAction_Trigger.BuildEditModeUndoAction:
 0305                    InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0306                    break;
 307                case DCLAction_Trigger.BuildEditModeQuickBar1:
 0308                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0309                    break;
 310                case DCLAction_Trigger.BuildEditModeQuickBar2:
 0311                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0312                    break;
 313                case DCLAction_Trigger.BuildEditModeQuickBar3:
 0314                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0315                    break;
 316                case DCLAction_Trigger.BuildEditModeQuickBar4:
 0317                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0318                    break;
 319                case DCLAction_Trigger.BuildEditModeQuickBar5:
 0320                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0321                    break;
 322                case DCLAction_Trigger.BuildEditModeQuickBar6:
 0323                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0324                    break;
 325                case DCLAction_Trigger.BuildEditModeQuickBar7:
 0326                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0327                    break;
 328                case DCLAction_Trigger.BuildEditModeQuickBar8:
 0329                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0330                    break;
 331                case DCLAction_Trigger.BuildEditModeQuickBar9:
 0332                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0333                    break;
 334                case DCLAction_Trigger.BuildEditModeDelete:
 0335                    InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0336                    InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput
 0337                    break;
 338                case DCLAction_Trigger.BuildEditModeDuplicate:
 0339                    InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0340                    break;
 341                case DCLAction_Trigger.BuildEditModeTranslate:
 0342                    InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0343                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0344                    break;
 345                case DCLAction_Trigger.BuildEditModeRotate:
 0346                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0347                    break;
 348                case DCLAction_Trigger.BuildEditModeScale:
 0349                    InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0350                    break;
 351                case DCLAction_Trigger.BuildEditModeFocusSelectedEntities:
 0352                    InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0353                    break;
 354                case DCLAction_Trigger.BuildEditModeReset:
 0355                    InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0356                    break;
 357                case DCLAction_Trigger.BuildEditHideSelectedEntities:
 0358                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput);
 0359                    break;
 360                case DCLAction_Trigger.BuildEditShowAllEntities:
 0361                    InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0362                    break;
 363                case DCLAction_Trigger.BuildEditModeResetCamera:
 0364                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 0365                    break;
 366                case DCLAction_Trigger.BuildEditModeZoomIn:
 0367                    InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu
 0368                    break;
 369                case DCLAction_Trigger.BuildEditModeZoomOut:
 0370                    InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp
 0371                    break;
 372                case DCLAction_Trigger.ToggleQuestsPanelHud:
 5560373                    InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560374                    break;
 375                case DCLAction_Trigger.ToggleAvatarNamesHud:
 5560376                    InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput);
 5560377                    break;
 378                default:
 0379                    throw new ArgumentOutOfRangeException();
 380            }
 381        }
 5562382    }
 383
 384    /// <summary>
 385    /// Map the hold actions to inputs + modifiers and check if their events must be triggered
 386    /// </summary>
 387    private void Update_Hold(InputAction_Hold[] holdActions)
 388    {
 111200389        for (var i = 0; i < holdActions.Length; i++)
 390        {
 50040391            var action = holdActions[i];
 50040392            switch (action.GetDCLAction())
 393            {
 394                case DCLAction_Hold.Sprint:
 5560395                    InputProcessor.FromKey(action, InputSettings.WalkButtonKeyCode,
 396                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560397                    break;
 398                case DCLAction_Hold.Jump:
 5560399                    InputProcessor.FromKey(action, InputSettings.JumpButtonKeyCode,
 400                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560401                    break;
 402                case DCLAction_Hold.ZoomIn:
 5560403                    InputProcessor.FromKey(action, KeyCode.KeypadPlus, InputProcessor.Modifier.None);
 5560404                    InputProcessor.FromKey(action, KeyCode.Plus, InputProcessor.Modifier.None);
 5560405                    break;
 406                case DCLAction_Hold.ZoomOut:
 5560407                    InputProcessor.FromKey(action, KeyCode.KeypadMinus, InputProcessor.Modifier.None);
 5560408                    InputProcessor.FromKey(action, KeyCode.Minus, InputProcessor.Modifier.None);
 5560409                    break;
 410                case DCLAction_Hold.FreeCameraMode:
 411                    //Disable until the fine-tuning is ready
 5560412                    if (ENABLE_THIRD_PERSON_CAMERA)
 5560413                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 5560414                    break;
 415                case DCLAction_Hold.VoiceChatRecording:
 416                    // Push to talk functionality only triggers if no modifier key is pressed
 11120417                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 11120418                    break;
 419                case DCLAction_Hold.DefaultConfirmAction:
 5560420                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None);
 5560421                    break;
 422                case DCLAction_Hold.DefaultCancelAction:
 5560423                    InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None);
 5560424                    break;
 425                case DCLAction_Hold.BuildEditModeMultiSelection:
 0426                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0427                    break;
 428                case DCLAction_Hold.BuildEditModeSquareMultiSelection:
 0429                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0430                    break;
 431                case DCLAction_Hold.BuildEditModeFirstPersonRotation:
 0432                    InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput);
 0433                    break;
 434                case DCLAction_Hold.BuildEditModeCameraAdvanceFoward:
 0435                    InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput);
 0436                    InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput);
 0437                    break;
 438                case DCLAction_Hold.BuildEditModeCameraAdvanceBack:
 0439                    InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput);
 0440                    InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput);
 0441                    break;
 442                case DCLAction_Hold.BuildEditModeCameraAdvanceLeft:
 0443                    InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput);
 0444                    InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput);
 0445                    break;
 446                case DCLAction_Hold.BuildEditModeCameraAdvanceRight:
 0447                    InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput);
 0448                    InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput);
 0449                    break;
 450                case DCLAction_Hold.BuildEditModeCameraAdvanceUp:
 0451                    InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput);
 0452                    break;
 453                case DCLAction_Hold.BuildEditModeCameraAdvanceDown:
 0454                    InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput);
 0455                    break;
 456                case DCLAction_Hold.BuildEditModeCameraPan:
 0457                    InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput);
 0458                    break;
 459                default:
 0460                    throw new ArgumentOutOfRangeException();
 461            }
 462        }
 5560463    }
 464
 465    /// <summary>
 466    /// Map the measurable actions to inputs + modifiers and check if their events must be triggered
 467    /// </summary>
 468    private void Update_Measurable(InputAction_Measurable[] measurableActions)
 469    {
 66720470        for (var i = 0; i < measurableActions.Length; i++)
 471        {
 27800472            var action = measurableActions[i];
 27800473            switch (action.GetDCLAction())
 474            {
 475                case DCLAction_Measurable.CharacterXAxis:
 5560476                    InputProcessor.FromAxis(action, "Horizontal",
 477                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560478                    break;
 479                case DCLAction_Measurable.CharacterYAxis:
 5560480                    InputProcessor.FromAxis(action, "Vertical",
 481                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 5560482                    break;
 483                case DCLAction_Measurable.CameraXAxis:
 5560484                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 5560485                    break;
 486                case DCLAction_Measurable.CameraYAxis:
 5560487                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 5560488                    break;
 489                case DCLAction_Measurable.MouseWheel:
 5560490                    InputProcessor.FromAxis(action, "Mouse ScrollWheel", modifiers: InputProcessor.Modifier.FocusNotInIn
 5560491                    break;
 492                default:
 0493                    throw new ArgumentOutOfRangeException();
 494            }
 495        }
 5560496    }
 497
 498    private void Stop_Measurable(InputAction_Measurable[] measurableActions)
 499    {
 36500        for (var i = 0; i < measurableActions.Length; i++)
 501        {
 15502            measurableActions[i].RaiseOnValueChanged(0);
 503        }
 3504    }
 505}
 506
 507/// <summary>
 508/// Helper class that wraps the processing of inputs and modifiers to trigger actions events
 509/// </summary>
 510public static class InputProcessor
 511{
 512    private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K
 513
 514    [Flags]
 515    public enum Modifier
 516    {
 517        //Set the values as bit masks
 518        None = 0b0000000, // No modifier needed
 519        NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game
 520        FocusNotInInput = 0b0000010, // The game focus cannot be in an input field
 521        NotInStartMenu = 0b0000100 // The game focus cannot be in full-screen start menu
 522    }
 523
 524    /// <summary>
 525    /// Check if the modifier keys are pressed
 526    /// </summary>
 527    /// <param name="modifierKeys"> Keycodes modifiers</param>
 528    /// <returns></returns>
 529    public static Boolean PassModifierKeys(KeyCode[] modifierKeys)
 530    {
 531        for (var i = 0; i < MODIFIER_KEYS.Length; i++)
 532        {
 533            var keyCode = MODIFIER_KEYS[i];
 534            var pressed = Input.GetKey(keyCode);
 535            if (modifierKeys == null)
 536            {
 537                if (pressed)
 538                    return false;
 539            }
 540            else
 541            {
 542                if (modifierKeys.Contains(keyCode) != pressed)
 543                    return false;
 544            }
 545        }
 546
 547        return true;
 548    }
 549
 550    /// <summary>
 551    /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application
 552    /// they can be anything such as mouse pointer state, where the focus is, camera mode...
 553    /// </summary>
 554    /// <param name="modifiers"></param>
 555    /// <returns></returns>
 556    public static bool PassModifiers(Modifier modifiers)
 557    {
 558        if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.IsCursorLocked)
 559            return false;
 560
 561        if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField())
 562            return false;
 563
 564        if (IsModifierSet(modifiers, Modifier.NotInStartMenu) && IsStartMenuVisible())
 565            return false;
 566
 567        return true;
 568    }
 569
 570    private static bool IsStartMenuVisible() => DataStore.i.exploreV2.isOpen.Get();
 571
 572    /// <summary>
 573    /// Process an input action mapped to a keyboard key.
 574    /// </summary>
 575    /// <param name="action">Trigger Action to perform</param>
 576    /// <param name="key">KeyCode mapped to this action</param>
 577    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 578    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 579    public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null,
 580        Modifier modifiers = Modifier.None)
 581    {
 582        if (!PassModifiers(modifiers))
 583            return;
 584
 585        if (!PassModifierKeys(modifierKeys))
 586            return;
 587
 588        if (Input.GetKeyDown(key))
 589            action.RaiseOnTriggered();
 590    }
 591
 592    /// <summary>
 593    /// Process an input action mapped to a button.
 594    /// </summary>
 595    /// <param name="action">Trigger Action to perform</param>
 596    /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param>
 597    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 598    public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx,
 599        Modifier modifiers = Modifier.None)
 600    {
 601        if (!PassModifiers(modifiers))
 602            return;
 603
 604        if (Input.GetMouseButton(mouseButtonIdx))
 605            action.RaiseOnTriggered();
 606    }
 607
 608    public static void FromMouseButtonUp(InputAction_Trigger action, int mouseButtonIdx,
 609        Modifier modifiers = Modifier.None)
 610    {
 611        if (!PassModifiers(modifiers))
 612            return;
 613
 614        if (Input.GetMouseButtonUp(mouseButtonIdx))
 615            action.RaiseOnTriggered();
 616    }
 617
 618    /// <summary>
 619    /// Process an input action mapped to a keyboard key
 620    /// </summary>
 621    /// <param name="action">Hold Action to perform</param>
 622    /// <param name="key">KeyCode mapped to this action</param>
 623    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 624    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None)
 625    {
 626        if (!PassModifiers(modifiers))
 627            return;
 628
 629        if (Input.GetKeyDown(key))
 630            action.RaiseOnStarted();
 631        if (Input.GetKeyUp(key))
 632            action.RaiseOnFinished();
 633    }
 634
 635    /// <summary>
 636    /// Process an input action mapped to a keyboard key
 637    /// </summary>
 638    /// <param name="action">Hold Action to perform</param>
 639    /// <param name="key">KeyCode mapped to this action</param>
 640    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 641    /// <param name="modifierKeys">KeyCodes required to perform the action</param>
 642    public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys)
 643    {
 644        if (!PassModifierKeys(modifierKeys))
 645            return;
 646
 647        FromKey(action, key, modifiers);
 648    }
 649
 650    /// <summary>
 651    /// Process an input action mapped to a mouse button
 652    /// </summary>
 653    /// <param name="action">Hold Action to perform</param>
 654    /// <param name="mouseButtonIdx">Index of the mouse button</param>
 655    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 656    public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None)
 657    {
 658        if (!PassModifiers(modifiers))
 659            return;
 660
 661        if (Input.GetMouseButtonDown(mouseButtonIdx))
 662            action.RaiseOnStarted();
 663        if (Input.GetMouseButtonUp(mouseButtonIdx))
 664            action.RaiseOnFinished();
 665    }
 666
 667    /// <summary>
 668    /// Process an input action mapped to an axis
 669    /// </summary>
 670    /// <param name="action">Measurable Action to perform</param>
 671    /// <param name="axisName">Axis name</param>
 672    /// <param name="modifiers">Miscellaneous modifiers required for this action</param>
 673    public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None)
 674    {
 675        if (!PassModifiers(modifiers))
 676        {
 677            action.RaiseOnValueChanged(0);
 678            return;
 679        }
 680
 681        action.RaiseOnValueChanged(Input.GetAxis(axisName));
 682    }
 683
 684    /// <summary>
 685    /// Bitwise check for the modifiers flags
 686    /// </summary>
 687    /// <param name="modifiers">Modifier to check</param>
 688    /// <param name="value">Modifier mapped to a bit to check</param>
 689    /// <returns></returns>
 690    public static bool IsModifierSet(Modifier modifiers, Modifier value)
 691    {
 692        int flagsValue = (int)modifiers;
 693        int flagValue = (int)value;
 694
 695        return (flagsValue & flagValue) != 0;
 696    }
 697
 698    public static bool FocusIsInInputField()
 699    {
 700        if (EventSystem.current == null)
 701            return false;
 702
 703        if (EventSystem.current.currentSelectedGameObject != null &&
 704            (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null ||
 705             EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null))
 706        {
 707            return true;
 708        }
 709
 710        return false;
 711    }
 712}