Migrate SavestateLuaLibrary to ApiHawk delegation

includes backwards-compatible API change
This commit is contained in:
YoshiRulz 2019-12-15 04:39:16 +10:00
parent cc8dffa769
commit f8dc18c1bd
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 27 additions and 47 deletions

View File

@ -2,9 +2,9 @@
{
public interface ISaveState : IExternalApi
{
void Load(string path);
void LoadSlot(int slotNum);
void Save(string path);
void SaveSlot(int slotNum);
void Load(string path, bool suppressOSD = false);
void LoadSlot(int slotNum, bool suppressOSD = false);
void Save(string path, bool suppressOSD = false);
void SaveSlot(int slotNum, bool suppressOSD = false);
}
}

View File

@ -9,39 +9,45 @@ namespace BizHawk.Client.EmuHawk
{
public sealed class SaveStateApi : ISaveState
{
public SaveStateApi() : base()
{ }
public SaveStateApi(Action<string> logCallback)
{
LogCallback = logCallback;
}
public void Load(string path)
public SaveStateApi() : this(Console.WriteLine) {}
private readonly Action<string> LogCallback;
public void Load(string path, bool suppressOSD)
{
if (!File.Exists(path))
{
Console.WriteLine($"could not find file: {path}");
LogCallback($"could not find file: {path}");
}
else
{
GlobalWin.MainForm.LoadState(path, Path.GetFileName(path), true);
GlobalWin.MainForm.LoadState(path, Path.GetFileName(path), true, suppressOSD);
}
}
public void LoadSlot(int slotNum)
public void LoadSlot(int slotNum, bool suppressOSD)
{
if (slotNum >= 0 && slotNum <= 9)
{
GlobalWin.MainForm.LoadQuickSave($"QuickSave{slotNum}", true);
GlobalWin.MainForm.LoadQuickSave($"QuickSave{slotNum}", true, suppressOSD);
}
}
public void Save(string path)
public void Save(string path, bool suppressOSD)
{
GlobalWin.MainForm.SaveState(path, path, true);
GlobalWin.MainForm.SaveState(path, path, true, suppressOSD);
}
public void SaveSlot(int slotNum)
public void SaveSlot(int slotNum, bool suppressOSD)
{
if (slotNum >= 0 && slotNum <= 9)
{
GlobalWin.MainForm.SaveQuickSave($"QuickSave{slotNum}");
GlobalWin.MainForm.SaveQuickSave($"QuickSave{slotNum}", true, suppressOSD);
}
}
}

View File

@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using NLua;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public sealed class SavestateLuaLibrary : LuaLibraryBase
public sealed class SavestateLuaLibrary : DelegatingLuaLibraryEmu
{
public SavestateLuaLibrary(Lua lua)
: base(lua) { }
@ -19,43 +18,18 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodExample("savestate.load( \"C:\\state.bin\" );")]
[LuaMethod("load", "Loads a savestate with the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
public void Load(string path, bool suppressOSD = false)
{
if (!File.Exists(path))
{
Log($"could not find file: {path}");
}
else
{
GlobalWin.MainForm.LoadState(path, Path.GetFileName(path), true, suppressOSD);
}
}
public void Load(string path, bool suppressOSD = false) => APIs.SaveState.Load(path, suppressOSD);
[LuaMethodExample("savestate.loadslot( 7 );")]
[LuaMethod("loadslot", "Loads the savestate at the given slot number (must be an integer between 0 and 9). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
public void LoadSlot(int slotNum, bool suppressOSD = false)
{
if (slotNum >= 0 && slotNum <= 9)
{
GlobalWin.MainForm.LoadQuickSave($"QuickSave{slotNum}", true, suppressOSD);
}
}
public void LoadSlot(int slotNum, bool suppressOSD = false) => APIs.SaveState.LoadSlot(slotNum, suppressOSD);
[LuaMethodExample("savestate.save( \"C:\\state.bin\" );")]
[LuaMethod("save", "Saves a state at the given path. If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes (and the path is ignored).")]
public void Save(string path, bool suppressOSD = false)
{
GlobalWin.MainForm.SaveState(path, path, true, suppressOSD);
}
public void Save(string path, bool suppressOSD = false) => APIs.SaveState.Save(path, suppressOSD);
[LuaMethodExample("savestate.saveslot( 7 );")]
[LuaMethod("saveslot", "Saves a state at the given save slot (must be an integer between 0 and 9). If EmuHawk is deferring quicksaves, to TAStudio for example, that form will do what it likes with the slot number.")]
public void SaveSlot(int slotNum, bool suppressOSD = false)
{
if (slotNum >= 0 && slotNum <= 9)
{
GlobalWin.MainForm.SaveQuickSave($"QuickSave{slotNum}", true, suppressOSD);
}
}
public void SaveSlot(int slotNum, bool suppressOSD = false) => APIs.SaveState.SaveSlot(slotNum, suppressOSD);
}
}