From f57feb7319725513fadde8b14d55f4e8e4b82c24 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 4 Sep 2020 20:56:27 -0400 Subject: extend game's input logic instead of replacing it --- src/SMAPI/Framework/Input/GamePadStateBuilder.cs | 31 +++++++++--------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/SMAPI/Framework/Input/GamePadStateBuilder.cs') diff --git a/src/SMAPI/Framework/Input/GamePadStateBuilder.cs b/src/SMAPI/Framework/Input/GamePadStateBuilder.cs index 2657fd12..f5f2d916 100644 --- a/src/SMAPI/Framework/Input/GamePadStateBuilder.cs +++ b/src/SMAPI/Framework/Input/GamePadStateBuilder.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.Input private GamePadState? State; /// The current button states. - private IDictionary ButtonStates; + private readonly IDictionary ButtonStates; /// The left trigger value. private float LeftTrigger; @@ -39,33 +39,26 @@ namespace StardewModdingAPI.Framework.Input ** Accessors *********/ /// Whether the gamepad is currently connected. - public bool IsConnected { get; private set; } + public bool IsConnected { get; } /********* ** Public methods *********/ /// Construct an instance. - /// The initial state, or null to get the latest state. - public GamePadStateBuilder(GamePadState? state = null) + /// The initial state. + public GamePadStateBuilder(GamePadState state) { - this.Reset(state); - } - - /// Reset the tracked state. - /// The state from which to reset, or null to get the latest state. - public GamePadStateBuilder Reset(GamePadState? state = null) - { - this.State = state ??= GamePad.GetState(PlayerIndex.One); - this.IsConnected = state.Value.IsConnected; + this.State = state; + this.IsConnected = state.IsConnected; if (!this.IsConnected) - return this; + return; - GamePadDPad pad = state.Value.DPad; - GamePadButtons buttons = state.Value.Buttons; - GamePadTriggers triggers = state.Value.Triggers; - GamePadThumbSticks sticks = state.Value.ThumbSticks; + GamePadDPad pad = state.DPad; + GamePadButtons buttons = state.Buttons; + GamePadTriggers triggers = state.Triggers; + GamePadThumbSticks sticks = state.ThumbSticks; this.ButtonStates = new Dictionary { [SButton.DPadUp] = pad.Up, @@ -89,8 +82,6 @@ namespace StardewModdingAPI.Framework.Input this.RightTrigger = triggers.Right; this.LeftStickPos = sticks.Left; this.RightStickPos = sticks.Right; - - return this; } /// Override the states for a set of buttons. -- cgit