Lua - add a gameinfo lua library with getromname(), getromhash(), getdisplaytype(), getindatabase(), getstatus(), getisstatusbad(), getboardtype(), and getoptions() methods
This commit is contained in:
parent
fd42606cc0
commit
9c3a7fec37
|
@ -113,6 +113,7 @@
|
|||
<Compile Include="lua\EmuLuaLibrary.Bit.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.Emu.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.Events.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.GameInfo.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.Joypad.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.MainMemory.cs" />
|
||||
<Compile Include="lua\EmuLuaLibrary.Memory.cs" />
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using BizHawk.Emulation.Cores.Nintendo.NES;
|
||||
using BizHawk.Emulation.Cores.PCEngine;
|
||||
|
@ -9,8 +11,6 @@ using LuaInterface;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EmulatorLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
private readonly Lua _lua;
|
||||
|
@ -171,11 +171,29 @@ namespace BizHawk.Client.Common
|
|||
|
||||
[LuaMethodAttributes(
|
||||
"yield",
|
||||
"TODO"
|
||||
"allows a script to run while emulation is paused and interact with the gui/main window in realtime "
|
||||
)]
|
||||
public void Yield()
|
||||
{
|
||||
_yieldCallback();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getdisplaytype",
|
||||
"returns the display type (PAL vs NTSC) that the emulator is currently running in"
|
||||
)]
|
||||
public string GetDisplayType()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
var displaytype = Global.Emulator.GetType().GetProperty("DisplayType");
|
||||
if (displaytype != null)
|
||||
{
|
||||
return displaytype.GetValue(Global.Emulator, null).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using LuaInterface;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class GameInfoLuaLibrary : LuaLibraryBase
|
||||
{
|
||||
public GameInfoLuaLibrary(Lua lua)
|
||||
{
|
||||
_lua = lua;
|
||||
}
|
||||
|
||||
public override string Name { get { return "gameinfo"; } }
|
||||
|
||||
private readonly Lua _lua;
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getromname",
|
||||
"returns the path of the currently loaded rom, if a rom is loaded"
|
||||
)]
|
||||
public string GetRomName()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
return Global.Game.Name ?? string.Empty;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getromhash",
|
||||
"returns the hash of the currently loaded rom, if a rom is loaded"
|
||||
)]
|
||||
public string GetRomHash()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
return Global.Game.Hash ?? string.Empty;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getindatabase",
|
||||
"returns whether or not the currently loaded rom is in the game database"
|
||||
)]
|
||||
public bool GetInDatabase()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
return !Global.Game.NotInDatabase;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getstatus",
|
||||
"returns the game database status of the currently loaded rom. Statuses are for example: GoodDump, BadDump, Hack, Unknown, NotInDatabase"
|
||||
)]
|
||||
public string GetStatus()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
return Global.Game.Status.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getisstatusbad",
|
||||
"returns the currently loaded rom's game database status is considered 'bad'"
|
||||
)]
|
||||
public bool GetIsStatusBad()
|
||||
{
|
||||
if (Global.Game != null)
|
||||
{
|
||||
return Global.Game.IsRomStatusBad();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"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()
|
||||
{
|
||||
return Global.Emulator.BoardName;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getoptions",
|
||||
"returns the game options for the currently loaded rom. Options vary per platform"
|
||||
)]
|
||||
public LuaTable GetOptions()
|
||||
{
|
||||
var options = _lua.NewTable();
|
||||
|
||||
if (Global.Game != null)
|
||||
{
|
||||
foreach (var option in Global.Game.GetOptionsDict())
|
||||
{
|
||||
options[option.Key] = option.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -101,7 +101,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
new SavestateLuaLibrary().LuaRegister(lua, Docs);
|
||||
new SnesLuaLibrary().LuaRegister(lua, Docs);
|
||||
new StringLuaLibrary().LuaRegister(lua, Docs);
|
||||
|
||||
new GameInfoLuaLibrary(_lua).LuaRegister(lua, Docs);
|
||||
Docs.Sort();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
console.log("Game Info library test")
|
||||
console.log("Rom Name: " .. gameinfo.getromname());
|
||||
console.log("Rom Hash: " .. gameinfo.getromhash());
|
||||
console.log("Display Type: " .. emu.getdisplaytype());
|
||||
console.log("In Database?: " .. tostring(gameinfo.getindatabase()));
|
||||
console.log("Rom Status: " .. gameinfo.getstatus());
|
||||
console.log("Is Status Bad?: " .. tostring(gameinfo.getisstatusbad()));
|
||||
console.log("Board Type: " .. gameinfo.getboardtype());
|
||||
console.log("Game Options: ")
|
||||
console.log(gameinfo.getoptions());
|
|
@ -1 +1,2 @@
|
|||
0 .\Lua\UnitTests\Joypad_Set.lua
|
||||
0 .\Lua\UnitTests\GameInfo.lua
|
||||
|
|
Loading…
Reference in New Issue