2014-04-13 14:22:13 +00:00
using System ;
using LuaInterface ;
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
2017-04-15 20:37:30 +00:00
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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 ;
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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 ;
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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
}
[ LuaMethodAttributes (
2017-05-09 18:19:55 +00:00
"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 ;
}
}
}