public static void SetCurrentControlState(Controls control, ControlStateMetadata metaData) { var overwriteResult = new KeyValuePair <Controls, ControlStateMetadata>(control, metaData); CurrentControlState[control] = metaData; }
public static ControlStateMetadata SeedMetadataBasedOnPreviousState(Controls control, ControlStateMetadata previousControlState, bool isPressed) { ControlStates currentState = ControlStates.Released; int previousInputTimer = previousControlState.inputTimer; int previousHeldTimer = previousControlState.heldTimer; int previousDoubleInputCooldown = previousControlState.doubleInputCooldown; int doubleInputCooldown = Math.Max(previousDoubleInputCooldown - 1, 0); int inputTimer = 0; int heldTimer = 0; if (isPressed) { switch (previousControlState.state) { case ControlStates.Released: currentState = ControlStates.PressedOnce; break; case ControlStates.PressedTwice: // prevents you from chaining dashes on third/subsequent presses currentState = ControlStates.Released; break; case ControlStates.PressedOnce: case ControlStates.PressedAndHeld: currentState = ControlStates.PressedAndHeld; break; case ControlStates.PressedAndReleased: if (previousInputTimer <= GetInputTimeLimit(control) && doubleInputCooldown == 0) { if (control != Controls.LightAttack) { doubleInputCooldown = DOUBLE_INPUT_COOLDOWN; } currentState = ControlStates.PressedTwice; } else { currentState = ControlStates.PressedOnce; } break; } } else { switch (previousControlState.state) { case ControlStates.Released: case ControlStates.PressedTwice: break; case ControlStates.PressedOnce: case ControlStates.PressedAndReleased: case ControlStates.PressedAndHeld: if (previousInputTimer <= GetInputTimeLimit(control)) { // light attack must be held for flurries. if (control == Controls.LightAttack) { inputTimer = 0; } if (previousControlState.state == ControlStates.PressedAndHeld && previousHeldTimer <= GetHeldTimeLimit(control)) { currentState = ControlStates.PressedAndReleased; } else { if ((previousControlState.state == ControlStates.PressedOnce || previousControlState.state == ControlStates.PressedAndReleased) && previousInputTimer <= GetInputTimeLimit(control)) { currentState = ControlStates.PressedAndReleased; } else { currentState = ControlStates.Released; } } } else { inputTimer = 0; currentState = ControlStates.Released; } break; } } // if we're in a combo or held state, the input timer gets incremented. if (currentState == ControlStates.PressedOnce || currentState == ControlStates.PressedAndHeld || currentState == ControlStates.PressedAndReleased) { inputTimer = previousInputTimer + 1; if (currentState == ControlStates.PressedAndHeld) { heldTimer = previousHeldTimer + 1; } else { heldTimer = 0; } } else { inputTimer = 0; } var result = new ControlStateMetadata(currentState, inputTimer, heldTimer, doubleInputCooldown); return(result); }