Make some more lua libraries into their own objects

This commit is contained in:
adelikat 2013-10-31 13:07:42 +00:00
parent 6e3d55372f
commit 6db76dd265
4 changed files with 103 additions and 80 deletions

View File

@ -4,8 +4,29 @@ using LuaInterface;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public class InputLuaLibrary : LuaLibraryBase
{
public InputLuaLibrary(Lua lua)
: base()
{
_lua = lua;
}
public override string Name { get { return "input"; } }
public override string[] Functions
{
get
{
return new[]
{
"get",
"getmouse"
};
}
}
private Lua _lua;
public LuaTable input_get()
{
LuaTable buttons = _lua.NewTable();

View File

@ -4,9 +4,31 @@ using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public class JoypadLuaLibrary : LuaLibraryBase
{
//Currently sends all controllers, needs to control which ones it sends
public JoypadLuaLibrary(Lua lua)
: base()
{
_lua = lua;
}
public override string Name { get { return "joypad"; } }
public override string[] Functions
{
get
{
return new[]
{
"get",
"getimmediate",
"set",
"setanalog"
};
}
}
private Lua _lua;
public LuaTable joypad_get(object controller = null)
{
LuaTable buttons = _lua.NewTable();
@ -16,9 +38,9 @@ namespace BizHawk.MultiClient
{
buttons[button] = Global.ControllerOutput[button];
}
else if (button.Length >= 3 && button.Substring(0, 2) == "P" + LuaCommon.LuaInt(controller).ToString())
else if (button.Length >= 3 && button.Substring(0, 2) == "P" + LuaInt(controller).ToString())
{
buttons[button.Substring(3)] = Global.ControllerOutput["P" + LuaCommon.LuaInt(controller) + " " + button.Substring(3)];
buttons[button.Substring(3)] = Global.ControllerOutput["P" + LuaInt(controller) + " " + button.Substring(3)];
}
}
@ -28,9 +50,9 @@ namespace BizHawk.MultiClient
{
buttons[button] = Global.ControllerOutput.GetFloat(button);
}
else if (button.Length >= 3 && button.Substring(0, 2) == "P" + LuaCommon.LuaInt(controller).ToString())
else if (button.Length >= 3 && button.Substring(0, 2) == "P" + LuaInt(controller).ToString())
{
buttons[button.Substring(3)] = Global.ControllerOutput.GetFloat("P" + LuaCommon.LuaInt(controller) + " " + button.Substring(3));
buttons[button.Substring(3)] = Global.ControllerOutput.GetFloat("P" + LuaInt(controller) + " " + button.Substring(3));
}
}
@ -45,7 +67,9 @@ namespace BizHawk.MultiClient
{
LuaTable buttons = _lua.NewTable();
foreach (string button in Global.ActiveController.Type.BoolButtons)
{
buttons[button] = Global.ActiveController[button];
}
return buttons;
}

View File

@ -3,9 +3,39 @@ using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public class MovieLuaLibrary : LuaLibraryBase
{
public string movie_filename()
public MovieLuaLibrary(Lua lua)
: base()
{
_lua = lua;
}
public override string Name { get { return "movie"; } }
public override string[] Functions
{
get
{
return new[]
{
"filename",
"getinput",
"getreadonly",
"getrerecordcounting",
"isloaded",
"length",
"mode",
"rerecordcount",
"setreadonly",
"setrerecordcounting",
"stop",
};
}
}
private Lua _lua;
public static string movie_filename()
{
return Global.MovieSession.Movie.Filename;
}
@ -27,29 +57,22 @@ namespace BizHawk.MultiClient
return input;
}
public bool movie_getreadonly()
public static bool movie_getreadonly()
{
return GlobalWinF.MainForm.ReadOnly;
}
public bool movie_getrerecordcounting()
public static bool movie_getrerecordcounting()
{
return Global.MovieSession.Movie.IsCountingRerecords;
}
public bool movie_isloaded()
public static bool movie_isloaded()
{
if (Global.MovieSession.Movie.IsActive)
{
return true;
}
else
{
return false;
}
return Global.MovieSession.Movie.IsActive;
}
public int movie_length()
public static int movie_length()
{
if (Global.MovieSession.Movie.Frames.HasValue)
{
@ -61,7 +84,7 @@ namespace BizHawk.MultiClient
}
}
public string movie_mode()
public static string movie_mode()
{
if (Global.MovieSession.Movie.IsFinished)
{
@ -81,28 +104,30 @@ namespace BizHawk.MultiClient
}
}
public string movie_rerecordcount()
public static string movie_rerecordcount()
{
return Global.MovieSession.Movie.Rerecords.ToString();
}
public void movie_setreadonly(object lua_input)
public static void movie_setreadonly(object lua_input)
{
if (lua_input.ToString().ToUpper() == "TRUE" || lua_input.ToString() == "1")
{
GlobalWinF.MainForm.SetReadOnly(true);
}
else
{
GlobalWinF.MainForm.SetReadOnly(false);
}
}
public void movie_setrerecordcounting(object lua_input)
public static void movie_setrerecordcounting(object lua_input)
{
if (lua_input.ToString().ToUpper() == "TRUE" || lua_input.ToString() == "1")
Global.MovieSession.Movie.IsCountingRerecords = true;
else
Global.MovieSession.Movie.IsCountingRerecords = false;
Global.MovieSession.Movie.IsCountingRerecords
= (lua_input.ToString().ToUpper() == "TRUE" || lua_input.ToString() == "1");
}
public void movie_stop()
public static void movie_stop()
{
Global.MovieSession.Movie.Stop();
}

View File

@ -107,20 +107,6 @@ namespace BizHawk.MultiClient
"textbox",
};
public static string[] InputFunctions = new[]
{
"get",
"getmouse"
};
public static string[] JoypadFunctions = new[]
{
"get",
"getimmediate",
"set",
"setanalog"
};
public static string[] MainMemoryFunctions = new[]
{
"getname",
@ -202,21 +188,6 @@ namespace BizHawk.MultiClient
"write_u32_be",
};
public static string[] MovieFunctions = new[]
{
"filename",
"getinput",
"getreadonly",
"getrerecordcounting",
"isloaded",
"length",
"mode",
"rerecordcount",
"setreadonly",
"setrerecordcounting",
"stop",
};
public static string[] SaveStateFunctions = new[]
{
"load",
@ -234,6 +205,9 @@ namespace BizHawk.MultiClient
new BitLuaLibrary().LuaRegister(lua, Docs);
new MultiClientLuaLibrary(ConsoleLuaLibrary.console_log).LuaRegister(lua, Docs);
new ConsoleLuaLibrary().LuaRegister(lua, Docs);
new InputLuaLibrary(_lua).LuaRegister(lua, Docs);
new JoypadLuaLibrary(_lua).LuaRegister(lua, Docs);
new MovieLuaLibrary(_lua).LuaRegister(lua, Docs);
new NESLuaLibrary().LuaRegister(lua, Docs);
new SNESLuaLibrary().LuaRegister(lua, Docs);
@ -274,27 +248,6 @@ namespace BizHawk.MultiClient
Docs.Add("savestate", t, GetType().GetMethod("savestate_" + t));
}
lua.NewTable("movie");
foreach (string t in MovieFunctions)
{
lua.RegisterFunction("movie." + t, this, GetType().GetMethod("movie_" + t));
Docs.Add("movie", t, GetType().GetMethod("movie_" + t));
}
lua.NewTable("input");
foreach (string t in InputFunctions)
{
lua.RegisterFunction("input." + t, this, GetType().GetMethod("input_" + t));
Docs.Add("input", t, GetType().GetMethod("input_" + t));
}
lua.NewTable("joypad");
foreach (string t in JoypadFunctions)
{
lua.RegisterFunction("joypad." + t, this, GetType().GetMethod("joypad_" + t));
Docs.Add("joypad", t, GetType().GetMethod("joypad_" + t));
}
lua.NewTable("forms");
foreach (string t in FormsFunctions)
{