diff --git a/src/BizHawk.Client.Common/Api/ApiContainer.cs b/src/BizHawk.Client.Common/Api/ApiContainer.cs index 14f3cd7f8f..c9f6f0536b 100644 --- a/src/BizHawk.Client.Common/Api/ApiContainer.cs +++ b/src/BizHawk.Client.Common/Api/ApiContainer.cs @@ -12,7 +12,10 @@ namespace BizHawk.Client.Common public ICommApi Comm => (ICommApi) Libraries[typeof(ICommApi)]; public IEmuClientApi EmuClient => (IEmuClientApi) Libraries[typeof(IEmuClientApi)]; public IEmulationApi Emulation => (IEmulationApi) Libraries[typeof(IEmulationApi)]; + + [Obsolete("use Emulation")] public IGameInfoApi GameInfo => (IGameInfoApi) Libraries[typeof(IGameInfoApi)]; + public IGuiApi Gui => (IGuiApi) Libraries[typeof(IGuiApi)]; public IInputApi Input => (IInputApi) Libraries[typeof(IInputApi)]; public IJoypadApi Joypad => (IJoypadApi) Libraries[typeof(IJoypadApi)]; diff --git a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs index 35b26b5144..9cc0587be9 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using BizHawk.Common; using BizHawk.Emulation.Common; @@ -186,6 +187,14 @@ namespace BizHawk.Client.Common public string GetBoardName() => BoardInfo?.BoardName ?? ""; + public IGameInfo? GetGameInfo() + => _game; + + public IReadOnlyDictionary GetGameOptions() + => _game == null + ? new Dictionary() + : ((GameInfo) _game).GetOptions().ToDictionary(static kvp => kvp.Key, static kvp => (string?) kvp.Value); + public object? GetSettings() => Emulator switch { GPGX gpgx => gpgx.GetSettings(), diff --git a/src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs b/src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs index 3446f88393..6e6dedc5f0 100644 --- a/src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs @@ -1,5 +1,6 @@ #nullable enable +using System; using System.Collections.Generic; using BizHawk.Common; @@ -7,6 +8,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Client.Common { + [Obsolete("use IEmulationApi")] public sealed class GameInfoApi : IGameInfoApi { [OptionalService] diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs index 760ae2fee7..177c73223a 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs @@ -24,6 +24,11 @@ namespace BizHawk.Client.Common void MinimizeFrameskip(bool enabled); string GetDisplayType(); string GetBoardName(); + + IGameInfo? GetGameInfo(); + + IReadOnlyDictionary GetGameOptions(); + object? GetSettings(); PutSettingsDirtyBits PutSettings(object settings); void SetRenderPlanes(params bool[] args); diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs index 59ed328ffa..b08c03bd35 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs @@ -1,11 +1,13 @@ #nullable enable +using System; using System.Collections.Generic; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common { + [Obsolete("use IEmulationApi")] public interface IGameInfoApi : IExternalApi { string GetBoardType(); diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs index 46db66bb30..ce065e53d8 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs @@ -18,36 +18,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() - => APIs.GameInfo.GetGameInfo()?.Name ?? string.Empty; + => APIs.Emulation.GetGameInfo()?.Name ?? string.Empty; [LuaMethodExample("local stgamget = gameinfo.getromhash( );")] [LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")] public string GetRomHash() - => APIs.GameInfo.GetGameInfo()?.Hash ?? string.Empty; + => APIs.Emulation.GetGameInfo()?.Hash ?? string.Empty; [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() - => APIs.GameInfo.GetGameInfo()?.NotInDatabase is false; + => APIs.Emulation.GetGameInfo()?.NotInDatabase is false; [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() - => (APIs.GameInfo.GetGameInfo()?.Status)?.ToString(); + => (APIs.Emulation.GetGameInfo()?.Status)?.ToString(); [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() - => APIs.GameInfo.GetGameInfo()?.IsRomStatusBad() is true or null; + => APIs.Emulation.GetGameInfo()?.IsRomStatusBad() is true or null; [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() - => APIs.GameInfo.GetBoardType(); + => APIs.Emulation.GetBoardName(); [LuaMethodExample("local nlgamget = gameinfo.getoptions( );")] [LuaMethod("getoptions", "returns the game options for the currently loaded rom. Options vary per platform")] public LuaTable GetOptions() - => _th.DictToTable(APIs.GameInfo.GetOptions()); + => _th.DictToTable(APIs.Emulation.GetGameOptions()); } }