From da11ea66dbe3dd033f4081baea5b439e2c11d0e8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 1 Sep 2017 14:51:12 -0400 Subject: [PATCH] add SButton extension to get InputButton equivalent --- src/StardewModdingAPI/Utilities/SButton.cs | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/StardewModdingAPI/Utilities/SButton.cs b/src/StardewModdingAPI/Utilities/SButton.cs index c4833b0b..33058a64 100644 --- a/src/StardewModdingAPI/Utilities/SButton.cs +++ b/src/StardewModdingAPI/Utilities/SButton.cs @@ -1,5 +1,6 @@ -using System; +using System; using Microsoft.Xna.Framework.Input; +using StardewValley; namespace StardewModdingAPI.Utilities { @@ -655,5 +656,30 @@ namespace StardewModdingAPI.Utilities button = 0; return false; } + + /// Get the equivalent for the given button. + /// The button to convert. + /// The Stardew Valley input button equivalent. + /// Returns whether the value was converted successfully. + public static bool TryGetStardewInput(this SButton input, out InputButton button) + { + // keyboard + if (input.TryGetKeyboard(out Keys key)) + { + button = new InputButton(key); + return true; + } + + // mouse + if (input == SButton.MouseLeft || input == SButton.MouseRight) + { + button = new InputButton(mouseLeft: input == SButton.MouseLeft); + return true; + } + + // not valid + button = default(InputButton); + return false; + } } }