< Summary

Class:InputController
Assembly:InputController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/InputController.cs
Covered lines:144
Uncovered lines:8
Coverable lines:152
Total lines:370
Line coverage:94.7% (144 of 152)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputController()0%110100%
Update()0%2.092071.43%
Update_Trigger(...)0%5555099%
Update_Hold(...)0%15.0115096.43%
Update_Measurable(...)0%10.0210094.12%
Stop_Measurable(...)0%6200%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System;
 3using UnityEngine;
 4using DCL.Configuration;
 5using System.Collections.Generic;
 6
 7/// <summary>
 8/// Mapping for Trigger actions
 9/// </summary>
 10public enum DCLAction_Trigger
 11{
 12    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 13    CameraChange = 100,
 14    CursorUnlock = 101,
 15
 16    ToggleNavMap = 110,
 17    ToggleFriends = 120,
 18    CloseWindow = 121,
 19    ToggleWorldChat = 122,
 20    ToggleUIVisibility = 123,
 21    ToggleControlsHud = 124,
 22    ToggleSettings = 125,
 23    ToggleStartMenu = 126,
 24    ToggleVoiceChatRecording = 127,
 25    ToggleAvatarEditorHud = 128,
 26    ToggleQuestsPanelHud = 129,
 27    ToggleAvatarNamesHud = 130,
 28    TogglePlacesAndEventsHud = 131,
 29    ToggleShortcut0 = 132,
 30    ToggleShortcut1 = 133,
 31    ToggleShortcut2 = 134,
 32    ToggleShortcut3 = 135,
 33    ToggleShortcut4 = 136,
 34    ToggleShortcut5 = 137,
 35    ToggleShortcut6 = 138,
 36    ToggleShortcut7 = 139,
 37    ToggleShortcut8 = 140,
 38    ToggleShortcut9 = 141,
 39    ToggleEmoteShortcut0 = 142,
 40    ToggleEmoteShortcut1 = 143,
 41    ToggleEmoteShortcut2 = 144,
 42    ToggleEmoteShortcut3 = 145,
 43    ToggleEmoteShortcut4 = 146,
 44    ToggleEmoteShortcut5 = 147,
 45    ToggleEmoteShortcut6 = 148,
 46    ToggleEmoteShortcut7 = 149,
 47    ToggleEmoteShortcut8 = 150,
 48    ToggleEmoteShortcut9 = 151,
 49    ChatPreviousInHistory = 152,
 50    ChatNextInHistory = 153,
 51
 52    Expression_Wave = 201,
 53    Expression_FistPump = 202,
 54    Expression_Robot = 203,
 55    Expression_RaiseHand = 204,
 56    Expression_Clap = 205,
 57    Expression_ThrowMoney = 206,
 58    Expression_SendKiss = 207,
 59    Expression_Dance = 208,
 60    Expression_Hohoho = 209,
 61    Expression_Snowfall = 210,
 62}
 63
 64/// <summary>
 65/// Mapping for hold actions
 66/// </summary>
 67public enum DCLAction_Hold
 68{
 69    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 70    Sprint = 1,
 71    Jump = 2,
 72    ZoomIn = 3,
 73    ZoomOut = 4,
 74    FreeCameraMode = 101,
 75    VoiceChatRecording = 102,
 76    DefaultConfirmAction = 300,
 77    DefaultCancelAction = 301,
 78    OpenExpressions = 447
 79}
 80
 81/// <summary>
 82/// Mapping for measurable actions
 83/// </summary>
 84public enum DCLAction_Measurable
 85{
 86    //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts
 87    CharacterXAxis = 1,
 88    CharacterYAxis = 2,
 89    CameraXAxis = 3,
 90    CameraYAxis = 4,
 91    MouseWheel = 5
 92}
 93
 94/// <summary>
 95/// Input Controller will map inputs(keys/mouse/axis) to DCL actions, check if they can be triggered (modifiers) and rai
 96/// </summary>
 97public class InputController : MonoBehaviour
 98{
 199    public static bool ENABLE_THIRD_PERSON_CAMERA = true;
 100
 101    [Header("General Input")]
 102    public InputAction_Trigger[] triggerTimeActions;
 103    public InputAction_Hold[] holdActions;
 104    public InputAction_Measurable[] measurableActions;
 105
 14965106    bool renderingEnabled => CommonScriptableObjects.rendererState.Get();
 44895107    bool allUIHidden => CommonScriptableObjects.allUIHidden.Get();
 108
 109    private void Update()
 110    {
 14965111        if (!renderingEnabled)
 112        {
 0113            Stop_Measurable(measurableActions);
 0114            return;
 115        }
 116
 14965117        Update_Trigger(triggerTimeActions);
 14965118        Update_Hold(holdActions);
 14965119        Update_Measurable(measurableActions);
 14965120    }
 121
 122    /// <summary>
 123    /// Map the trigger actions to inputs + modifiers and check if their events must be triggered
 124    /// </summary>
 125    private void Update_Trigger(InputAction_Trigger[] triggerTimeActions)
 126    {
 1346850127        foreach (var action in triggerTimeActions)
 128        {
 658460129            if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get())
 130                continue;
 131
 658460132            switch (action.DCLAction)
 133            {
 134                case DCLAction_Trigger.CameraChange:
 135                    // Disable until the fine-tuning is ready
 14965136                    if (!CommonScriptableObjects.cameraModeInputLocked.Get() && ENABLE_THIRD_PERSON_CAMERA)
 14965137                        InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965138                    break;
 139                case DCLAction_Trigger.CursorUnlock:
 14965140                    InputProcessor.FromMouseButtonUp(action, mouseButtonIdx: 1, modifiers: InputProcessor.Modifier.Needs
 141#if !WEB_PLATFORM
 14965142                    InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.NeedsPointerLocked
 143#endif
 14965144                    break;
 145                case DCLAction_Trigger.ToggleNavMap:
 14965146                    InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965147                    break;
 148                case DCLAction_Trigger.ToggleFriends:
 14965149                    if (!allUIHidden)
 14965150                        InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None);
 14965151                    break;
 152                case DCLAction_Trigger.ToggleWorldChat:
 14965153                    if (!allUIHidden)
 14965154                        InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.FocusNotInInpu
 14965155                    break;
 156                case DCLAction_Trigger.ToggleUIVisibility:
 14965157                    InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None);
 14965158                    break;
 159                case DCLAction_Trigger.CloseWindow:
 14965160                    if (!allUIHidden && !DataStore.i.common.isSignUpFlow.Get())
 14965161                        InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None);
 14965162                    break;
 163                case DCLAction_Trigger.ToggleControlsHud:
 14965164                    InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965165                    break;
 166                case DCLAction_Trigger.ToggleSettings:
 14965167                    InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965168                    break;
 169                case DCLAction_Trigger.ToggleStartMenu:
 14965170                    InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.None);
 14965171                    break;
 172                case DCLAction_Trigger.TogglePlacesAndEventsHud:
 14965173                    InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965174                    break;
 175                case DCLAction_Trigger.ToggleShortcut0:
 14965176                    InputProcessor.FromKey(action, KeyCode.Alpha0, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965177                    break;
 178                case DCLAction_Trigger.ToggleShortcut1:
 14965179                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965180                    break;
 181                case DCLAction_Trigger.ToggleShortcut2:
 14965182                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965183                    break;
 184                case DCLAction_Trigger.ToggleShortcut3:
 14965185                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965186                    break;
 187                case DCLAction_Trigger.ToggleShortcut4:
 14965188                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965189                    break;
 190                case DCLAction_Trigger.ToggleShortcut5:
 14965191                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965192                    break;
 193                case DCLAction_Trigger.ToggleShortcut6:
 14965194                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965195                    break;
 196                case DCLAction_Trigger.ToggleShortcut7:
 14965197                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965198                    break;
 199                case DCLAction_Trigger.ToggleShortcut8:
 14965200                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965201                    break;
 202                case DCLAction_Trigger.ToggleShortcut9:
 14965203                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965204                    break;
 205                case DCLAction_Trigger.ToggleEmoteShortcut0:
 14965206                    InputProcessor.FromKey(action, KeyCode.Alpha0, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965207                    break;
 208                case DCLAction_Trigger.ToggleEmoteShortcut1:
 14965209                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965210                    break;
 211                case DCLAction_Trigger.ToggleEmoteShortcut2:
 14965212                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965213                    break;
 214                case DCLAction_Trigger.ToggleEmoteShortcut3:
 14965215                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965216                    break;
 217                case DCLAction_Trigger.ToggleEmoteShortcut4:
 14965218                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965219                    break;
 220                case DCLAction_Trigger.ToggleEmoteShortcut5:
 14965221                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965222                    break;
 223                case DCLAction_Trigger.ToggleEmoteShortcut6:
 14965224                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965225                    break;
 226                case DCLAction_Trigger.ToggleEmoteShortcut7:
 14965227                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965228                    break;
 229                case DCLAction_Trigger.ToggleEmoteShortcut8:
 14965230                    InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965231                    break;
 232                case DCLAction_Trigger.ToggleEmoteShortcut9:
 14965233                    InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput, m
 14965234                    break;
 235                case DCLAction_Trigger.ChatNextInHistory:
 14965236                    InputProcessor.FromKey(action, KeyCode.UpArrow, modifiers: InputProcessor.Modifier.OnlyWithInputFocu
 14965237                    break;
 238                case DCLAction_Trigger.ChatPreviousInHistory:
 14965239                    InputProcessor.FromKey(action, KeyCode.DownArrow, modifiers: InputProcessor.Modifier.OnlyWithInputFo
 14965240                    break;
 241                case DCLAction_Trigger.Expression_Wave:
 14965242                    InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965243                    break;
 244                case DCLAction_Trigger.Expression_FistPump:
 14965245                    InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965246                    break;
 247                case DCLAction_Trigger.Expression_Robot:
 14965248                    InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965249                    break;
 250                case DCLAction_Trigger.Expression_RaiseHand:
 14965251                    InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965252                    break;
 253                case DCLAction_Trigger.Expression_Clap:
 14965254                    InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965255                    break;
 256                case DCLAction_Trigger.Expression_ThrowMoney:
 14965257                    InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965258                    break;
 259                case DCLAction_Trigger.Expression_SendKiss:
 14965260                    InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput | 
 14965261                    break;
 262                case DCLAction_Trigger.ToggleVoiceChatRecording:
 14965263                    InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi
 14965264                    break;
 265                case DCLAction_Trigger.ToggleAvatarEditorHud:
 14965266                    InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965267                    break;
 268                case DCLAction_Trigger.ToggleQuestsPanelHud:
 14965269                    InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965270                    break;
 271                case DCLAction_Trigger.ToggleAvatarNamesHud:
 14965272                    InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput);
 14965273                    break;
 274                default:
 0275                    throw new ArgumentOutOfRangeException();
 276            }
 277        }
 14965278    }
 279
 280    /// <summary>
 281    /// Map the hold actions to inputs + modifiers and check if their events must be triggered
 282    /// </summary>
 283    private void Update_Hold(InputAction_Hold[] holdActions)
 284    {
 329230285        foreach (var action in holdActions)
 286        {
 149650287            if (action.isHoldBlocked != null && action.isHoldBlocked.Get())
 288                continue;
 289
 149650290            switch (action.DCLAction)
 291            {
 292                case DCLAction_Hold.Sprint:
 14965293                    InputProcessor.FromKey(action, InputSettings.WalkButtonKeyCode,
 294                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 14965295                    break;
 296                case DCLAction_Hold.Jump:
 14965297                    InputProcessor.FromKey(action, InputSettings.JumpButtonKeyCode,
 298                        InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu);
 14965299                    break;
 300                case DCLAction_Hold.ZoomIn:
 14965301                    InputProcessor.FromKey(action, KeyCode.KeypadPlus);
 14965302                    InputProcessor.FromKey(action, KeyCode.Plus);
 14965303                    break;
 304                case DCLAction_Hold.ZoomOut:
 14965305                    InputProcessor.FromKey(action, KeyCode.KeypadMinus);
 14965306                    InputProcessor.FromKey(action, KeyCode.Minus);
 14965307                    break;
 308                case DCLAction_Hold.FreeCameraMode:
 309                    // Disable until the fine-tuning is ready
 14965310                    if (ENABLE_THIRD_PERSON_CAMERA)
 14965311                        InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked);
 14965312                    break;
 313                case DCLAction_Hold.VoiceChatRecording:
 314                    // Push to talk functionality only triggers if no modifier key is pressed
 29930315                    InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null);
 29930316                    break;
 317                case DCLAction_Hold.DefaultConfirmAction:
 14965318                    InputProcessor.FromKey(action, KeyCode.E);
 14965319                    break;
 320                case DCLAction_Hold.DefaultCancelAction:
 14965321                    InputProcessor.FromKey(action, KeyCode.F);
 14965322                    break;
 323                case DCLAction_Hold.OpenExpressions:
 14965324                    InputProcessor.FromKey(action, KeyCode.B, InputProcessor.Modifier.FocusNotInInput);
 14965325                    break;
 326                default:
 0327                    throw new ArgumentOutOfRangeException();
 328            }
 329        }
 14965330    }
 331
 332    /// <summary>
 333    /// Map the measurable actions to inputs + modifiers and check if their events must be triggered
 334    /// </summary>
 335    private void Update_Measurable(InputAction_Measurable[] measurableActions)
 336    {
 179580337        foreach (var action in measurableActions)
 338        {
 74825339            if (action.isMeasurableBlocked != null && action.isMeasurableBlocked.Get())
 340                continue;
 341
 74825342            switch (action.DCLAction)
 343            {
 344                case DCLAction_Measurable.CharacterXAxis:
 14965345                    InputProcessor.FromAxis(action, "Horizontal", InputProcessor.Modifier.FocusNotInInput | InputProcess
 14965346                    break;
 347                case DCLAction_Measurable.CharacterYAxis:
 14965348                    InputProcessor.FromAxis(action, "Vertical", InputProcessor.Modifier.FocusNotInInput | InputProcessor
 14965349                    break;
 350                case DCLAction_Measurable.CameraXAxis:
 14965351                    InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked);
 14965352                    break;
 353                case DCLAction_Measurable.CameraYAxis:
 14965354                    InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked);
 14965355                    break;
 356                case DCLAction_Measurable.MouseWheel:
 14965357                    InputProcessor.FromAxis(action, "Mouse ScrollWheel", modifiers: InputProcessor.Modifier.FocusNotInIn
 14965358                    break;
 359                default:
 0360                    throw new ArgumentOutOfRangeException();
 361            }
 362        }
 14965363    }
 364
 365    private static void Stop_Measurable(InputAction_Measurable[] measurableActions)
 366    {
 0367        foreach (var action in measurableActions)
 0368            action.RaiseOnValueChanged(0);
 0369    }
 370}