lua: movie.getinput() now fails gracefully if adapter is null.

fixes #595
movie.mode() returns a string, so make its modes look like strings in the description.
This commit is contained in:
feos 2016-03-12 12:05:24 +03:00
parent 29e6d5e1d5
commit a6c3561db0
1 changed files with 14 additions and 2 deletions

View File

@ -48,9 +48,21 @@ namespace BizHawk.Client.Common
)] )]
public LuaTable GetInput(int frame) public LuaTable GetInput(int frame)
{ {
if (!Global.MovieSession.Movie.IsActive)
{
Log("No movie loaded");
return null;
}
var input = Lua.NewTable(); var input = Lua.NewTable();
var adapter = Global.MovieSession.Movie.GetInputState(frame); var adapter = Global.MovieSession.Movie.GetInputState(frame);
if (adapter == null)
{
Log("Can't get input of the last frame of the movie. Use the previous frame");
return null;
}
foreach (var button in adapter.Type.BoolButtons) foreach (var button in adapter.Type.BoolButtons)
{ {
input[button] = adapter[button]; input[button] = adapter[button];
@ -127,7 +139,7 @@ namespace BizHawk.Client.Common
[LuaMethodAttributes( [LuaMethodAttributes(
"mode", "mode",
"Returns the mode of the current movie. Possible modes: PLAY, RECORD, FINISHED, INACTIVE" "Returns the mode of the current movie. Possible modes: \"PLAY\", \"RECORD\", \"FINISHED\", \"INACTIVE\""
)] )]
public static string Mode() public static string Mode()
{ {
@ -173,7 +185,7 @@ namespace BizHawk.Client.Common
var test = new FileInfo(filename); var test = new FileInfo(filename);
if (test.Exists) if (test.Exists)
{ {
Log(string.Format("File {0} already exists, will not overwrite.", filename)); Log(string.Format("File {0} already exists, will not overwrite", filename));
return; return;
} }
Global.MovieSession.Movie.Filename = filename; Global.MovieSession.Movie.Filename = filename;