EmuLuaLibrary.Events - cleanup
This commit is contained in:
parent
a0ba2189af
commit
ce2a7b1612
|
@ -23,8 +23,6 @@ namespace BizHawk.Client.Common
|
||||||
[OptionalService]
|
[OptionalService]
|
||||||
private IMemoryDomains Domains { get; set; }
|
private IMemoryDomains Domains { get; set; }
|
||||||
|
|
||||||
private readonly LuaFunctionList _luaFunctions = new LuaFunctionList();
|
|
||||||
|
|
||||||
public EventLuaLibrary(Lua lua)
|
public EventLuaLibrary(Lua lua)
|
||||||
: base(lua) { }
|
: base(lua) { }
|
||||||
|
|
||||||
|
@ -37,18 +35,18 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void CallExitEvent(Lua thread)
|
public void CallExitEvent(Lua thread)
|
||||||
{
|
{
|
||||||
var exitCallbacks = _luaFunctions.Where(l => l.Lua == thread && l.Event == "OnExit");
|
var exitCallbacks = RegisteredFunctions.Where(l => l.Lua == thread && l.Event == "OnExit");
|
||||||
foreach (var exitCallback in exitCallbacks)
|
foreach (var exitCallback in exitCallbacks)
|
||||||
{
|
{
|
||||||
exitCallback.Call();
|
exitCallback.Call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuaFunctionList RegisteredFunctions => _luaFunctions;
|
public LuaFunctionList RegisteredFunctions { get; } = new LuaFunctionList();
|
||||||
|
|
||||||
public void CallSaveStateEvent(string name)
|
public void CallSaveStateEvent(string name)
|
||||||
{
|
{
|
||||||
var lfs = _luaFunctions.Where(l => l.Event == "OnSavestateSave");
|
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateSave");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var lf in lfs)
|
foreach (var lf in lfs)
|
||||||
|
@ -64,7 +62,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void CallLoadStateEvent(string name)
|
public void CallLoadStateEvent(string name)
|
||||||
{
|
{
|
||||||
var lfs = _luaFunctions.Where(l => l.Event == "OnSavestateLoad");
|
var lfs = RegisteredFunctions.Where(l => l.Event == "OnSavestateLoad");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var lf in lfs)
|
foreach (var lf in lfs)
|
||||||
|
@ -80,7 +78,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void CallFrameBeforeEvent()
|
public void CallFrameBeforeEvent()
|
||||||
{
|
{
|
||||||
var lfs = _luaFunctions.Where(l => l.Event == "OnFrameStart");
|
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameStart");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var lf in lfs)
|
foreach (var lf in lfs)
|
||||||
|
@ -96,7 +94,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void CallFrameAfterEvent()
|
public void CallFrameAfterEvent()
|
||||||
{
|
{
|
||||||
var lfs = _luaFunctions.Where(l => l.Event == "OnFrameEnd");
|
var lfs = RegisteredFunctions.Where(l => l.Event == "OnFrameEnd");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var lf in lfs)
|
foreach (var lf in lfs)
|
||||||
|
@ -128,7 +126,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnFrameEnd(LuaFunction luaf, string name = null)
|
public string OnFrameEnd(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnFrameEnd", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnFrameEnd", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
return nlf.Guid.ToString();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +135,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnFrameStart(LuaFunction luaf, string name = null)
|
public string OnFrameStart(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnFrameStart", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnFrameStart", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
return nlf.Guid.ToString();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +144,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnInputPoll(LuaFunction luaf, string name = null)
|
public string OnInputPoll(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnInputPoll", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnInputPoll", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
|
|
||||||
if (InputPollableCore != null)
|
if (InputPollableCore != null)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +174,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnLoadState(LuaFunction luaf, string name = null)
|
public string OnLoadState(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnSavestateLoad", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnSavestateLoad", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
return nlf.Guid.ToString();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +188,7 @@ namespace BizHawk.Client.Common
|
||||||
DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
|
DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryExecute", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(domain))
|
if (string.IsNullOrWhiteSpace(domain))
|
||||||
{
|
{
|
||||||
|
@ -224,7 +222,7 @@ namespace BizHawk.Client.Common
|
||||||
if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable())
|
if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable())
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryRead", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(domain))
|
if (string.IsNullOrWhiteSpace(domain))
|
||||||
{
|
{
|
||||||
|
@ -258,7 +256,7 @@ namespace BizHawk.Client.Common
|
||||||
if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable())
|
if (DebuggableCore != null && DebuggableCore.MemoryCallbacksAvailable())
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnMemoryWrite", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(domain))
|
if (string.IsNullOrWhiteSpace(domain))
|
||||||
{
|
{
|
||||||
|
@ -288,7 +286,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnSaveState(LuaFunction luaf, string name = null)
|
public string OnSaveState(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnSavestateSave", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnSavestateSave", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
return nlf.Guid.ToString();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +295,7 @@ namespace BizHawk.Client.Common
|
||||||
public string OnExit(LuaFunction luaf, string name = null)
|
public string OnExit(LuaFunction luaf, string name = null)
|
||||||
{
|
{
|
||||||
var nlf = new NamedLuaFunction(luaf, "OnExit", LogOutputCallback, CurrentThread, name);
|
var nlf = new NamedLuaFunction(luaf, "OnExit", LogOutputCallback, CurrentThread, name);
|
||||||
_luaFunctions.Add(nlf);
|
RegisteredFunctions.Add(nlf);
|
||||||
return nlf.Guid.ToString();
|
return nlf.Guid.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,9 +303,9 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("unregisterbyid", "Removes the registered function that matches the guid. If a function is found and remove the function will return true. If unable to find a match, the function will return false.")]
|
[LuaMethod("unregisterbyid", "Removes the registered function that matches the guid. If a function is found and remove the function will return true. If unable to find a match, the function will return false.")]
|
||||||
public bool UnregisterById(string guid)
|
public bool UnregisterById(string guid)
|
||||||
{
|
{
|
||||||
foreach (var nlf in _luaFunctions.Where(nlf => nlf.Guid.ToString() == guid.ToString()))
|
foreach (var nlf in RegisteredFunctions.Where(nlf => nlf.Guid.ToString() == guid))
|
||||||
{
|
{
|
||||||
_luaFunctions.Remove(nlf);
|
RegisteredFunctions.Remove(nlf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,9 +316,9 @@ namespace BizHawk.Client.Common
|
||||||
[LuaMethod("unregisterbyname", "Removes the first registered function that matches Name. If a function is found and remove the function will return true. If unable to find a match, the function will return false.")]
|
[LuaMethod("unregisterbyname", "Removes the first registered function that matches Name. If a function is found and remove the function will return true. If unable to find a match, the function will return false.")]
|
||||||
public bool UnregisterByName(string name)
|
public bool UnregisterByName(string name)
|
||||||
{
|
{
|
||||||
foreach (var nlf in _luaFunctions.Where(nlf => nlf.Name == name))
|
foreach (var nlf in RegisteredFunctions.Where(nlf => nlf.Name == name))
|
||||||
{
|
{
|
||||||
_luaFunctions.Remove(nlf);
|
RegisteredFunctions.Remove(nlf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,6 +315,7 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpause/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpause/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpaused/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpaused/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpausing/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpausing/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unregister/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottle/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottle/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottled/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottled/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=vals/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=vals/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|
Loading…
Reference in New Issue