Skip to content

Commit

Permalink
Change IJoypadApi methods from float to int, allow null in SetAnalog
Browse files Browse the repository at this point in the history
also from Dictionary<,> to IDictionary<,>
  • Loading branch information
YoshiRulz authored and adelikat committed Sep 12, 2020
1 parent 12c5658 commit 99440b6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public interface IJoypadApi : IExternalApi
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);
}
}
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/inputAdapters/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class InputManager
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();

Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.Common/lua/CommonLibs/JoypadLuaLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void Set(LuaTable buttons, int? controller = null)
[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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/BizHawk.Client.EmuHawk/Api/Libraries/JoypadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void SetFromMnemonicStr(string inputLogEntry)
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
Expand All @@ -62,16 +62,16 @@ public void Set(string button, bool? state = null, int? controller = null)
}
}

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
{
Expand Down

0 comments on commit 99440b6

Please sign in to comment.