diff --git a/CHANGELOG.md b/CHANGELOG.md index 5394dd7..be61a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Jump to version: Additions - Added TokenizedString.Realign - Added GetFlags and GetUniqueFlags to EnumHelper +- Added GetDownTime, GetUpTime and GetTimeSincePress to Keybind and Combination - **Added the ability to find paths to one of multiple goals using AStar** Improvements diff --git a/MLEM/Input/Keybind.cs b/MLEM/Input/Keybind.cs index 78ad1b4..ee501f2 100644 --- a/MLEM/Input/Keybind.cs +++ b/MLEM/Input/Keybind.cs @@ -183,6 +183,39 @@ namespace MLEM.Input { return false; } + /// + /// Returns the amount of time that this keybind has been held down for. + /// If this input isn't currently down, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting down time, or if the input is not being held. + public TimeSpan GetDownTime(InputHandler handler, int gamepadIndex = -1) { + return this.combinations.Max(c => c.GetDownTime(handler, gamepadIndex)); + } + + /// + /// Returns the amount of time that this keybind has been up for since the last time it was down. + /// If this input isn't currently up, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting up time, or if the input is being held. + public TimeSpan GetUpTime(InputHandler handler, int gamepadIndex = -1) { + return this.combinations.Min(c => c.GetUpTime(handler, gamepadIndex)); + } + + /// + /// Returns the amount of time that has passed since this keybind last counted as pressed. + /// If this input hasn't been pressed previously, or is currently pressed, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting up time, or if the input has never been pressed, or is currently pressed. + public TimeSpan GetTimeSincePress(InputHandler handler, int gamepadIndex = -1) { + return this.combinations.Min(c => c.GetTimeSincePress(handler, gamepadIndex)); + } + /// /// Returns an enumerable of all of the combinations that this keybind currently contains /// @@ -347,6 +380,39 @@ namespace MLEM.Input { return false; } + /// + /// Returns the amount of time that this combination has been held down for. + /// If this input isn't currently down, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting down time, or if the input is not being held. + public TimeSpan GetDownTime(InputHandler handler, int gamepadIndex = -1) { + return handler.GetDownTime(this.Key, gamepadIndex); + } + + /// + /// Returns the amount of time that this combination has been up for since the last time it was down. + /// If this input isn't currently up, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting up time, or if the input is being held. + public TimeSpan GetUpTime(InputHandler handler, int gamepadIndex = -1) { + return handler.GetUpTime(this.Key, gamepadIndex); + } + + /// + /// Returns the amount of time that has passed since this combination last counted as pressed. + /// If this input hasn't been pressed previously, or is currently pressed, this method returns . + /// + /// The input handler to query the keys with + /// The index of the gamepad to query, or -1 to query all gamepads + /// The resulting up time, or if the input has never been pressed, or is currently pressed. + public TimeSpan GetTimeSincePress(InputHandler handler, int gamepadIndex = -1) { + return handler.GetTimeSincePress(this.Key, gamepadIndex); + } + /// /// Converts this combination into an easily human-readable string. /// When using , this method is used with set to " + ".