2014-04-13 14:22:13 +00:00
using System ;
2017-07-10 04:51:02 +00:00
using NLua ;
2017-05-01 02:01:37 +00:00
2015-01-01 20:08:03 +00:00
using BizHawk.Emulation.Common ;
2014-04-13 14:22:13 +00:00
namespace BizHawk.Client.Common
{
2014-06-01 22:02:59 +00:00
public sealed class GameInfoLuaLibrary : LuaLibraryBase
2014-04-13 14:22:13 +00:00
{
2017-05-01 02:01:37 +00:00
[OptionalService]
2017-05-19 13:58:23 +00:00
private IBoardInfo BoardInfo { get ; set ; }
2017-05-01 02:01:37 +00:00
2014-04-13 14:22:13 +00:00
public GameInfoLuaLibrary ( Lua lua )
2014-05-21 00:17:35 +00:00
: base ( lua ) { }
public GameInfoLuaLibrary ( Lua lua , Action < string > logOutputCallback )
: base ( lua , logOutputCallback ) { }
2014-04-13 14:22:13 +00:00
2017-04-14 19:59:01 +00:00
public override string Name = > "gameinfo" ;
2014-04-13 14:22:13 +00:00
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local stgamget = gameinfo.getromname( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getromname", "returns the path of the currently loaded rom, if a rom is loaded")]
2014-04-13 14:22:13 +00:00
public string GetRomName ( )
{
if ( Global . Game ! = null )
{
2017-05-10 11:45:23 +00:00
return Global . Game . Name ? ? "" ;
2014-04-13 14:22:13 +00:00
}
2017-05-10 11:45:23 +00:00
return "" ;
2014-04-13 14:22:13 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local stgamget = gameinfo.getromhash( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getromhash", "returns the hash of the currently loaded rom, if a rom is loaded")]
2014-04-13 14:22:13 +00:00
public string GetRomHash ( )
{
if ( Global . Game ! = null )
{
2017-05-10 11:45:23 +00:00
return Global . Game . Hash ? ? "" ;
2014-04-13 14:22:13 +00:00
}
2017-05-10 11:45:23 +00:00
return "" ;
2014-04-13 14:22:13 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("if ( gameinfo.indatabase( ) ) then\r\n\tconsole.log( \"returns whether or not the currently loaded rom is in the game database\" );\r\nend;")]
2017-07-10 19:02:00 +00:00
[LuaMethod("indatabase", "returns whether or not the currently loaded rom is in the game database")]
2014-04-13 14:24:38 +00:00
public bool InDatabase ( )
2014-04-13 14:22:13 +00:00
{
if ( Global . Game ! = null )
{
return ! Global . Game . NotInDatabase ;
}
return false ;
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local stgamget = gameinfo.getstatus( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getstatus", "returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase")]
2014-04-13 14:22:13 +00:00
public string GetStatus ( )
{
if ( Global . Game ! = null )
{
2017-05-09 18:19:55 +00:00
return Global . Game . Status . ToString ( ) ;
2014-04-13 14:22:13 +00:00
}
2017-05-10 11:45:23 +00:00
return "" ;
2014-04-13 14:22:13 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("if ( gameinfo.isstatusbad( ) ) then\r\n\tconsole.log( \"returns the currently loaded rom's game database status is considered 'bad'\" );\r\nend;")]
2017-07-10 19:02:00 +00:00
[LuaMethod("isstatusbad", "returns the currently loaded rom's game database status is considered 'bad'")]
2014-04-13 14:24:38 +00:00
public bool IsStatusBad ( )
2014-04-13 14:22:13 +00:00
{
if ( Global . Game ! = null )
{
return Global . Game . IsRomStatusBad ( ) ;
}
return true ;
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local stgamget = gameinfo.getboardtype( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getboardtype", "returns identifying information about the 'mapper' or similar capability used for this game. empty if no such useful distinction can be drawn")]
2014-04-13 14:22:13 +00:00
public string GetBoardType ( )
{
2017-05-10 11:45:23 +00:00
return BoardInfo ? . BoardName ? ? "" ;
2014-04-13 14:22:13 +00:00
}
2018-03-14 01:05:30 +00:00
[LuaMethodExample("local nlgamget = gameinfo.getoptions( );")]
2017-07-10 19:02:00 +00:00
[LuaMethod("getoptions", "returns the game options for the currently loaded rom. Options vary per platform")]
2014-04-13 14:22:13 +00:00
public LuaTable GetOptions ( )
{
2014-05-20 20:34:51 +00:00
var options = Lua . NewTable ( ) ;
2014-04-13 14:22:13 +00:00
if ( Global . Game ! = null )
{
foreach ( var option in Global . Game . GetOptionsDict ( ) )
{
options [ option . Key ] = option . Value ;
}
}
return options ;
}
}
}