Refactor `IGameInfoApi` (expose GameInfo as its read-only interface)
also enabled NRTs
This commit is contained in:
parent
fcd7a47435
commit
73af92b579
|
@ -1,4 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
|
@ -7,27 +9,22 @@ namespace BizHawk.Client.Common
|
|||
public sealed class GameInfoApi : IGameInfoApi
|
||||
{
|
||||
[OptionalService]
|
||||
private IBoardInfo BoardInfo { get; set; }
|
||||
public IBoardInfo? _boardInfo { get; set; }
|
||||
|
||||
private readonly IGameInfo _game;
|
||||
private readonly IGameInfo? _game;
|
||||
|
||||
public GameInfoApi(IGameInfo game) => _game = game;
|
||||
public GameInfoApi(IGameInfo? game)
|
||||
=> _game = game;
|
||||
|
||||
public string GetRomName() => _game?.Name ?? "";
|
||||
public string GetBoardType()
|
||||
=> _boardInfo?.BoardName ?? string.Empty;
|
||||
|
||||
public string GetRomHash() => _game?.Hash ?? "";
|
||||
public IGameInfo? GetGameInfo()
|
||||
=> _game;
|
||||
|
||||
public bool InDatabase() => _game?.NotInDatabase == false;
|
||||
|
||||
public string GetStatus() => _game?.Status.ToString();
|
||||
|
||||
public bool IsStatusBad() => _game?.IsRomStatusBad() != false;
|
||||
|
||||
public string GetBoardType() => BoardInfo?.BoardName ?? "";
|
||||
|
||||
public IReadOnlyDictionary<string, string> GetOptions()
|
||||
public IReadOnlyDictionary<string, string?> GetOptions()
|
||||
{
|
||||
var options = new Dictionary<string, string>();
|
||||
var options = new Dictionary<string, string?>();
|
||||
if (_game == null) return options;
|
||||
foreach (var option in ((GameInfo) _game).GetOptions()) options[option.Key] = option.Value;
|
||||
return options;
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public interface IGameInfoApi : IExternalApi
|
||||
{
|
||||
string GetRomName();
|
||||
string GetRomHash();
|
||||
bool InDatabase();
|
||||
string GetStatus();
|
||||
bool IsStatusBad();
|
||||
string GetBoardType();
|
||||
IReadOnlyDictionary<string, string> GetOptions();
|
||||
|
||||
IGameInfo? GetGameInfo();
|
||||
|
||||
IReadOnlyDictionary<string, string?> GetOptions();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
using System;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
using NLua;
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
@ -14,30 +17,37 @@ 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.GetRomName();
|
||||
public string GetRomName()
|
||||
=> APIs.GameInfo.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.GetRomHash();
|
||||
public string GetRomHash()
|
||||
=> APIs.GameInfo.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.InDatabase();
|
||||
public bool InDatabase()
|
||||
=> APIs.GameInfo.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.GetStatus();
|
||||
public string GetStatus()
|
||||
=> (APIs.GameInfo.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.IsStatusBad();
|
||||
public bool IsStatusBad()
|
||||
=> APIs.GameInfo.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();
|
||||
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() => _th.DictToTable(APIs.GameInfo.GetOptions());
|
||||
public LuaTable GetOptions()
|
||||
=> _th.DictToTable(APIs.GameInfo.GetOptions());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue