Merge `IGameInfoApi` into `IEmulationApi`

This commit is contained in:
YoshiRulz 2022-03-01 11:22:35 +10:00
parent e8b3f5ffef
commit b82ac3e2de
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 28 additions and 7 deletions

View File

@ -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)];

View File

@ -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<string, string?> GetGameOptions()
=> _game == null
? new Dictionary<string, string?>()
: ((GameInfo) _game).GetOptions().ToDictionary(static kvp => kvp.Key, static kvp => (string?) kvp.Value);
public object? GetSettings() => Emulator switch
{
GPGX gpgx => gpgx.GetSettings(),

View File

@ -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]

View File

@ -24,6 +24,11 @@ namespace BizHawk.Client.Common
void MinimizeFrameskip(bool enabled);
string GetDisplayType();
string GetBoardName();
IGameInfo? GetGameInfo();
IReadOnlyDictionary<string, string?> GetGameOptions();
object? GetSettings();
PutSettingsDirtyBits PutSettings(object settings);
void SetRenderPlanes(params bool[] args);

View File

@ -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();

View File

@ -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());
}
}