From 939cd1bcaf35f2597b8e7d59cad63a9370411bef Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 26 Nov 2020 22:12:12 +1000 Subject: [PATCH] Add prop IToolApi.AvailableTools and use in ClientLuaLibrary --- src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs | 3 +++ src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs | 3 +++ .../tools/Lua/Libraries/ClientLuaLibrary.cs | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs index f41fbbb388b..37b3e0eaa75 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs @@ -1,8 +1,11 @@ using System; +using System.Collections.Generic; + namespace BizHawk.Client.Common { public interface IToolApi : IExternalApi { + IEnumerable AvailableTools { get; } Type GetTool(string name); object CreateInstance(string name); void OpenCheats(); diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs index dbb8904879f..ea10aa79c7a 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using BizHawk.Client.Common; @@ -8,6 +9,8 @@ namespace BizHawk.Client.EmuHawk { public sealed class ToolApi : IToolApi { + public IEnumerable AvailableTools => GlobalWin.Tools.AvailableTools.ToList(); // defensive copy in case ToolManager's implementation changes + public Type GetTool(string name) { var toolType = Util.GetTypeByName(name).FirstOrDefault(x => typeof(IToolForm).IsAssignableFrom(x) && !x.IsInterface); diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs index 487cd19d244..b6ddbf78e66 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/ClientLuaLibrary.cs @@ -295,7 +295,7 @@ public static string GetVersion() [LuaMethodExample("local nlcliget = client.getavailabletools( );")] [LuaMethod("getavailabletools", "Returns a list of the tools currently open")] - public LuaTable GetAvailableTools() => GlobalWin.Tools.AvailableTools.Select(tool => tool.Name.ToLower()).EnumerateToLuaTable(Lua); + public LuaTable GetAvailableTools() => APIs.Tool.AvailableTools.Select(tool => tool.Name.ToLower()).EnumerateToLuaTable(Lua); [LuaMethodExample("local nlcliget = client.gettool( \"Tool name\" );")] [LuaMethod("gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use gettools to get a list of names")]