diff --git a/src/SMAPI/Framework/Input/SInputState.cs b/src/SMAPI/Framework/Input/SInputState.cs index f54d3124..4eaa9ca6 100644 --- a/src/SMAPI/Framework/Input/SInputState.cs +++ b/src/SMAPI/Framework/Input/SInputState.cs @@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework.Input public ICursorPosition CursorPosition => this.CursorPositionImpl; /// The buttons which were pressed, held, or released. - public IDictionary ActiveButtons { get; private set; } = new Dictionary(); + public IDictionary ActiveButtons { get; private set; } = new Dictionary(); /// The buttons to suppress when the game next handles input. Each button is suppressed until it's released. public HashSet SuppressButtons { get; } = new HashSet(); @@ -75,7 +75,7 @@ namespace StardewModdingAPI.Framework.Input [Obsolete("This method should only be called by the game itself.")] public override void Update() { } - /// Update the current button statuses for the given tick. + /// Update the current button states for the given tick. public void TrueUpdate() { try @@ -86,7 +86,7 @@ namespace StardewModdingAPI.Framework.Input GamePadState realController = GamePad.GetState(PlayerIndex.One); KeyboardState realKeyboard = Keyboard.GetState(); MouseState realMouse = Mouse.GetState(); - var activeButtons = this.DeriveStatuses(this.ActiveButtons, realKeyboard, realMouse, realController); + var activeButtons = this.DeriveStates(this.ActiveButtons, realKeyboard, realMouse, realController); Vector2 cursorAbsolutePos = new Vector2((realMouse.X * zoomMultiplier) + Game1.viewport.X, (realMouse.Y * zoomMultiplier) + Game1.viewport.Y); Vector2? playerTilePos = Context.IsPlayerFree ? Game1.player.getTileLocation() : (Vector2?)null; @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Framework.Input } // update suppressed states - this.SuppressButtons.RemoveWhere(p => !this.GetStatus(activeButtons, p).IsDown()); + this.SuppressButtons.RemoveWhere(p => !this.GetState(activeButtons, p).IsDown()); this.UpdateSuppression(); } catch (InvalidOperationException) @@ -159,7 +159,7 @@ namespace StardewModdingAPI.Framework.Input /// The button to check. public bool IsDown(SButton button) { - return this.GetStatus(this.ActiveButtons, button).IsDown(); + return this.GetState(this.ActiveButtons, button).IsDown(); } /// Get whether any of the given buttons were pressed or held. @@ -169,11 +169,11 @@ namespace StardewModdingAPI.Framework.Input return buttons.Any(button => this.IsDown(button.ToSButton())); } - /// Get the status of a button. + /// Get the state of a button. /// The button to check. - public InputStatus GetStatus(SButton button) + public SButtonState GetState(SButton button) { - return this.GetStatus(this.ActiveButtons, button); + return this.GetState(this.ActiveButtons, button); } @@ -205,7 +205,7 @@ namespace StardewModdingAPI.Framework.Input /// The game's keyboard state for the current tick. /// The game's mouse state for the current tick. /// The game's controller state for the current tick. - private void SuppressGivenStates(IDictionary activeButtons, ref KeyboardState keyboardState, ref MouseState mouseState, ref GamePadState gamePadState) + private void SuppressGivenStates(IDictionary activeButtons, ref KeyboardState keyboardState, ref MouseState mouseState, ref GamePadState gamePadState) { if (this.SuppressButtons.Count == 0) return; @@ -252,48 +252,48 @@ namespace StardewModdingAPI.Framework.Input } } - /// Get the status of all pressed or released buttons relative to their previous status. - /// The previous button statuses. + /// Get the state of all pressed or released buttons relative to their previous state. + /// The previous button states. /// The keyboard state. /// The mouse state. /// The controller state. - private IDictionary DeriveStatuses(IDictionary previousStatuses, KeyboardState keyboard, MouseState mouse, GamePadState controller) + private IDictionary DeriveStates(IDictionary previousStates, KeyboardState keyboard, MouseState mouse, GamePadState controller) { - IDictionary activeButtons = new Dictionary(); + IDictionary activeButtons = new Dictionary(); // handle pressed keys SButton[] down = this.GetPressedButtons(keyboard, mouse, controller).ToArray(); foreach (SButton button in down) - activeButtons[button] = this.DeriveStatus(this.GetStatus(previousStatuses, button), isDown: true); + activeButtons[button] = this.DeriveState(this.GetState(previousStates, button), isDown: true); // handle released keys - foreach (KeyValuePair prev in previousStatuses) + foreach (KeyValuePair prev in previousStates) { if (prev.Value.IsDown() && !activeButtons.ContainsKey(prev.Key)) - activeButtons[prev.Key] = InputStatus.Released; + activeButtons[prev.Key] = SButtonState.Released; } return activeButtons; } - /// Get the status of a button relative to its previous status. - /// The previous button status. + /// Get the state of a button relative to its previous state. + /// The previous button state. /// Whether the button is currently down. - private InputStatus DeriveStatus(InputStatus oldStatus, bool isDown) + private SButtonState DeriveState(SButtonState oldState, bool isDown) { - if (isDown && oldStatus.IsDown()) - return InputStatus.Held; + if (isDown && oldState.IsDown()) + return SButtonState.Held; if (isDown) - return InputStatus.Pressed; - return InputStatus.Released; + return SButtonState.Pressed; + return SButtonState.Released; } - /// Get the status of a button. + /// Get the state of a button. /// The current button states to check. /// The button to check. - private InputStatus GetStatus(IDictionary activeButtons, SButton button) + private SButtonState GetState(IDictionary activeButtons, SButton button) { - return activeButtons.TryGetValue(button, out InputStatus status) ? status : InputStatus.None; + return activeButtons.TryGetValue(button, out SButtonState state) ? state : SButtonState.None; } /// Get the buttons pressed in the given stats. diff --git a/src/SMAPI/Framework/ModHelpers/InputHelper.cs b/src/SMAPI/Framework/ModHelpers/InputHelper.cs index 5858cddd..f8ff0355 100644 --- a/src/SMAPI/Framework/ModHelpers/InputHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/InputHelper.cs @@ -51,11 +51,11 @@ namespace StardewModdingAPI.Framework.ModHelpers this.InputState.SuppressButtons.Add(button); } - /// Get the status of a button. + /// Get the state of a button. /// The button to check. - public InputStatus GetStatus(SButton button) + public SButtonState GetState(SButton button) { - return this.InputState.GetStatus(button); + return this.InputState.GetState(button); } } } diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 4b346059..6a472e3c 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -635,16 +635,16 @@ namespace StardewModdingAPI.Framework foreach (var pair in inputState.ActiveButtons) { SButton button = pair.Key; - InputStatus status = pair.Value; + SButtonState status = pair.Value; - if (status == InputStatus.Pressed) + if (status == SButtonState.Pressed) { if (this.Monitor.IsVerbose) this.Monitor.Log($"Events: button {button} pressed.", LogLevel.Trace); events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState)); } - else if (status == InputStatus.Released) + else if (status == SButtonState.Released) { if (this.Monitor.IsVerbose) this.Monitor.Log($"Events: button {button} released.", LogLevel.Trace); diff --git a/src/SMAPI/IInputHelper.cs b/src/SMAPI/IInputHelper.cs index ba26773d..e9768c24 100644 --- a/src/SMAPI/IInputHelper.cs +++ b/src/SMAPI/IInputHelper.cs @@ -18,8 +18,8 @@ namespace StardewModdingAPI /// The button to suppress. void Suppress(SButton button); - /// Get the status of a button. + /// Get the state of a button. /// The button to check. - InputStatus GetStatus(SButton button); + SButtonState GetState(SButton button); } } diff --git a/src/SMAPI/InputStatus.cs b/src/SMAPI/SButtonState.cs similarity index 59% rename from src/SMAPI/InputStatus.cs rename to src/SMAPI/SButtonState.cs index d9cdd6b2..2b78da27 100644 --- a/src/SMAPI/InputStatus.cs +++ b/src/SMAPI/SButtonState.cs @@ -1,7 +1,7 @@ namespace StardewModdingAPI { - /// The input status for a button during an update frame. - public enum InputStatus + /// The input state for a button during an update frame. + public enum SButtonState { /// The button was neither pressed, held, nor released. None, @@ -16,14 +16,14 @@ namespace StardewModdingAPI Released } - /// Extension methods for . + /// Extension methods for . internal static class InputStatusExtensions { /// Whether the button was pressed or held. - /// The button status. - public static bool IsDown(this InputStatus status) + /// The button state. + public static bool IsDown(this SButtonState state) { - return status == InputStatus.Held || status == InputStatus.Pressed; + return state == SButtonState.Held || state == SButtonState.Pressed; } } }