Migrate InputLuaLibrary to ApiHawk delegation
This commit is contained in:
parent
104c17e77c
commit
cc8dffa769
|
@ -1,13 +1,12 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using NLua;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using NLua;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public sealed class InputLuaLibrary : LuaLibraryBase
|
||||
public sealed class InputLuaLibrary : DelegatingLuaLibraryEmu
|
||||
{
|
||||
public InputLuaLibrary(Lua 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.")]
|
||||
public LuaTable Get()
|
||||
{
|
||||
var buttons = Lua.NewTable();
|
||||
foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value))
|
||||
{
|
||||
buttons[kvp.Key] = true;
|
||||
}
|
||||
|
||||
return buttons;
|
||||
var result = APIs.Input.Get();
|
||||
var table = Lua.NewTable();
|
||||
foreach (var kvp in result) table[kvp.Key] = kvp.Value;
|
||||
return table;
|
||||
}
|
||||
|
||||
[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.")]
|
||||
public LuaTable GetMouse()
|
||||
{
|
||||
var buttons = Lua.NewTable();
|
||||
|
||||
// TODO - need to specify whether in "emu" or "native" coordinate space.
|
||||
var p = GlobalWin.DisplayManager.UntransformPoint(Control.MousePosition);
|
||||
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;
|
||||
var result = APIs.Input.GetMouse();
|
||||
var table = Lua.NewTable();
|
||||
foreach (var kvp in result) table[kvp.Key] = kvp.Value;
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue