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/MouseStateBuilder.cs | 39 ++++++++++---------------- 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'src/SMAPI/Framework/Input/MouseStateBuilder.cs') diff --git a/src/SMAPI/Framework/Input/MouseStateBuilder.cs b/src/SMAPI/Framework/Input/MouseStateBuilder.cs index 1cc16ca9..a1ac5492 100644 --- a/src/SMAPI/Framework/Input/MouseStateBuilder.cs +++ b/src/SMAPI/Framework/Input/MouseStateBuilder.cs @@ -13,51 +13,42 @@ namespace StardewModdingAPI.Framework.Input private MouseState? State; /// The current button states. - private IDictionary ButtonStates; + private readonly IDictionary ButtonStates; /// The mouse wheel scroll value. - private int ScrollWheelValue; + private readonly int ScrollWheelValue; /********* ** Accessors *********/ /// The X cursor position. - public int X { get; private set; } + public int X { get; } /// The Y cursor position. - public int Y { get; private set; } + public int Y { get; } /********* ** Public methods *********/ /// Construct an instance. - /// The initial state, or null to get the latest state. - public MouseStateBuilder(MouseState? state = null) + /// The initial state. + public MouseStateBuilder(MouseState state) { - this.Reset(state); - } - - /// Reset the tracked state. - /// The state from which to reset, or null to get the latest state. - public MouseStateBuilder Reset(MouseState? state = null) - { - this.State = state ??= Mouse.GetState(); + this.State = state; this.ButtonStates = new Dictionary { - [SButton.MouseLeft] = state.Value.LeftButton, - [SButton.MouseMiddle] = state.Value.MiddleButton, - [SButton.MouseRight] = state.Value.RightButton, - [SButton.MouseX1] = state.Value.XButton1, - [SButton.MouseX2] = state.Value.XButton2 + [SButton.MouseLeft] = state.LeftButton, + [SButton.MouseMiddle] = state.MiddleButton, + [SButton.MouseRight] = state.RightButton, + [SButton.MouseX1] = state.XButton1, + [SButton.MouseX2] = state.XButton2 }; - this.X = state.Value.X; - this.Y = state.Value.Y; - this.ScrollWheelValue = state.Value.ScrollWheelValue; - - return this; + this.X = state.X; + this.Y = state.Y; + this.ScrollWheelValue = state.ScrollWheelValue; } /// Override the states for a set of buttons. -- cgit