From 71d9f8f4fea7d6682e03535af004dcd39988d7e2 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 18 Mar 2022 11:58:10 -0700 Subject: [PATCH] remove unnecessary setters and add doc comments --- src/Input/Axis.cs | 3 ++ src/Input/Button.cs | 15 ++++++++++ src/Input/Gamepad.cs | 68 ++++++++++++++++++++++++++++++-------------- src/Input/Trigger.cs | 3 ++ 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/Input/Axis.cs b/src/Input/Axis.cs index 4fed2b9..acef4a0 100644 --- a/src/Input/Axis.cs +++ b/src/Input/Axis.cs @@ -2,6 +2,9 @@ namespace MoonWorks.Input { public class Axis { + /// + /// An axis value between -1 and 1. + /// public float Value { get; private set; } internal void Update(float value) diff --git a/src/Input/Button.cs b/src/Input/Button.cs index 615d8a3..7826d07 100644 --- a/src/Input/Button.cs +++ b/src/Input/Button.cs @@ -4,9 +4,24 @@ namespace MoonWorks.Input { public ButtonState State { get; private set; } + /// + /// True if the button is pressed or held. + /// public bool IsDown => State.IsDown; + + /// + /// True if the button has been continuously held for more than one frame. + /// public bool IsHeld => State.IsHeld; + + /// + /// True if the button was pressed this exact frame. + /// public bool IsPressed => State.IsPressed; + + /// + /// True if the button is not pressed. + /// public bool IsReleased => State.IsReleased; internal void Update(bool isPressed) diff --git a/src/Input/Gamepad.cs b/src/Input/Gamepad.cs index f0cb554..59dc036 100644 --- a/src/Input/Gamepad.cs +++ b/src/Input/Gamepad.cs @@ -9,29 +9,29 @@ namespace MoonWorks.Input { internal IntPtr Handle; - public Button A { get; private set; } = new Button(); - public Button B { get; private set; } = new Button(); - public Button X { get; private set; } = new Button(); - public Button Y { get; private set; } = new Button(); - public Button Back { get; private set; } = new Button(); - public Button Guide { get; private set; } = new Button(); - public Button Start { get; private set; } = new Button(); - public Button LeftStick { get; private set; } = new Button(); - public Button RightStick { get; private set; } = new Button(); - public Button LeftShoulder { get; private set; } = new Button(); - public Button RightShoulder { get; private set; } = new Button(); - public Button DpadUp { get; private set; } = new Button(); - public Button DpadDown { get; private set; } = new Button(); - public Button DpadLeft { get; private set; } = new Button(); - public Button DpadRight { get; private set; } = new Button(); + public Button A { get; } = new Button(); + public Button B { get; } = new Button(); + public Button X { get; } = new Button(); + public Button Y { get; } = new Button(); + public Button Back { get; } = new Button(); + public Button Guide { get; } = new Button(); + public Button Start { get; } = new Button(); + public Button LeftStick { get; } = new Button(); + public Button RightStick { get; } = new Button(); + public Button LeftShoulder { get; } = new Button(); + public Button RightShoulder { get; } = new Button(); + public Button DpadUp { get; } = new Button(); + public Button DpadDown { get; } = new Button(); + public Button DpadLeft { get; } = new Button(); + public Button DpadRight { get; } = new Button(); - public Axis LeftX { get; private set; } - public Axis LeftY { get; private set; } - public Axis RightX { get; private set; } - public Axis RightY { get; private set; } + public Axis LeftX { get; } = new Axis(); + public Axis LeftY { get; } = new Axis(); + public Axis RightX { get; } = new Axis(); + public Axis RightY { get; } = new Axis(); - public Trigger TriggerLeft { get; private set; } - public Trigger TriggerRight { get; private set; } + public Trigger TriggerLeft { get; } = new Trigger(); + public Trigger TriggerRight { get; } = new Trigger(); private Dictionary EnumToButton; private Dictionary EnumToAxis; @@ -97,6 +97,9 @@ namespace MoonWorks.Input } } + /// + /// Sets vibration values on the left and right motors. + /// public bool SetVibration(float leftMotor, float rightMotor, uint durationInMilliseconds) { return SDL.SDL_GameControllerRumble( @@ -107,36 +110,59 @@ namespace MoonWorks.Input ) == 0; } + /// + /// True if the button is pressed or held. + /// public bool IsDown(ButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode].IsDown; } + /// + /// True if the button was pressed this exact frame. + /// public bool IsPressed(ButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode].IsPressed; } + /// + /// True if the button has been continuously held for more than one frame. + /// public bool IsHeld(ButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode].IsHeld; } + /// + /// True if the button is not pressed. + /// public bool IsReleased(ButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode].IsReleased; } + /// + /// Obtains the button state given a ButtonCode. + /// public ButtonState ButtonState(ButtonCode buttonCode) { return EnumToButton[(SDL.SDL_GameControllerButton) buttonCode].State; } + /// + /// Obtains the axis value given an AxisCode. + /// + /// A value between -1 and 1. public float AxisValue(AxisCode axisCode) { return EnumToAxis[(SDL.SDL_GameControllerAxis) axisCode].Value; } + /// + /// Obtains the trigger value given an TriggerCode. + /// + /// A value between 0 and 1. public float TriggerValue(TriggerCode triggerCode) { return EnumToTrigger[(SDL.SDL_GameControllerAxis) triggerCode].Value; diff --git a/src/Input/Trigger.cs b/src/Input/Trigger.cs index 19a2b29..58b151d 100644 --- a/src/Input/Trigger.cs +++ b/src/Input/Trigger.cs @@ -2,6 +2,9 @@ namespace MoonWorks.Input { public class Trigger { + /// + /// A trigger value between 0 and 1. + /// public float Value { get; private set; } internal void Update(float value)