diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-01 14:51:12 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-09-01 14:51:12 -0400 |
commit | da11ea66dbe3dd033f4081baea5b439e2c11d0e8 (patch) | |
tree | b9e4395c5eab06a651edcdbf462ba6eb3a1003cc /src | |
parent | 7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef (diff) | |
download | SMAPI-da11ea66dbe3dd033f4081baea5b439e2c11d0e8.tar.gz SMAPI-da11ea66dbe3dd033f4081baea5b439e2c11d0e8.tar.bz2 SMAPI-da11ea66dbe3dd033f4081baea5b439e2c11d0e8.zip |
add SButton extension to get InputButton equivalent
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Utilities/SButton.cs | 28 |
1 files changed, 27 insertions, 1 deletions
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; } + + /// <summary>Get the <see cref="InputButton"/> equivalent for the given button.</summary> + /// <param name="input">The button to convert.</param> + /// <param name="button">The Stardew Valley input button equivalent.</param> + /// <returns>Returns whether the value was converted successfully.</returns> + 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; + } } } |