2013-10-28 20:57:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2014-12-04 00:43:12 +00:00
|
|
|
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
|
|
|
|
|
2013-10-28 19:13:01 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public class LuaFunctionList : List<NamedLuaFunction>
|
|
|
|
|
{
|
2019-11-29 21:02:40 +00:00
|
|
|
|
public NamedLuaFunction this[string guid] =>
|
|
|
|
|
this.FirstOrDefault(nlf => nlf.Guid.ToString() == guid);
|
2013-11-10 19:19:58 +00:00
|
|
|
|
|
2013-12-19 01:02:50 +00:00
|
|
|
|
public new bool Remove(NamedLuaFunction function)
|
2013-11-10 19:19:58 +00:00
|
|
|
|
{
|
2015-10-18 00:03:07 +00:00
|
|
|
|
if (Global.Emulator.InputCallbacksAvailable())
|
2014-12-04 00:43:12 +00:00
|
|
|
|
{
|
2014-12-05 00:59:00 +00:00
|
|
|
|
Global.Emulator.AsInputPollable().InputCallbacks.Remove(function.Callback);
|
2014-12-04 00:43:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 00:03:07 +00:00
|
|
|
|
if (Global.Emulator.MemoryCallbacksAvailable())
|
2014-12-05 01:56:45 +00:00
|
|
|
|
{
|
2019-01-24 11:11:25 +00:00
|
|
|
|
Global.Emulator.AsDebuggable().MemoryCallbacks.Remove(function.MemCallback);
|
2014-12-05 01:56:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 01:02:50 +00:00
|
|
|
|
return base.Remove(function);
|
2013-11-10 19:19:58 +00:00
|
|
|
|
}
|
2013-11-10 21:56:02 +00:00
|
|
|
|
|
2019-11-29 21:02:40 +00:00
|
|
|
|
public void RemoveForFile(LuaFile file)
|
|
|
|
|
{
|
|
|
|
|
var functionsToRemove = this
|
|
|
|
|
.ForFile(file)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var function in functionsToRemove)
|
|
|
|
|
{
|
|
|
|
|
Remove(function);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-21 23:16:16 +00:00
|
|
|
|
public new void Clear()
|
2013-11-10 21:56:02 +00:00
|
|
|
|
{
|
2015-10-12 23:02:03 +00:00
|
|
|
|
if (Global.Emulator.InputCallbacksAvailable())
|
2014-12-04 00:43:12 +00:00
|
|
|
|
{
|
2017-05-18 16:36:38 +00:00
|
|
|
|
Global.Emulator.AsInputPollable().InputCallbacks.RemoveAll(this.Select(w => w.Callback));
|
2014-12-04 00:43:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 23:02:03 +00:00
|
|
|
|
if (Global.Emulator.MemoryCallbacksAvailable())
|
2014-12-05 01:56:45 +00:00
|
|
|
|
{
|
2017-04-14 19:59:01 +00:00
|
|
|
|
var memoryCallbacks = Global.Emulator.AsDebuggable().MemoryCallbacks;
|
2019-01-24 11:11:25 +00:00
|
|
|
|
memoryCallbacks.RemoveAll(this.Select(w => w.MemCallback));
|
2014-12-05 01:56:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-21 23:16:16 +00:00
|
|
|
|
base.Clear();
|
2013-11-10 21:56:02 +00:00
|
|
|
|
}
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
2019-11-29 21:02:40 +00:00
|
|
|
|
|
|
|
|
|
public static class LuaFunctionListExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IEnumerable<NamedLuaFunction> ForFile(this IEnumerable<NamedLuaFunction> list, LuaFile luaFile)
|
|
|
|
|
{
|
|
|
|
|
return list
|
2019-11-29 21:11:40 +00:00
|
|
|
|
.Where(l => l.LuaFile.Path == luaFile.Path
|
|
|
|
|
|| l.LuaFile.Thread == luaFile.Thread);
|
2019-11-29 21:02:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<NamedLuaFunction> ForEvent(this IEnumerable<NamedLuaFunction> list, string eventName)
|
|
|
|
|
{
|
|
|
|
|
return list.Where(l => l.Event == eventName);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|