From 8e241067e6e417c5cbaa119d5c6953c4a3b9ebaf Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Fri, 3 Feb 2012 12:18:27 +0000 Subject: [PATCH] Lua - hook up savestate library and implement saveslot() and loadslot() methods --- BizHawk.MultiClient/LuaImplementation.cs | 70 ++++++++++++++++++------ BizHawk.MultiClient/MainForm.cs | 6 +- BizHawk.MultiClient/tools/LuaConsole.cs | 2 +- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index 5ef3cee83b..f5d68bd88f 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -31,8 +31,8 @@ namespace BizHawk.MultiClient public void Close() { - LuaKillThread(); lua.Close(); + LuaKillThread(); LuaWait.Dispose(); } @@ -79,8 +79,8 @@ namespace BizHawk.MultiClient lua.NewTable("savestate"); for (int i = 0; i < SaveStateFunctions.Length; i++) { - //lua.RegisterFunction("statestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); - //LuaLibraryList += "savestate." + SaveStateFunctions[i] + "\n"; + lua.RegisterFunction("savestate." + SaveStateFunctions[i], this, this.GetType().GetMethod("savestate_" + SaveStateFunctions[i])); + LuaLibraryList += "savestate." + SaveStateFunctions[i] + "\n"; } lua.NewTable("movie"); @@ -110,7 +110,8 @@ namespace BizHawk.MultiClient isRunning = true; try { - lua.DoFile(F); + if (LuaThread != null) + lua.DoFile(F); } catch (Exception e) { @@ -119,11 +120,12 @@ namespace BizHawk.MultiClient isRunning = false; LuaWait.Set(); } - public void LuaKillThread() - { - if (LuaThread != null) - LuaThread.Abort(); - } + + public void LuaKillThread() + { + if (LuaThread != null) + LuaThread.Abort(); + } public void DoLuaFile(string File) { @@ -204,19 +206,21 @@ namespace BizHawk.MultiClient }; public static string[] SaveStateFunctions = new string[] { - //"create", + "saveslot", + "loadslot", "save", "load" - //"write" }; + public static string[] MovieFunctions = new string[] { "mode", "rerecordcount", "stop" }; + public static string[] JoypadFunctions = new string[] { - "set", - //"get", + "set" + //"get" }; public static string[] MultiClientFunctions = new string[] { @@ -272,9 +276,6 @@ namespace BizHawk.MultiClient return; } - if (y.GetType() != typeof(int)) - return; - Global.MainForm.LuaConsole1.WriteToOutputWindow(lua_input.ToString()); Global.RenderPanel.AddGUIText(lua_input.ToString(), x, y); } @@ -412,6 +413,43 @@ namespace BizHawk.MultiClient //---------------------------------------------------- //Savestate library //---------------------------------------------------- + public void savestate_saveslot(object lua_input) + { + int x = 0; + + try //adelikat: This crap might not be necessary, need to test for a more elegant solution + { + x = int.Parse(lua_input.ToString()); + } + catch + { + return; + } + + if (x < 0 || x > 9) + return; + + Global.MainForm.SaveState("QuickSave" + x.ToString()); + } + + public void savestate_loadslot(object lua_input) + { + int x = 0; + + try //adelikat: This crap might not be necessary, need to test for a more elegant solution + { + x = int.Parse(lua_input.ToString()); + } + catch + { + return; + } + + if (x < 0 || x > 9) + return; + + Global.MainForm.LoadState("QuickLoad" + x.ToString()); + } public void savestate_save(object lua_input) { diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index c31d59df07..f487d447f3 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -118,7 +118,7 @@ namespace BizHawk.MultiClient Global.CheatList.SaveSettings(); CloseGame(); Global.MovieSession.Movie.StopMovie(); - SaveConfig(); + SaveConfig(); }; ResizeBegin += (o, e) => @@ -1790,7 +1790,7 @@ namespace BizHawk.MultiClient MakeScreenshot(String.Format(PathManager.ScreenshotPrefix(Global.Game) + ".{0:yyyy-MM-dd HH.mm.ss}.png", DateTime.Now)); } - private void SaveState(string name) + public void SaveState(string name) { string path = PathManager.SaveStatePrefix(Global.Game) + "." + name + ".State"; @@ -1874,7 +1874,7 @@ namespace BizHawk.MultiClient Global.RenderPanel.AddMessage("Loadstate error!"); } - private void LoadState(string name) + public void LoadState(string name) { string path = PathManager.SaveStatePrefix(Global.Game) + "." + name + ".State"; if (File.Exists(path) == false) diff --git a/BizHawk.MultiClient/tools/LuaConsole.cs b/BizHawk.MultiClient/tools/LuaConsole.cs index 71a344389f..d6e5d0ba1e 100644 --- a/BizHawk.MultiClient/tools/LuaConsole.cs +++ b/BizHawk.MultiClient/tools/LuaConsole.cs @@ -93,7 +93,7 @@ namespace BizHawk.MultiClient private void StopAllScripts() { for (int x = 0; x < luaList.Count; x++) - luaList[x].Enabled = false; + luaList[x].Enabled = false; LuaImp.Close(); LuaImp = new LuaImplementation(this); }