From 99440b609527dd535b1c8c20119fd9662e26bc7a Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 3 Sep 2020 09:21:25 +1000 Subject: [PATCH] Change IJoypadApi methods from float to int, allow null in SetAnalog also from Dictionary<,> to IDictionary<,> --- src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs | 6 +++--- src/BizHawk.Client.Common/inputAdapters/InputManager.cs | 2 +- .../lua/CommonLibs/JoypadLuaLibrary.cs | 4 ++-- src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs index 9209bded97..279d2d1aa4 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs @@ -7,9 +7,9 @@ namespace BizHawk.Client.Common IDictionary Get(int? controller = null); IDictionary GetImmediate(int? controller = null); void SetFromMnemonicStr(string inputLogEntry); - void Set(Dictionary buttons, int? controller = null); + void Set(IDictionary buttons, int? controller = null); void Set(string button, bool? state = null, int? controller = null); - void SetAnalog(Dictionary controls, object controller = null); - void SetAnalog(string control, float? value = null, object controller = null); + void SetAnalog(IDictionary controls, object controller = null); + void SetAnalog(string control, int? value = null, object controller = null); } } diff --git a/src/BizHawk.Client.Common/inputAdapters/InputManager.cs b/src/BizHawk.Client.Common/inputAdapters/InputManager.cs index 7c015c265b..2a237a4045 100644 --- a/src/BizHawk.Client.Common/inputAdapters/InputManager.cs +++ b/src/BizHawk.Client.Common/inputAdapters/InputManager.cs @@ -29,7 +29,7 @@ namespace BizHawk.Client.Common public StickyXorAdapter StickyXorAdapter { get; } = new StickyXorAdapter(); /// - /// Used to AND to another controller, used for JoypadApi.Set + /// Used to AND to another controller, used for JoypadApi.Set /// public OverrideAdapter ButtonOverrideAdapter { get; } = new OverrideAdapter(); diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs index e3b2760f36..15109895a2 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs @@ -48,8 +48,8 @@ namespace BizHawk.Client.Common [LuaMethod("setanalog", "sets the given analog controls to their provided values for the current frame. Note that unlike set() there is only the logic of overriding with the given value.")] public void SetAnalog(LuaTable controls, object controller = null) { - var dict = new Dictionary(); - foreach (var k in controls.Keys) dict[k.ToString()] = Convert.ToSingle(controls[k]); + var dict = new Dictionary(); + foreach (var k in controls.Keys) dict[k.ToString()] = (int) Convert.ToSingle(controls[k]); APIs.Joypad.SetAnalog(dict, controller); } } diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs index 61b5af5a03..09748fa5a9 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs @@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk foreach (var axis in controller.Definition.Axes.Keys) GlobalWin.InputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis)); } - public void Set(Dictionary buttons, int? controller = null) + public void Set(IDictionary buttons, int? controller = null) { // If a controller is specified, we need to iterate over unique button names. If not, we iterate over // ALL button names with P{controller} prefixes @@ -62,16 +62,16 @@ namespace BizHawk.Client.EmuHawk } } - public void SetAnalog(Dictionary controls, object controller = null) + public void SetAnalog(IDictionary controls, object controller = null) { foreach (var kvp in controls) SetAnalog(kvp.Key, kvp.Value, controller); } - public void SetAnalog(string control, float? value = null, object controller = null) + public void SetAnalog(string control, int? value = null, object controller = null) { try { - GlobalWin.InputManager.StickyXorAdapter.SetAxis(controller == null ? control : $"P{controller} {control}", value == null ? (int?) null : (int) value.Value); // the time for changing the API will come --yoshi + GlobalWin.InputManager.StickyXorAdapter.SetAxis(controller == null ? control : $"P{controller} {control}", value); } catch {