Skip to content

Commit b82ac3e

Browse files
committed
Merge IGameInfoApi into IEmulationApi
1 parent e8b3f5f commit b82ac3e

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

src/BizHawk.Client.Common/Api/ApiContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public sealed class ApiContainer : IDisposable
1212
public ICommApi Comm => (ICommApi) Libraries[typeof(ICommApi)];
1313
public IEmuClientApi EmuClient => (IEmuClientApi) Libraries[typeof(IEmuClientApi)];
1414
public IEmulationApi Emulation => (IEmulationApi) Libraries[typeof(IEmulationApi)];
15+
16+
[Obsolete("use Emulation")]
1517
public IGameInfoApi GameInfo => (IGameInfoApi) Libraries[typeof(IGameInfoApi)];
18+
1619
public IGuiApi Gui => (IGuiApi) Libraries[typeof(IGuiApi)];
1720
public IInputApi Input => (IInputApi) Libraries[typeof(IInputApi)];
1821
public IJoypadApi Joypad => (IJoypadApi) Libraries[typeof(IJoypadApi)];

src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.ComponentModel;
6+
using System.Linq;
67

78
using BizHawk.Common;
89
using BizHawk.Emulation.Common;
@@ -186,6 +187,14 @@ public void SetLagCount(int count)
186187

187188
public string GetBoardName() => BoardInfo?.BoardName ?? "";
188189

190+
public IGameInfo? GetGameInfo()
191+
=> _game;
192+
193+
public IReadOnlyDictionary<string, string?> GetGameOptions()
194+
=> _game == null
195+
? new Dictionary<string, string?>()
196+
: ((GameInfo) _game).GetOptions().ToDictionary(static kvp => kvp.Key, static kvp => (string?) kvp.Value);
197+
189198
public object? GetSettings() => Emulator switch
190199
{
191200
GPGX gpgx => gpgx.GetSettings(),

src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#nullable enable
22

3+
using System;
34
using System.Collections.Generic;
45

56
using BizHawk.Common;
67
using BizHawk.Emulation.Common;
78

89
namespace BizHawk.Client.Common
910
{
11+
[Obsolete("use IEmulationApi")]
1012
public sealed class GameInfoApi : IGameInfoApi
1113
{
1214
[OptionalService]

src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public interface IEmulationApi : IExternalApi
2424
void MinimizeFrameskip(bool enabled);
2525
string GetDisplayType();
2626
string GetBoardName();
27+
28+
IGameInfo? GetGameInfo();
29+
30+
IReadOnlyDictionary<string, string?> GetGameOptions();
31+
2732
object? GetSettings();
2833
PutSettingsDirtyBits PutSettings(object settings);
2934
void SetRenderPlanes(params bool[] args);

src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#nullable enable
22

3+
using System;
34
using System.Collections.Generic;
45

56
using BizHawk.Emulation.Common;
67

78
namespace BizHawk.Client.Common
89
{
10+
[Obsolete("use IEmulationApi")]
911
public interface IGameInfoApi : IExternalApi
1012
{
1113
string GetBoardType();

src/BizHawk.Client.Common/lua/CommonLibs/GameInfoLuaLibrary.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,36 @@ public GameInfoLuaLibrary(IPlatformLuaLibEnv luaLibsImpl, ApiContainer apiContai
1818
[LuaMethodExample("local stgamget = gameinfo.getromname( );")]
1919
[LuaMethod("getromname", "returns the name of the currently loaded rom, if a rom is loaded")]
2020
public string GetRomName()
21-
=> APIs.GameInfo.GetGameInfo()?.Name ?? string.Empty;
21+
=> APIs.Emulation.GetGameInfo()?.Name ?? string.Empty;
2222

2323
[LuaMethodExample("local stgamget = gameinfo.getromhash( );")]
2424
[LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")]
2525
public string GetRomHash()
26-
=> APIs.GameInfo.GetGameInfo()?.Hash ?? string.Empty;
26+
=> APIs.Emulation.GetGameInfo()?.Hash ?? string.Empty;
2727

2828
[LuaMethodExample("if ( gameinfo.indatabase( ) ) then\r\n\tconsole.log( \"returns whether or not the currently loaded rom is in the game database\" );\r\nend;")]
2929
[LuaMethod("indatabase", "returns whether or not the currently loaded rom is in the game database")]
3030
public bool InDatabase()
31-
=> APIs.GameInfo.GetGameInfo()?.NotInDatabase is false;
31+
=> APIs.Emulation.GetGameInfo()?.NotInDatabase is false;
3232

3333
[LuaMethodExample("local stgamget = gameinfo.getstatus( );")]
3434
[LuaMethod("getstatus", "returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase")]
3535
public string GetStatus()
36-
=> (APIs.GameInfo.GetGameInfo()?.Status)?.ToString();
36+
=> (APIs.Emulation.GetGameInfo()?.Status)?.ToString();
3737

3838
[LuaMethodExample("if ( gameinfo.isstatusbad( ) ) then\r\n\tconsole.log( \"returns the currently loaded rom's game database status is considered 'bad'\" );\r\nend;")]
3939
[LuaMethod("isstatusbad", "returns the currently loaded rom's game database status is considered 'bad'")]
4040
public bool IsStatusBad()
41-
=> APIs.GameInfo.GetGameInfo()?.IsRomStatusBad() is true or null;
41+
=> APIs.Emulation.GetGameInfo()?.IsRomStatusBad() is true or null;
4242

4343
[LuaMethodExample("local stgamget = gameinfo.getboardtype( );")]
4444
[LuaMethod("getboardtype", "returns identifying information about the 'mapper' or similar capability used for this game. empty if no such useful distinction can be drawn")]
4545
public string GetBoardType()
46-
=> APIs.GameInfo.GetBoardType();
46+
=> APIs.Emulation.GetBoardName();
4747

4848
[LuaMethodExample("local nlgamget = gameinfo.getoptions( );")]
4949
[LuaMethod("getoptions", "returns the game options for the currently loaded rom. Options vary per platform")]
5050
public LuaTable GetOptions()
51-
=> _th.DictToTable(APIs.GameInfo.GetOptions());
51+
=> _th.DictToTable(APIs.Emulation.GetGameOptions());
5252
}
5353
}

0 commit comments

Comments
 (0)