Migrate InputLuaLibrary to ApiHawk delegation

This commit is contained in:
YoshiRulz 2019-12-15 03:59:21 +10:00
parent 104c17e77c
commit cc8dffa769
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 11 additions and 24 deletions

View File

@ -1,13 +1,12 @@
using System; using System;
using System.Linq;
using System.Windows.Forms; using NLua;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using NLua;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public sealed class InputLuaLibrary : LuaLibraryBase public sealed class InputLuaLibrary : DelegatingLuaLibraryEmu
{ {
public InputLuaLibrary(Lua lua) public InputLuaLibrary(Lua lua)
: base(lua) { } : base(lua) { }
@ -21,32 +20,20 @@ namespace BizHawk.Client.EmuHawk
[LuaMethod("get", "Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil.")] [LuaMethod("get", "Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil.")]
public LuaTable Get() public LuaTable Get()
{ {
var buttons = Lua.NewTable(); var result = APIs.Input.Get();
foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value)) var table = Lua.NewTable();
{ foreach (var kvp in result) table[kvp.Key] = kvp.Value;
buttons[kvp.Key] = true; return table;
}
return buttons;
} }
[LuaMethodExample("local nlinpget = input.getmouse( );")] [LuaMethodExample("local nlinpget = input.getmouse( );")]
[LuaMethod("getmouse", "Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel.")] [LuaMethod("getmouse", "Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel.")]
public LuaTable GetMouse() public LuaTable GetMouse()
{ {
var buttons = Lua.NewTable(); var result = APIs.Input.GetMouse();
var table = Lua.NewTable();
// TODO - need to specify whether in "emu" or "native" coordinate space. foreach (var kvp in result) table[kvp.Key] = kvp.Value;
var p = GlobalWin.DisplayManager.UntransformPoint(Control.MousePosition); return table;
buttons["X"] = p.X;
buttons["Y"] = p.Y;
buttons[MouseButtons.Left.ToString()] = (Control.MouseButtons & MouseButtons.Left) != 0;
buttons[MouseButtons.Middle.ToString()] = (Control.MouseButtons & MouseButtons.Middle) != 0;
buttons[MouseButtons.Right.ToString()] = (Control.MouseButtons & MouseButtons.Right) != 0;
buttons[MouseButtons.XButton1.ToString()] = (Control.MouseButtons & MouseButtons.XButton1) != 0;
buttons[MouseButtons.XButton2.ToString()] = (Control.MouseButtons & MouseButtons.XButton2) != 0;
buttons["Wheel"] = GlobalWin.MainForm.MouseWheelTracker;
return buttons;
} }
} }
} }