Make some more lua libraries into their own objects

This commit is contained in:
adelikat 2013-10-29 16:03:06 +00:00
parent 3e1c28f26c
commit fcfdf1ac40
9 changed files with 184 additions and 170 deletions

View File

@ -3,74 +3,100 @@ using BizHawk.Client.Common;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public static class MultiClientLuaLibrary
{
public void client_closerom()
public static string Name = "client";
public static string[] Functions = new[]
{
"closerom",
"getwindowsize",
"opencheats",
"openhexeditor",
"openramwatch",
"openramsearch",
"openrom",
"opentasstudio",
"opentoolbox",
"opentracelogger",
"pause_av",
"reboot_core",
"screenheight",
"screenshot",
"screenshottoclipboard",
"screenwidth",
"setscreenshotosd",
"setwindowsize",
"unpause_av",
"xpos",
"ypos",
};
public static void client_closerom()
{
GlobalWinF.MainForm.CloseROM();
}
public int client_getwindowsize()
public static int client_getwindowsize()
{
return Global.Config.TargetZoomFactor;
}
public void client_opencheats()
public static void client_opencheats()
{
GlobalWinF.MainForm.LoadCheatsWindow();
}
public void client_openhexeditor()
public static void client_openhexeditor()
{
GlobalWinF.MainForm.LoadHexEditor();
}
public void client_openramwatch()
public static void client_openramwatch()
{
GlobalWinF.MainForm.LoadRamWatch(true);
}
public void client_openramsearch()
public static void client_openramsearch()
{
GlobalWinF.MainForm.LoadRamSearch();
}
public void client_openrom(object lua_input)
public static void client_openrom(object lua_input)
{
GlobalWinF.MainForm.LoadRom(lua_input.ToString());
}
public void client_opentasstudio()
public static void client_opentasstudio()
{
GlobalWinF.MainForm.LoadTAStudio();
}
public void client_opentoolbox()
public static void client_opentoolbox()
{
GlobalWinF.MainForm.LoadToolBox();
}
public void client_opentracelogger()
public static void client_opentracelogger()
{
GlobalWinF.MainForm.LoadTraceLogger();
}
public void client_pause_av()
public static void client_pause_av()
{
GlobalWinF.MainForm.PauseAVI = true;
}
public void client_reboot_core()
public static void client_reboot_core()
{
GlobalWinF.MainForm.RebootCore();
}
public int client_screenheight()
public static int client_screenheight()
{
return GlobalWinF.RenderPanel.NativeSize.Height;
}
public void client_screenshot(object path = null)
public static void client_screenshot(object path = null)
{
if (path == null)
{
@ -82,22 +108,22 @@ namespace BizHawk.MultiClient
}
}
public void client_screenshottoclipboard()
public static void client_screenshottoclipboard()
{
GlobalWinF.MainForm.TakeScreenshotToClipboard();
}
public void client_setscreenshotosd(bool value)
public static void client_setscreenshotosd(bool value)
{
Global.Config.Screenshot_CaptureOSD = value;
}
public int client_screenwidth()
public static int client_screenwidth()
{
return GlobalWinF.RenderPanel.NativeSize.Width;
}
public void client_setwindowsize(object window_size)
public static void client_setwindowsize(object window_size)
{
try
{
@ -111,27 +137,27 @@ namespace BizHawk.MultiClient
}
else
{
console_log("Invalid window size");
ConsoleLuaLibrary.console_log("Invalid window size");
}
}
catch
{
console_log("Invalid window size");
ConsoleLuaLibrary.console_log("Invalid window size");
}
}
public void client_unpause_av()
public static void client_unpause_av()
{
GlobalWinF.MainForm.PauseAVI = false;
}
public int client_xpos()
public static int client_xpos()
{
return GlobalWinF.MainForm.DesktopLocation.X;
}
public int client_ypos()
public static int client_ypos()
{
return GlobalWinF.MainForm.DesktopLocation.Y;
}

View File

@ -6,14 +6,23 @@ using LuaInterface;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public static class ConsoleLuaLibrary
{
public void console_clear()
public static string Name = "console";
public static string[] Functions = new[]
{
"clear",
"getluafunctionslist",
"log",
"output",
};
public static void console_clear()
{
GlobalWinF.MainForm.LuaConsole1.ClearOutputWindow();
}
public string console_getluafunctionslist()
public static string console_getluafunctionslist()
{
string list = "";
foreach (LuaDocumentation.LibraryFunction l in GlobalWinF.MainForm.LuaConsole1.LuaImp.Docs.FunctionList)
@ -24,12 +33,12 @@ namespace BizHawk.MultiClient
return list;
}
public void console_log(object lua_input)
public static void console_log(object lua_input)
{
console_output(lua_input);
}
public void console_output(object lua_input)
public static void console_output(object lua_input)
{
if (lua_input == null)
{

View File

@ -95,12 +95,12 @@ namespace BizHawk.MultiClient
}
else
{
console_log("Invalid frame skip value");
ConsoleLuaLibrary.console_log("Invalid frame skip value");
}
}
catch
{
console_log("Invalid frame skip value");
ConsoleLuaLibrary.console_log("Invalid frame skip value");
}
}
@ -204,12 +204,12 @@ namespace BizHawk.MultiClient
}
else
{
console_log("Invalid speed value");
ConsoleLuaLibrary.console_log("Invalid speed value");
}
}
catch
{
console_log("Invalid speed value");
ConsoleLuaLibrary.console_log("Invalid speed value");
}
}

