2013-10-28 20:57:25 +00:00
|
|
|
|
using LuaInterface;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
|
2013-11-01 15:43:15 +00:00
|
|
|
|
namespace BizHawk.Client.Common
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-10-31 13:07:42 +00:00
|
|
|
|
public class MovieLuaLibrary : LuaLibraryBase
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2014-02-03 20:48:01 +00:00
|
|
|
|
private readonly Lua _lua;
|
|
|
|
|
|
2013-10-31 13:07:42 +00:00
|
|
|
|
public MovieLuaLibrary(Lua lua)
|
|
|
|
|
{
|
|
|
|
|
_lua = lua;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name { get { return "movie"; } }
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"filename",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns the file name including path of the currently loaded movie"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static string Filename()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.MovieSession.Movie.Filename;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"getinput",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns a table of buttons pressed on a given frame of the loaded movie"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
2014-01-27 01:15:56 +00:00
|
|
|
|
public LuaTable GetInput(int frame)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-12-30 01:58:44 +00:00
|
|
|
|
var input = _lua.NewTable();
|
2013-10-28 19:13:01 +00:00
|
|
|
|
|
2013-12-30 01:58:44 +00:00
|
|
|
|
var m = new MovieControllerAdapter { Type = Global.MovieSession.MovieControllerAdapter.Type };
|
2013-10-29 16:03:06 +00:00
|
|
|
|
m.SetControllersAsMnemonic(
|
2014-02-03 20:48:01 +00:00
|
|
|
|
Global.MovieSession.Movie.GetInput(frame));
|
2013-10-29 16:03:06 +00:00
|
|
|
|
|
2013-12-30 01:58:44 +00:00
|
|
|
|
foreach (var button in m.Type.BoolButtons)
|
2013-10-29 16:03:06 +00:00
|
|
|
|
{
|
2013-10-28 19:13:01 +00:00
|
|
|
|
input[button] = m[button];
|
2013-10-29 16:03:06 +00:00
|
|
|
|
}
|
2013-10-28 19:13:01 +00:00
|
|
|
|
|
|
|
|
|
return input;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"getreadonly",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns true if the movie is in read-only mode, false if in read+write"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static bool GetReadOnly()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-12-03 18:08:45 +00:00
|
|
|
|
return Global.MovieSession.ReadOnly;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"getrerecordcounting",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns whether or not the current movie is incrementing rerecords on loadstate"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static bool GetRerecordCounting()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return Global.MovieSession.Movie.IsCountingRerecords;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"isloaded",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns true if a movie is loaded in memory (play, record, or finished modes), false if not (inactive mode)"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static bool IsLoaded()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-10-31 13:07:42 +00:00
|
|
|
|
return Global.MovieSession.Movie.IsActive;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"length",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns the total number of frames of the loaded movie"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static double Length()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-11-30 03:10:05 +00:00
|
|
|
|
return Global.MovieSession.Movie.FrameCount;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"mode",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns the mode of the current movie. Possible modes: PLAY, RECORD, FINISHED, INACTIVE"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static string Mode()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (Global.MovieSession.Movie.IsFinished)
|
|
|
|
|
{
|
|
|
|
|
return "FINISHED";
|
|
|
|
|
}
|
2014-02-03 20:48:01 +00:00
|
|
|
|
|
|
|
|
|
if (Global.MovieSession.Movie.IsPlaying)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return "PLAY";
|
|
|
|
|
}
|
2014-02-03 20:48:01 +00:00
|
|
|
|
|
|
|
|
|
if (Global.MovieSession.Movie.IsRecording)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
return "RECORD";
|
|
|
|
|
}
|
2014-02-03 20:48:01 +00:00
|
|
|
|
|
|
|
|
|
return "INACTIVE";
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"rerecordcount",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns the current rerecord count for the loaded movie"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static string RerecordCount()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-12-02 17:50:29 +00:00
|
|
|
|
return Global.MovieSession.Movie.Header.Rerecords.ToString();
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"setreadonly",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Sets the read-only state to the given value. true for read only, false for read+write"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
2014-01-26 18:36:27 +00:00
|
|
|
|
public static void SetReadOnly(bool readOnly)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2014-01-26 18:36:27 +00:00
|
|
|
|
Global.MovieSession.ReadOnly = readOnly;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"setrerecordcounting",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Sets whether or not the current movie will increment the rerecord counter on loadstate"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
2014-01-26 18:36:27 +00:00
|
|
|
|
public static void SetRerecordCounting(bool counting)
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2014-01-26 18:36:27 +00:00
|
|
|
|
Global.MovieSession.Movie.IsCountingRerecords = counting;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 02:50:26 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"stop",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Stops the current movie"
|
2014-01-26 02:50:26 +00:00
|
|
|
|
)]
|
|
|
|
|
public static void Stop()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
|
|
|
|
Global.MovieSession.Movie.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|