Change IJoypadApi methods from float to int, allow null in SetAnalog

also from Dictionary<,> to IDictionary<,>
This commit is contained in:
YoshiRulz 2020-09-03 09:21:25 +10:00 committed by adelikat
parent 12c5658050
commit 99440b6095
4 changed files with 10 additions and 10 deletions

View File

@ -7,9 +7,9 @@ namespace BizHawk.Client.Common
IDictionary<string, object> Get(int? controller = null);
IDictionary<string, object> GetImmediate(int? controller = null);
void SetFromMnemonicStr(string inputLogEntry);
void Set(Dictionary<string, bool> buttons, int? controller = null);
void Set(IDictionary<string, bool> buttons, int? controller = null);
void Set(string button, bool? state = null, int? controller = null);
void SetAnalog(Dictionary<string, float> controls, object controller = null);
void SetAnalog(string control, float? value = null, object controller = null);
void SetAnalog(IDictionary<string, int?> controls, object controller = null);
void SetAnalog(string control, int? value = null, object controller = null);
}
}

View File

@ -29,7 +29,7 @@ namespace BizHawk.Client.Common
public StickyXorAdapter StickyXorAdapter { get; } = new StickyXorAdapter();
/// <summary>
/// Used to AND to another controller, used for <see cref="IJoypadApi.Set(Dictionary{string, bool}, int?)">JoypadApi.Set</see>
/// Used to AND to another controller, used for <see cref="IJoypadApi.Set(IDictionary{string, bool}, int?)">JoypadApi.Set</see>
/// </summary>
public OverrideAdapter ButtonOverrideAdapter { get; } = new OverrideAdapter();

View File

@ -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<string, float>();
foreach (var k in controls.Keys) dict[k.ToString()] = Convert.ToSingle(controls[k]);
var dict = new Dictionary<string, int?>();
foreach (var k in controls.Keys) dict[k.ToString()] = (int) Convert.ToSingle(controls[k]);
APIs.Joypad.SetAnalog(dict, controller);
}
}

View File

@ -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<string, bool> buttons, int? controller = null)
public void Set(IDictionary<string, bool> 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<string, float> controls, object controller = null)
public void SetAnalog(IDictionary<string, int?> 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
{