Some low-hanging fruit in the IMovie refactor
This commit is contained in:
parent
1372fa258f
commit
a7a28c000a
|
@ -11,16 +11,20 @@ namespace BizHawk.Client.Common
|
|||
string Filename { get; set; }
|
||||
|
||||
bool IsCountingRerecords { get; set; }
|
||||
|
||||
bool IsActive { get; }
|
||||
bool IsPlaying { get; }
|
||||
bool IsRecording { get; }
|
||||
bool IsFinished { get; }
|
||||
bool Changes { get; }
|
||||
bool Loaded { get; }
|
||||
|
||||
bool LoadMovie();
|
||||
void WriteBackup();
|
||||
bool Load();
|
||||
void Save();
|
||||
void SaveAs();
|
||||
void Stop(bool saveChanges = true);
|
||||
|
||||
#region Editing API
|
||||
|
||||
void ClearFrame(int frame);
|
||||
void ModifyFrame(string record, int frame);
|
||||
void AppendFrame(string record);
|
||||
|
@ -28,12 +32,10 @@ namespace BizHawk.Client.Common
|
|||
void InsertBlankFrame(int frame);
|
||||
void DeleteFrame(int frame);
|
||||
void TruncateMovie(int frame);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dubious, should reconsider
|
||||
bool Loaded { get; } //Who needs to know it is loaded or not? The movie should decide what to do based on being loaded or not
|
||||
bool IsText { get; } //remove until needed Make a get set, consider an Enum of FileTypeMode or something,
|
||||
bool HasChanges { get; } //Rename to changes
|
||||
void CommitFrame(int frameNum, IController source); //why pass in frameNum? Calling api
|
||||
void PokeFrame(int frameNum, string input); //Why does this exist as something different than Commit Frame?
|
||||
void CaptureState(); //Movie code should manage wheter it needs to capture a state
|
||||
|
@ -46,14 +48,11 @@ namespace BizHawk.Client.Common
|
|||
|
||||
void Finish(); //Why isn't the movie in charge of this?
|
||||
void StartRecording(bool truncate = true); //Why do we need to truncate or not truncate? Why isn't the object in charge of this decision?
|
||||
void Stop(bool abortchanges = false); //Refactor to have a bool saveChanges instead
|
||||
|
||||
void StartPlayback(); //Poorly named for what it does, SetToPlay() perhaps? Also, this seems like too much power to give the calling code
|
||||
void SwitchToRecord(); //Ditto
|
||||
void SwitchToPlay(); //Dubious that it is needed
|
||||
|
||||
void WriteMovie(); //Rename to Write()
|
||||
|
||||
bool FrameLagged(int frame); //SHould be a property of a Record object
|
||||
byte[] GetState(int frame); //Should be a property of a Record object
|
||||
string GetInput(int frame); //Should be a property of a Record object
|
||||
|
@ -65,7 +64,7 @@ namespace BizHawk.Client.Common
|
|||
MovieLog LogDump { get; } //Don't expose this!!!
|
||||
SubtitleList Subtitles { get; } //Don't expose this!!!
|
||||
|
||||
int StateFirstIndex { get; }
|
||||
int StateFirstIndex { get; } //What do these do?
|
||||
int StateLastIndex { get; }
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -60,11 +60,6 @@ namespace BizHawk.Client.Common
|
|||
get { return Header.GetHeaderLine(MovieHeader.PLATFORM); }
|
||||
}
|
||||
|
||||
public string Guid
|
||||
{
|
||||
get { return Header.GetHeaderLine(MovieHeader.GUID); }
|
||||
}
|
||||
|
||||
public string GameName
|
||||
{
|
||||
get { return Header.GetHeaderLine(MovieHeader.GAMENAME); }
|
||||
|
@ -172,7 +167,7 @@ namespace BizHawk.Client.Common
|
|||
get { return _mode == Moviemode.Finished; }
|
||||
}
|
||||
|
||||
public bool HasChanges
|
||||
public bool Changes
|
||||
{
|
||||
get { return _changes; }
|
||||
}
|
||||
|
@ -186,7 +181,7 @@ namespace BizHawk.Client.Common
|
|||
_mode = Moviemode.Record;
|
||||
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
|
||||
{
|
||||
WriteBackup();
|
||||
SaveAs();
|
||||
MakeBackup = false;
|
||||
}
|
||||
if (truncate)
|
||||
|
@ -214,16 +209,16 @@ namespace BizHawk.Client.Common
|
|||
public void SwitchToPlay()
|
||||
{
|
||||
_mode = Moviemode.Play;
|
||||
WriteMovie();
|
||||
Save();
|
||||
}
|
||||
|
||||
public void Stop(bool abortchanges = false)
|
||||
public void Stop(bool saveChanges = true)
|
||||
{
|
||||
if (!abortchanges)
|
||||
if (saveChanges)
|
||||
{
|
||||
if (_mode == Moviemode.Record || _changes)
|
||||
{
|
||||
WriteMovie();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
_changes = false;
|
||||
|
@ -245,7 +240,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Public File Handling
|
||||
|
||||
public void WriteMovie(string path)
|
||||
public void SaveAs(string path)
|
||||
{
|
||||
if (!Loaded)
|
||||
{
|
||||
|
@ -264,18 +259,18 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void WriteMovie()
|
||||
public void Save()
|
||||
{
|
||||
if (!Loaded || String.IsNullOrWhiteSpace(Filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WriteMovie(Filename);
|
||||
SaveAs(Filename);
|
||||
_changes = false;
|
||||
}
|
||||
|
||||
public void WriteBackup()
|
||||
public void SaveAs()
|
||||
{
|
||||
if (!Loaded || String.IsNullOrWhiteSpace(Filename))
|
||||
{
|
||||
|
@ -355,7 +350,7 @@ namespace BizHawk.Client.Common
|
|||
return true;
|
||||
}
|
||||
|
||||
public bool LoadMovie()
|
||||
public bool Load()
|
||||
{
|
||||
var file = new FileInfo(Filename);
|
||||
if (file.Exists == false)
|
||||
|
@ -513,7 +508,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
|
||||
{
|
||||
WriteBackup();
|
||||
SaveAs();
|
||||
MakeBackup = false;
|
||||
}
|
||||
_log.Clear();
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
|
|||
);
|
||||
}
|
||||
|
||||
public void StopMovie(bool abortchanges = false)
|
||||
public void StopMovie(bool saveChanges = true)
|
||||
{
|
||||
string message = "Movie ";
|
||||
if (Movie.IsRecording)
|
||||
|
@ -86,8 +86,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
if (Movie.IsActive)
|
||||
{
|
||||
Movie.Stop(abortchanges);
|
||||
if (!abortchanges)
|
||||
Movie.Stop(saveChanges);
|
||||
if (saveChanges)
|
||||
{
|
||||
Output(Path.GetFileName(Movie.Filename) + " written to disk.");
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ namespace BizHawk.Client.Common
|
|||
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
|
||||
if (result == LoadStateResult.Pass)
|
||||
{
|
||||
Movie.WriteMovie();
|
||||
Movie.Save();
|
||||
Movie.SwitchToPlay();
|
||||
|
||||
return true;
|
||||
|
@ -232,7 +232,7 @@ namespace BizHawk.Client.Common
|
|||
var newresult = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
|
||||
if (newresult == LoadStateResult.Pass)
|
||||
{
|
||||
Movie.WriteMovie();
|
||||
Movie.Save();
|
||||
Movie.SwitchToPlay();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void MovieSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||
{
|
||||
FullMovieLoadstatesMenuItem.Enabled = !Global.MovieSession.MultiTrack.IsActive;
|
||||
StopMovieWithoutSavingMenuItem.Enabled = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.HasChanges;
|
||||
StopMovieWithoutSavingMenuItem.Enabled = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
|
||||
StopMovieMenuItem.Enabled
|
||||
= PlayFromBeginningMenuItem.Enabled
|
||||
= SaveMovieMenuItem.Enabled
|
||||
|
@ -436,7 +436,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void StopMovieWithoutSavingMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
StopMovie(true);
|
||||
StopMovie(saveChanges: false);
|
||||
}
|
||||
|
||||
private void BindSavestatesToMoviesMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -1813,7 +1813,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
SaveMovieContextMenuItem.Visible =
|
||||
Global.MovieSession.Movie.IsActive;
|
||||
|
||||
StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.HasChanges;
|
||||
StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
|
||||
|
||||
AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && Global.ReadOnly;
|
||||
|
||||
|
@ -1902,7 +1902,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void BackupMovieContextMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
GlobalWin.OSD.AddMessage("Backup movie saved.");
|
||||
Global.MovieSession.Movie.WriteBackup();
|
||||
Global.MovieSession.Movie.SaveAs();
|
||||
}
|
||||
|
||||
private void ViewSubtitlesContextMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -2214,7 +2214,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
//for instance, something which doesnt clobber movies you already may have had.
|
||||
//i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this:
|
||||
movie.Filename += ".autoimported." + Global.Config.MovieExtension;
|
||||
movie.WriteMovie();
|
||||
movie.Save();
|
||||
StartNewMovie(movie, false);
|
||||
}
|
||||
GlobalWin.OSD.AddMessage(warningMsg);
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
//If a movie is already loaded, save it before starting a new movie
|
||||
if (Global.MovieSession.Movie.IsActive)
|
||||
{
|
||||
Global.MovieSession.Movie.WriteMovie();
|
||||
Global.MovieSession.Movie.Save();
|
||||
}
|
||||
|
||||
Global.MovieSession = new MovieSession
|
||||
|
@ -31,7 +31,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (!record)
|
||||
{
|
||||
Global.MovieSession.Movie.LoadMovie();
|
||||
Global.MovieSession.Movie.Load();
|
||||
SetSyncDependentSettings();
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public void StopMovie(bool abortchanges = false)
|
||||
public void StopMovie(bool saveChanges = true)
|
||||
{
|
||||
Global.MovieSession.StopMovie();
|
||||
Global.MovieSession.StopMovie(saveChanges);
|
||||
SetMainformMovieInfo();
|
||||
}
|
||||
|
||||
|
|
|
@ -603,7 +603,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
for (int i = 0; i < frames; i++)
|
||||
{
|
||||
if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && 0 == Global.MovieSession.Movie.Frames))
|
||||
if (RewindBuf.Count == 0 || (Global.MovieSession.Movie.Loaded && Global.MovieSession.Movie.Frames == 0))
|
||||
return;
|
||||
|
||||
if (LastState.Length < 0x10000)
|
||||
|
|
|
@ -2381,7 +2381,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (Global.MovieSession.Movie.IsActive)
|
||||
{
|
||||
Global.MovieSession.Movie.WriteMovie();
|
||||
Global.MovieSession.Movie.Save();
|
||||
GlobalWin.OSD.AddMessage(Global.MovieSession.Movie.Filename + " saved.");
|
||||
}
|
||||
}
|
||||
|
@ -3794,7 +3794,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
Directory.CreateDirectory(d);
|
||||
|
||||
string outPath = Path.Combine(d, (Path.GetFileName(fn) + "." + Global.Config.MovieExtension));
|
||||
m.WriteMovie(outPath);
|
||||
m.SaveAs(outPath);
|
||||
}
|
||||
|
||||
public void FlagNeedsReboot() //Make private, config dialogs use it and it can be called after they close
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
Global.MovieSession.Movie.WriteMovie();
|
||||
Global.MovieSession.Movie.Save();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
DataGridViewCell c = CommentGrid.Rows[x].Cells[0];
|
||||
selectedMovie.Header.Comments.Add("comment " + c.Value);
|
||||
}
|
||||
selectedMovie.WriteMovie();
|
||||
selectedMovie.Save();
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
s.Message = c.Value.ToString();
|
||||
selectedMovie.Subtitles.Add(s);
|
||||
}
|
||||
selectedMovie.WriteMovie();
|
||||
selectedMovie.Save();
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (file.Extension.ToUpper() == "STATE")
|
||||
{
|
||||
Movie movie = new Movie(file.FullName);
|
||||
movie.LoadMovie(); //State files will have to load everything unfortunately
|
||||
movie.Load(); //State files will have to load everything unfortunately
|
||||
if (movie.Frames == 0)
|
||||
{
|
||||
MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
||||
|
@ -122,7 +122,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (x == 0)
|
||||
{
|
||||
Movie movie = new Movie(file.CanonicalFullPath);
|
||||
movie.LoadMovie(); //State files will have to load everything unfortunately
|
||||
movie.Load(); //State files will have to load everything unfortunately
|
||||
if (movie.Frames > 0)
|
||||
{
|
||||
_movieList.Add(movie);
|
||||
|
|
|
@ -372,7 +372,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Global.MovieSession.Movie.WriteMovie();
|
||||
Global.MovieSession.Movie.Save();
|
||||
}
|
||||
|
||||
private void saveProjectAsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -382,7 +382,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
if ("" != fileName)
|
||||
{
|
||||
Global.MovieSession.Movie.Filename = fileName;
|
||||
Global.MovieSession.Movie.WriteMovie();
|
||||
Global.MovieSession.Movie.Save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue