diff --git a/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs b/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs index dabf91cc94..0acc66213a 100644 --- a/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs @@ -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; diff --git a/src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs b/src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs index fa49b7e9c9..8aac52f0d1 100644 --- a/src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs +++ b/src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs @@ -15,6 +15,14 @@ namespace BizHawk.Client.Common bool IsLoaded(); int Length(); string Mode(); + + /// + /// Resets the core to frame 0 with the currently loaded movie in playback mode. + /// If is specified, attempts to load it, then continues with playback if it was successful. + /// + /// true iff successful + bool PlayFromStart(string path = ""); + void Save(string filename = ""); void SetReadOnly(bool readOnly); void SetRerecordCount(ulong count); diff --git a/src/BizHawk.Client.Common/IMainFormForApi.cs b/src/BizHawk.Client.Common/IMainFormForApi.cs index 16f856ae9a..9a23ee1a12 100644 --- a/src/BizHawk.Client.Common/IMainFormForApi.cs +++ b/src/BizHawk.Client.Common/IMainFormForApi.cs @@ -60,6 +60,14 @@ namespace BizHawk.Client.Common /// only referenced from int GetApproxFramerate(); + /// + /// essentially return MainForm.StartNewMovie(MovieSession.Get(filename), record: false);, + /// but also ensures a rom is loaded, and defers to TAStudio + /// + /// unused + /// only referenced from + bool LoadMovie(string filename, string archive = null); + /// only referenced from void LoadQuickSave(string quickSlotName, bool suppressOSD = false); @@ -77,6 +85,9 @@ namespace BizHawk.Client.Common /// only referenced from EmuClientApi void Render(); + /// only referenced from + bool RestartMovie(); + /// only referenced from void SaveQuickSave(string quickSlotName, bool fromLua = false, bool suppressOSD = false); diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs index b582d2a446..26edb547a1 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/MovieLuaLibrary.cs @@ -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 = "") diff --git a/src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs b/src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs index 2c0f47e541..13a3a6e7e1 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs @@ -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()) { diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs index ace23e9d49..9d8640fdca 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Movie.cs @@ -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;