View File

@ -181,10 +181,10 @@ namespace BizHawk.MultiClient
}
catch (Exception ex)
{
console_output(ex.Message);
ConsoleLuaLibrary.console_output(ex.Message);
}
return "";
return String.Empty;
}
public string forms_gettext(object handle)
@ -212,10 +212,10 @@ namespace BizHawk.MultiClient
}
catch (Exception ex)
{
console_output(ex.Message);
ConsoleLuaLibrary.console_output(ex.Message);
}
return "";
return String.Empty;
}
public int forms_label(object form_handle, object caption, object X = null, object Y = null, object width = null, object height = null)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using LuaInterface;
using BizHawk.Client.Common;
@ -144,8 +145,8 @@ namespace BizHawk.MultiClient
dy -= Global.Emulator.CoreComm.ScreenLogicalOffsetY;
}
// blah hacks
dx *= client_getwindowsize();
dy *= client_getwindowsize();
dx *= MultiClientLuaLibrary.client_getwindowsize();
dy *= MultiClientLuaLibrary.client_getwindowsize();
GlobalWinF.OSD.AddGUIText(luaStr.ToString(), dx, dy, alert, GetColor(background), GetColor(forecolor), a);
}

View File

@ -14,11 +14,15 @@ namespace BizHawk.MultiClient
{
LuaTable input = _lua.NewTable();
string s = Global.MovieSession.Movie.GetInput(LuaCommon.LuaInt(frame));
MovieControllerAdapter m = new MovieControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type };
m.SetControllersAsMnemonic(s);
m.SetControllersAsMnemonic(
Global.MovieSession.Movie.GetInput(LuaCommon.LuaInt(frame))
);
foreach (string button in m.Type.BoolButtons)
{
input[button] = m[button];
}
return input;
}

View File

