diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs index 5c846844ed..c89338dd0e 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.GameInfo.cs @@ -7,11 +7,8 @@ using BizHawk.Emulation.Common; // ReSharper disable UnusedAutoPropertyAccessor.Local namespace BizHawk.Client.Common { - public sealed class GameInfoLuaLibrary : LuaLibraryBase + public sealed class GameInfoLuaLibrary : DelegatingLuaLibrary { - [OptionalService] - private IBoardInfo BoardInfo { get; set; } - public GameInfoLuaLibrary(Lua lua) : base(lua) { } @@ -22,66 +19,36 @@ namespace BizHawk.Client.Common [LuaMethodExample("local stgamget = gameinfo.getromname( );")] [LuaMethod("getromname", "returns the name of the currently loaded rom, if a rom is loaded")] - public string GetRomName() - { - return Global.Game?.Name ?? ""; - } + public string GetRomName() => APIs.GameInfo.GetRomName(); [LuaMethodExample("local stgamget = gameinfo.getromhash( );")] [LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")] - public string GetRomHash() - { - return Global.Game?.Hash ?? ""; - } + public string GetRomHash() => APIs.GameInfo.GetRomHash(); [LuaMethodExample("if ( gameinfo.indatabase( ) ) then\r\n\tconsole.log( \"returns whether or not the currently loaded rom is in the game database\" );\r\nend;")] [LuaMethod("indatabase", "returns whether or not the currently loaded rom is in the game database")] - public bool InDatabase() - { - if (Global.Game != null) - { - return !Global.Game.NotInDatabase; - } - - return false; - } + public bool InDatabase() => APIs.GameInfo.InDatabase(); [LuaMethodExample("local stgamget = gameinfo.getstatus( );")] [LuaMethod("getstatus", "returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase")] - public string GetStatus() - { - return Global.Game?.Status.ToString(); - } + public string GetStatus() => APIs.GameInfo.GetStatus(); [LuaMethodExample("if ( gameinfo.isstatusbad( ) ) then\r\n\tconsole.log( \"returns the currently loaded rom's game database status is considered 'bad'\" );\r\nend;")] [LuaMethod("isstatusbad", "returns the currently loaded rom's game database status is considered 'bad'")] - public bool IsStatusBad() - { - return Global.Game?.IsRomStatusBad() ?? true; - } + public bool IsStatusBad() => APIs.GameInfo.IsStatusBad(); [LuaMethodExample("local stgamget = gameinfo.getboardtype( );")] [LuaMethod("getboardtype", "returns identifying information about the 'mapper' or similar capability used for this game. empty if no such useful distinction can be drawn")] - public string GetBoardType() - { - return BoardInfo?.BoardName ?? ""; - } + public string GetBoardType() => APIs.GameInfo.GetBoardType(); [LuaMethodExample("local nlgamget = gameinfo.getoptions( );")] [LuaMethod("getoptions", "returns the game options for the currently loaded rom. Options vary per platform")] public LuaTable GetOptions() { - var options = Lua.NewTable(); - - if (Global.Game != null) - { - foreach (var option in Global.Game.GetOptionsDict()) - { - options[option.Key] = option.Value; - } - } - - return options; + var dict = APIs.GameInfo.GetOptions(); + var table = Lua.NewTable(); + foreach (var kvp in dict) table[kvp.Key] = kvp.Value; + return table; } } }