Fix joypad.Set() when using the controller number parameter, also strongly type that parameter to nullable int instead of object, add a unit test lua script that tests for this
This commit is contained in:
parent
67704b35bf
commit
04aa023cb9
|
@ -71,7 +71,7 @@ namespace BizHawk.Client.Common
|
|||
"set",
|
||||
"sets the given buttons to their provided values for the current frame"
|
||||
)]
|
||||
public void Set(LuaTable buttons, object controller = null)
|
||||
public void Set(LuaTable buttons, int? controller = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -102,8 +102,8 @@ namespace BizHawk.Client.Common
|
|||
theValue = null;
|
||||
}
|
||||
|
||||
var toPress = button;
|
||||
if (controller != null)
|
||||
var toPress = button.ToString();
|
||||
if (controller.HasValue)
|
||||
{
|
||||
toPress = "P" + controller + " " + button;
|
||||
}
|
||||
|
@ -112,16 +112,16 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (theValue.HasValue) // Force
|
||||
{
|
||||
Global.LuaAndAdaptor.SetButton(button.ToString(), theValue.Value);
|
||||
Global.LuaAndAdaptor.SetButton(toPress, theValue.Value);
|
||||
}
|
||||
else // Unset
|
||||
{
|
||||
Global.LuaAndAdaptor.UnSet(button.ToString());
|
||||
Global.LuaAndAdaptor.UnSet(toPress);
|
||||
}
|
||||
}
|
||||
else // Inverse
|
||||
{
|
||||
Global.LuaAndAdaptor.SetInverse(button.ToString());
|
||||
Global.LuaAndAdaptor.SetInverse(toPress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,33 +10,33 @@ console.log("After frame 600, the console will say 'cleared', and now all button
|
|||
|
||||
buttons = { };
|
||||
|
||||
buttons["P1 Up"] = false;
|
||||
buttons["P1 Down"] = true;
|
||||
buttons["P1 Left"] = "invert";
|
||||
buttons["P1 Right"] = null;
|
||||
joypad.set(buttons);
|
||||
buttons["Up"] = false;
|
||||
buttons["Down"] = true;
|
||||
buttons["Left"] = "invert";
|
||||
buttons["Right"] = null;
|
||||
joypad.set(buttons, 1);
|
||||
|
||||
pushThings = true;
|
||||
|
||||
while true do
|
||||
if (pushThings) then
|
||||
buttons = { };
|
||||
buttons["P1 A"] = false;
|
||||
buttons["P1 B"] = true;
|
||||
buttons["P1 Select"] = "invert";
|
||||
buttons["P1 Start"] = null;
|
||||
joypad.set(buttons);
|
||||
buttons["A"] = false;
|
||||
buttons["B"] = true;
|
||||
buttons["Select"] = "invert";
|
||||
buttons["Start"] = null;
|
||||
joypad.set(buttons, 1);
|
||||
end
|
||||
|
||||
if (emu.framecount() == 600) then
|
||||
pushThings = false;
|
||||
turnoff = { };
|
||||
turnoff["P1 A"] = null;
|
||||
turnoff["P1 B"] = null;
|
||||
turnoff["P1 Select"] = null;
|
||||
turnoff["P1 Start"] = null;
|
||||
turnoff["A"] = null;
|
||||
turnoff["B"] = null;
|
||||
turnoff["Select"] = null;
|
||||
turnoff["Start"] = null;
|
||||
|
||||
joypad.set(turnoff);
|
||||
joypad.set(turnoff, 1);
|
||||
console.log("cleared")
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
console.log("Unit test for joypad.set using the controller parameter")
|
||||
console.log("Core Required: NES (or any multi-player core with U,D,L,R,select,start,A,B as buttons)")
|
||||
console.log("Correct behavior:")
|
||||
console.log("No Directional button shoudl be imparied in any way, should operate as if nothing was ever pressed")
|
||||
console.log("A should be off and user can not push buttons to change that")
|
||||
console.log("B should be on and the user can not push buttons to change that")
|
||||
console.log("Select should be on, but pressing it turns it off")
|
||||
console.log("Start should be unaffected")
|
||||
console.log("After frame 600, the console will say 'cleared', and now all buttons should be off and unaffected, as if the script was never run");
|
||||
|
||||
buttons = { };
|
||||
|
||||
buttons["Up"] = false;
|
||||
buttons["Down"] = true;
|
||||
buttons["Left"] = "invert";
|
||||
buttons["Right"] = null;
|
||||
joypad.set(buttons, 1);
|
||||
|
||||
pushThings = true;
|
||||
|
||||
while true do
|
||||
if (pushThings) then
|
||||
buttons = { };
|
||||
buttons["A"] = false;
|
||||
buttons["B"] = true;
|
||||
buttons["Select"] = "invert";
|
||||
buttons["Start"] = null;
|
||||
joypad.set(buttons, 1);
|
||||
end
|
||||
|
||||
if (emu.framecount() == 600) then
|
||||
pushThings = false;
|
||||
turnoff = { };
|
||||
turnoff["A"] = null;
|
||||
turnoff["B"] = null;
|
||||
turnoff["Select"] = null;
|
||||
turnoff["Start"] = null;
|
||||
|
||||
joypad.set(turnoff, 1);
|
||||
console.log("cleared")
|
||||
end
|
||||
|
||||
emu.frameadvance();
|
||||
end
|
|
@ -1,2 +1,3 @@
|
|||
0 .\Lua\UnitTests\Joypad_Set.lua
|
||||
0 .\Lua\UnitTests\Joypad_WithControllerNumbers.lua
|
||||
0 .\Lua\UnitTests\GameInfo.lua
|
||||
|
|
Loading…
Reference in New Issue