Lua - Fix joypad.set()
This commit is contained in:
parent
9f60c73564
commit
42ff4c072c
|
@ -134,6 +134,19 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void Overrides(OverrideAdaptor controller)
|
||||
{
|
||||
foreach (var button in controller.Overrides)
|
||||
{
|
||||
_buttons[button] = controller[button];
|
||||
}
|
||||
|
||||
foreach (var button in controller.InversedButtons)
|
||||
{
|
||||
_buttons[button] ^= true;
|
||||
}
|
||||
}
|
||||
|
||||
public void BindButton(string button, string control)
|
||||
{
|
||||
_bindings[button].Add(control);
|
||||
|
|
|
@ -73,9 +73,9 @@ namespace BizHawk.Client.Common
|
|||
public static StickyXorAdapter StickyXORAdapter = new StickyXorAdapter();
|
||||
|
||||
/// <summary>
|
||||
/// Forces any controller button to Off, useful for things like Joypad.Set
|
||||
/// Used to AND to another controller, used for Joypad.Set()
|
||||
/// </summary>
|
||||
public static ForceOffAdaptor ForceOffAdaptor = new ForceOffAdaptor();
|
||||
public static OverrideAdaptor LuaAndAdaptor = new OverrideAdaptor();
|
||||
|
||||
/// <summary>
|
||||
/// fire off one-frame logical button clicks here. useful for things like ti-83 virtual pad and reset buttons
|
||||
|
|
|
@ -19,9 +19,7 @@ namespace BizHawk.Client.Common
|
|||
Global.AutofireStickyXORAdapter.Source = Global.StickyXORAdapter;
|
||||
|
||||
Global.MultitrackRewiringControllerAdapter.Source = Global.AutofireStickyXORAdapter;
|
||||
Global.ForceOffAdaptor.Source = Global.MultitrackRewiringControllerAdapter;
|
||||
|
||||
Global.MovieInputSourceAdapter.Source = Global.ForceOffAdaptor;
|
||||
Global.MovieInputSourceAdapter.Source = Global.MultitrackRewiringControllerAdapter;
|
||||
Global.ControllerOutput.Source = Global.MovieOutputHardpoint;
|
||||
|
||||
Global.Emulator.Controller = Global.ControllerOutput;
|
||||
|
|
|
@ -110,25 +110,18 @@ namespace BizHawk.Client.Common
|
|||
|
||||
if (!invert)
|
||||
{
|
||||
if (theValue == true) // Force On
|
||||
if (theValue.HasValue) // Force
|
||||
{
|
||||
Global.ClickyVirtualPadController.Click(button.ToString());
|
||||
Global.ForceOffAdaptor.SetSticky(button.ToString(), false);
|
||||
Global.LuaAndAdaptor.SetButton(button.ToString(), theValue.Value);
|
||||
}
|
||||
else if (theValue == false) // Force off
|
||||
else // Unset
|
||||
{
|
||||
Global.ForceOffAdaptor.SetSticky(button.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.StickyXORAdapter.Unset(button.ToString());
|
||||
Global.ForceOffAdaptor.Unset(button.ToString());
|
||||
Global.LuaAndAdaptor.UnSet(button.ToString());
|
||||
}
|
||||
}
|
||||
else // Inverse
|
||||
{
|
||||
Global.StickyXORAdapter.SetSticky(button.ToString(), true);
|
||||
Global.ForceOffAdaptor.SetSticky(button.ToString(), false);
|
||||
Global.LuaAndAdaptor.SetInverse(button.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,55 +202,6 @@ namespace BizHawk.Client.Common
|
|||
|
||||
}
|
||||
|
||||
public class ForceOffAdaptor : IController
|
||||
{
|
||||
public bool IsPressed(string button) { return this[button]; }
|
||||
|
||||
// what exactly would we want to do here with floats?
|
||||
// ForceOffAdaptor is only used by lua, and the code there looks like a big mess...
|
||||
public float GetFloat(string name) { return Source.GetFloat(name); }
|
||||
|
||||
protected HashSet<string> StickySet = new HashSet<string>();
|
||||
public IController Source { get; set; }
|
||||
public IController SourceOr { get; set; }
|
||||
|
||||
public ControllerDefinition Type
|
||||
{
|
||||
get { return Source.Type; }
|
||||
set { throw new InvalidOperationException(); }
|
||||
}
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get
|
||||
{
|
||||
return !StickySet.Contains(button) && Source[button];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSticky(string button, bool isSticky)
|
||||
{
|
||||
if (isSticky)
|
||||
{
|
||||
this.StickySet.Add(button);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.StickySet.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unset(string button)
|
||||
{
|
||||
StickySet.Remove(button);
|
||||
}
|
||||
}
|
||||
|
||||
public class StickyXorAdapter : IController
|
||||
{
|
||||
protected HashSet<string> stickySet = new HashSet<string>();
|
||||
|
@ -625,4 +576,93 @@ namespace BizHawk.Client.Common
|
|||
return Source.IsPressed(RemapButtonName(button));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to pass into an Override method to manage the logic overriding input
|
||||
/// This only works with bool buttons!
|
||||
/// </summary>
|
||||
public class OverrideAdaptor : IController
|
||||
{
|
||||
private readonly Dictionary<string, bool> _overrides = new Dictionary<string, bool>();
|
||||
private readonly List<string> _inverses = new List<string>();
|
||||
|
||||
public bool this[string button]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_overrides.ContainsKey(button))
|
||||
{
|
||||
return _overrides[button];
|
||||
}
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_overrides.ContainsKey(button))
|
||||
{
|
||||
_overrides[button] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_overrides.Add(button, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ControllerDefinition Type { get; set; }
|
||||
|
||||
public IEnumerable<string> Overrides
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var kvp in _overrides)
|
||||
{
|
||||
yield return kvp.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> InversedButtons
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var name in _inverses)
|
||||
{
|
||||
yield return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
public bool IsPressed(string button) { return this[button]; }
|
||||
|
||||
public void SetButton(string button, bool value)
|
||||
{
|
||||
this[button] = value;
|
||||
_inverses.Remove(button);
|
||||
}
|
||||
|
||||
public void UnSet(string button)
|
||||
{
|
||||
_overrides.Remove(button);
|
||||
_inverses.Remove(button);
|
||||
}
|
||||
|
||||
public void SetInverse(string button)
|
||||
{
|
||||
_inverses.Add(button);
|
||||
}
|
||||
|
||||
public void FrameTick()
|
||||
{
|
||||
_overrides.Clear();
|
||||
_inverses.Clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -398,6 +398,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
Global.ActiveController.LatchFromPhysical(Global.ControllerInputCoalescer);
|
||||
|
||||
Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController);
|
||||
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
|
||||
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
|
||||
|
||||
if (Global.ClientControls["Autohold"])
|
||||
|
@ -2339,6 +2340,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
Global.ClickyVirtualPadController.FrameTick();
|
||||
Global.LuaAndAdaptor.FrameTick();
|
||||
|
||||
_runloopFps++;
|
||||
|
||||
|
|
Loading…
Reference in New Issue