@ -4,9 +4,27 @@ using BizHawk.Emulation.Consoles.Nintendo;
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public static class NESLuaLibrary
{
public void nes_addgamegenie(string code)
public static string Name = "nes";
public static string[] Functions = new[]
{
"addgamegenie",
"getallowmorethaneightsprites",
"getbottomscanline",
"getclipleftandright",
"getdispbackground",
"getdispsprites",
"gettopscanline",
"removegamegenie",
"setallowmorethaneightsprites",
"setclipleftandright",
"setdispbackground",
"setdispsprites",
"setscanlines",
};
public static void nes_addgamegenie(string code)
{
if (Global.Emulator is NES)
{
@ -34,12 +52,12 @@ namespace BizHawk.MultiClient
}
}
public bool nes_getallowmorethaneightsprites()
public static bool nes_getallowmorethaneightsprites()
{
return Global.Config.NESAllowMoreThanEightSprites;
}
public int nes_getbottomscanline(bool pal = false)
public static int nes_getbottomscanline(bool pal = false)
{
if (pal)
{
@ -51,22 +69,22 @@ namespace BizHawk.MultiClient
}
}
public bool nes_getclipleftandright()
public static bool nes_getclipleftandright()
{
return Global.Config.NESClipLeftAndRight;
}
public bool nes_getdispbackground()
public static bool nes_getdispbackground()
{
return Global.Config.NESDispBackground;
}
public bool nes_getdispsprites()
public static bool nes_getdispsprites()
{
return Global.Config.NESDispSprites;
}
public int nes_gettopscanline(bool pal = false)
public static int nes_gettopscanline(bool pal = false)
{
if (pal)
{
@ -78,7 +96,7 @@ namespace BizHawk.MultiClient
}
}
public void nes_removegamegenie(string code)
public static void nes_removegamegenie(string code)
{
if (Global.Emulator is NES)
{
@ -94,7 +112,7 @@ namespace BizHawk.MultiClient
}
}
public void nes_setallowmorethaneightsprites(bool allow)
public static void nes_setallowmorethaneightsprites(bool allow)
{
Global.Config.NESAllowMoreThanEightSprites = allow;
if (Global.Emulator is NES)
@ -103,7 +121,7 @@ namespace BizHawk.MultiClient
}
}
public void nes_setclipleftandright(bool leftandright)
public static void nes_setclipleftandright(bool leftandright)
{
Global.Config.NESClipLeftAndRight = leftandright;
if (Global.Emulator is NES)
@ -112,19 +130,19 @@ namespace BizHawk.MultiClient
}
}
public void nes_setdispbackground(bool show)
public static void nes_setdispbackground(bool show)
{
Global.Config.NESDispBackground = show;
GlobalWinF.MainForm.SyncCoreCommInputSignals();
}
public void nes_setdispsprites(bool show)
public static void nes_setdispsprites(bool show)
{
Global.Config.NESDispSprites = show;
GlobalWinF.MainForm.SyncCoreCommInputSignals();
}
public void nes_setscanlines(object top, object bottom, bool pal = false)
public static void nes_setscanlines(object top, object bottom, bool pal = false)
{
int first = LuaCommon.LuaInt(top);

View File

@ -2,84 +2,105 @@
namespace BizHawk.MultiClient
{
public partial class EmuLuaLibrary
public static class SNESLuaLibrary
{
public bool snes_getlayer_bg_1()
public static string Name = "snes";
public static string[] Functions = new[]
{
"getlayer_bg_1",
"getlayer_bg_2",
"getlayer_bg_3",
"getlayer_bg_4",
"getlayer_obj_1",
"getlayer_obj_2",
"getlayer_obj_3",
"getlayer_obj_4",
"setlayer_bg_1",
"setlayer_bg_2",
"setlayer_bg_3",
"setlayer_bg_4",
"setlayer_obj_1",
"setlayer_obj_2",
"setlayer_obj_3",
"setlayer_obj_4",
};
public static bool snes_getlayer_bg_1()
{
return Global.Config.SNES_ShowBG1_1;
}
public bool snes_getlayer_bg_2()
public static bool snes_getlayer_bg_2()
{
return Global.Config.SNES_ShowBG2_1;
}
public bool snes_getlayer_bg_3()
public static bool snes_getlayer_bg_3()
{
return Global.Config.SNES_ShowBG3_1;
}
public bool snes_getlayer_bg_4()
public static bool snes_getlayer_bg_4()
{
return Global.Config.SNES_ShowBG4_1;
}
public bool snes_getlayer_obj_1()
public static bool snes_getlayer_obj_1()
{
return Global.Config.SNES_ShowOBJ1;
}
public bool snes_getlayer_obj_2()
public static bool snes_getlayer_obj_2()
{
return Global.Config.SNES_ShowOBJ2;
}
public bool snes_getlayer_obj_3()
public static bool snes_getlayer_obj_3()
{
return Global.Config.SNES_ShowOBJ3;
}
public bool snes_getlayer_obj_4()
public static bool snes_getlayer_obj_4()
{
return Global.Config.SNES_ShowOBJ4;
}
public void snes_setlayer_bg_1(bool value)
public static void snes_setlayer_bg_1(bool value)
{
GlobalWinF.MainForm.SNES_ToggleBG1(value);
}
public void snes_setlayer_bg_2(bool value)
public static void snes_setlayer_bg_2(bool value)
{
GlobalWinF.MainForm.SNES_ToggleBG2(value);
}
public void snes_setlayer_bg_3(bool value)
public static void snes_setlayer_bg_3(bool value)
{
GlobalWinF.MainForm.SNES_ToggleBG3(value);
}
public void snes_setlayer_bg_4(bool value)
public static void snes_setlayer_bg_4(bool value)
{
GlobalWinF.MainForm.SNES_ToggleBG4(value);
}
public void snes_setlayer_obj_1(bool value)
public static void snes_setlayer_obj_1(bool value)
{
GlobalWinF.MainForm.SNES_ToggleOBJ1(value);
}
public void snes_setlayer_obj_2(bool value)
public static void snes_setlayer_obj_2(bool value)
{
GlobalWinF.MainForm.SNES_ToggleOBJ2(value);
}
public void snes_setlayer_obj_3(bool value)
public static void snes_setlayer_obj_3(bool value)
{
GlobalWinF.MainForm.SNES_ToggleOBJ3(value);
}
public void snes_setlayer_obj_4(bool value)
public static void snes_setlayer_obj_4(bool value)
{
GlobalWinF.MainForm.SNES_ToggleOBJ4(value);
}

View File

@ -33,39 +33,6 @@ namespace BizHawk.MultiClient
#region Register Library Functions
public static string[] MultiClientFunctions = new[]
{
"closerom",
"getwindowsize",
"opencheats",
"openhexeditor",
"openramwatch",
"openramsearch",
"openrom",
"opentasstudio",
"opentoolbox",
"opentracelogger",
"pause_av",
"reboot_core",
"screenheight",
"screenshot",
"screenshottoclipboard",
"screenwidth",
"setscreenshotosd",
"setwindowsize",
"unpause_av",
"xpos",
"ypos",
};
public static string[] ConsoleFunctions = new[]
{
"clear",
"getluafunctionslist",
"log",
"output",
};
public static string[] GuiFunctions = new[]
{
"addmessage",
@ -250,23 +217,6 @@ namespace BizHawk.MultiClient
"stop",
};
public static string[] NESFunctions = new[]
{
"addgamegenie",
"getallowmorethaneightsprites",
"getbottomscanline",
"getclipleftandright",
"getdispbackground",
"getdispsprites",
"gettopscanline",
"removegamegenie",
"setallowmorethaneightsprites",
"setclipleftandright",
"setdispbackground",
"setdispsprites",
"setscanlines",
};
public static string[] SaveStateFunctions = new[]
{
"load",
@ -277,26 +227,6 @@ namespace BizHawk.MultiClient
"saveslot",
};
public static string[] SNESFunctions = new[]
{
"getlayer_bg_1",
"getlayer_bg_2",
"getlayer_bg_3",
"getlayer_bg_4",
"getlayer_obj_1",
"getlayer_obj_2",
"getlayer_obj_3",
"getlayer_obj_4",
"setlayer_bg_1",
"setlayer_bg_2",
"setlayer_bg_3",
"setlayer_bg_4",
"setlayer_obj_1",
"setlayer_obj_2",
"setlayer_obj_3",
"setlayer_obj_4",
};
public void LuaRegister(Lua lua)
{
lua.RegisterFunction("print", this, GetType().GetMethod("print"));
@ -310,13 +240,40 @@ namespace BizHawk.MultiClient
Docs.Add(BitLuaLibrary.Name, funcName, method);
}
//Register libraries
lua.NewTable("console");
foreach (string t in ConsoleFunctions)
lua.NewTable("client");
foreach (var funcName in MultiClientLuaLibrary.Functions)
{
lua.RegisterFunction("console." + t, this,
GetType().GetMethod("console_" + t));
Docs.Add("console", t, GetType().GetMethod("console_" + t));
string libName = MultiClientLuaLibrary.Name + "." + funcName;
var method = (typeof(MultiClientLuaLibrary)).GetMethod(MultiClientLuaLibrary.Name + "_" + funcName);
lua.RegisterFunction(libName, this, method);
Docs.Add(MultiClientLuaLibrary.Name, funcName, method);
}
lua.NewTable("console");
foreach (var funcName in ConsoleLuaLibrary.Functions)
{
string libName = ConsoleLuaLibrary.Name + "." + funcName;
var method = (typeof(ConsoleLuaLibrary)).GetMethod(ConsoleLuaLibrary.Name + "_" + funcName);
lua.RegisterFunction(libName, this, method);
Docs.Add(ConsoleLuaLibrary.Name, funcName, method);
}
lua.NewTable("nes");
foreach (var funcName in NESLuaLibrary.Functions)
{
string libName = NESLuaLibrary.Name + "." + funcName;
var method = (typeof(NESLuaLibrary)).GetMethod(NESLuaLibrary.Name + "_" + funcName);
lua.RegisterFunction(libName, this, method);
Docs.Add(NESLuaLibrary.Name, funcName, method);
}
lua.NewTable("snes");
foreach (var funcName in SNESLuaLibrary.Functions)
{
string libName = SNESLuaLibrary.Name + "." + funcName;
var method = (typeof(SNESLuaLibrary)).GetMethod(SNESLuaLibrary.Name + "_" + funcName);
lua.RegisterFunction(libName, this, method);
Docs.Add(SNESLuaLibrary.Name, funcName, method);
}
lua.NewTable("gui");
@ -377,14 +334,6 @@ namespace BizHawk.MultiClient
Docs.Add("joypad", t, GetType().GetMethod("joypad_" + t));
}
lua.NewTable("client");
foreach (string t in MultiClientFunctions)
{
lua.RegisterFunction("client." + t, this,
GetType().GetMethod("client_" + t));
Docs.Add("client", t, GetType().GetMethod("client_" + t));
}
lua.NewTable("forms");
foreach (string t in FormsFunctions)
{
@ -392,20 +341,6 @@ namespace BizHawk.MultiClient
Docs.Add("forms", t, GetType().GetMethod("forms_" + t));
}
lua.NewTable("nes");
foreach (string t in NESFunctions)
{
lua.RegisterFunction("nes." + t, this, GetType().GetMethod("nes_" + t));
Docs.Add("nes", t, GetType().GetMethod("nes_" + t));
}
lua.NewTable("snes");
foreach (string t in SNESFunctions)
{
lua.RegisterFunction("snes." + t, this, GetType().GetMethod("snes_" + t));
Docs.Add("snes", t, GetType().GetMethod("snes_" + t));
}
lua.NewTable("event");
foreach (string t in EventFunctions)
{