Add `IMovieApi.PlayFromStart`/`movie.play_from_start` (resolves #384)

This commit is contained in:
YoshiRulz 2022-12-07 03:18:07 +10:00 committed by James Groom
parent 7fdc3f992d
commit df4df517b8
6 changed files with 56 additions and 2 deletions

View File

@ -100,6 +100,31 @@ namespace BizHawk.Client.Common
public string Mode() => (_movieSession.Movie?.Mode ?? MovieMode.Inactive).ToString().ToUpper();
public bool PlayFromStart(string path = "")
{
if (string.IsNullOrEmpty(path))
{
try
{
return _mainForm.RestartMovie();
}
catch (Exception e)
{
LogCallback($"caught {e.GetType().Name} while trying to restart movie: {e.Message}");
return false;
}
}
try
{
return _mainForm.LoadMovie(filename: path);
}
catch (Exception e)
{
LogCallback($"caught {e.GetType().Name} while trying to load movie: {e.Message}");
return false;
}
}
public void SetReadOnly(bool readOnly) => _movieSession.ReadOnly = readOnly;
public void SetRerecordCount(ulong count) => _movieSession.Movie.Rerecords = count;

View File

@ -15,6 +15,14 @@ namespace BizHawk.Client.Common
bool IsLoaded();
int Length();
string Mode();
/// <summary>
/// Resets the core to frame 0 with the currently loaded movie in playback mode.
/// If <paramref name="path"/> is specified, attempts to load it, then continues with playback if it was successful.
/// </summary>
/// <returns>true iff successful</returns>
bool PlayFromStart(string path = "");
void Save(string filename = "");
void SetReadOnly(bool readOnly);
void SetRerecordCount(ulong count);

View File

@ -60,6 +60,14 @@ namespace BizHawk.Client.Common
/// <remarks>only referenced from <see cref="EmuClientApi"/></remarks>
int GetApproxFramerate();
/// <summary>
/// essentially <c>return MainForm.StartNewMovie(MovieSession.Get(filename), record: false);</c>,
/// but also ensures a rom is loaded, and defers to TAStudio
/// </summary>
/// <param name="archive">unused</param>
/// <remarks>only referenced from <see cref="MovieApi"/></remarks>
bool LoadMovie(string filename, string archive = null);
/// <remarks>only referenced from <see cref="SaveStateApi"/></remarks>
void LoadQuickSave(string quickSlotName, bool suppressOSD = false);
@ -77,6 +85,9 @@ namespace BizHawk.Client.Common
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
void Render();
/// <remarks>only referenced from <see cref="MovieApi"/></remarks>
bool RestartMovie();
/// <remarks>only referenced from <see cref="SaveStateApi"/></remarks>
void SaveQuickSave(string quickSlotName, bool fromLua = false, bool suppressOSD = false);

View File

@ -72,6 +72,16 @@ namespace BizHawk.Client.Common
public string Mode()
=> APIs.Movie.Mode();
[LuaMethodExample(@"movie.play_from_start(""C:\\moviename.ext"");")]
[LuaMethod("play_from_start", "Resets the core to frame 0 with the currently loaded movie in playback mode. If a path to a movie is specified, attempts to load it, then continues with playback if it was successful. Returns true iff successful.")]
public bool PlayFromStart([LuaArbitraryStringParam] string path = "")
{
_luaLibsImpl.IsRebootingCore = true;
var success = APIs.Movie.PlayFromStart(path);
_luaLibsImpl.IsRebootingCore = false;
return success;
}
[LuaMethodExample("movie.save( \"C:\\moviename.ext\" );")]
[LuaMethod("save", "Saves the current movie to the disc. If the filename is provided (no extension or path needed), the movie is saved under the specified name to the current movie directory. The filename may contain a subdirectory, it will be created if it doesn't exist. Existing files won't get overwritten.")]
public void Save([LuaArbitraryStringParam] string filename = "")

View File

@ -87,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
}
}
private bool LoadMovie(string filename, string archive = null)
public bool LoadMovie(string filename, string archive = null)
{
if (Emulator.IsNull())
{

View File

@ -99,7 +99,7 @@ namespace BizHawk.Client.EmuHawk
}
}
private bool RestartMovie()
public bool RestartMovie()
{
if (IsSlave && Master.WantsToControlRestartMovie) return Master.RestartMovie();
if (!MovieSession.Movie.IsActive()) return false;