Skip to content

Commit

Permalink
Add prop IToolApi.AvailableTools and use in ClientLuaLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Nov 26, 2020
1 parent 2e428cc commit 939cd1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/BizHawk.Client.Common/Api/Interfaces/IToolApi.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;

namespace BizHawk.Client.Common
{
public interface IToolApi : IExternalApi
{
IEnumerable<Type> AvailableTools { get; }
Type GetTool(string name);
object CreateInstance(string name);
void OpenCheats();
Expand Down
3 changes: 3 additions & 0 deletions src/BizHawk.Client.EmuHawk/Api/Libraries/ToolApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;

using BizHawk.Client.Common;
Expand All @@ -8,6 +9,8 @@ namespace BizHawk.Client.EmuHawk
{
public sealed class ToolApi : IToolApi
{
public IEnumerable<Type> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 939cd1b

Please sign in to comment.