move methods for Log copying from ITasMovie to IMovie. This bloats the IMovie contract more, but this allows for converting from one IMovie to another without an IEmulator dependency. Refactor conversion extensions to use these methods and remove emulator and movie session dependencies
This commit is contained in:
parent
b88f20faed
commit
b22f9e6e01
|
@ -331,7 +331,7 @@ namespace BizHawk.Client.Common
|
|||
public void ConvertToTasProj()
|
||||
{
|
||||
Movie.Save();
|
||||
Movie = Movie.ToTasMovie(this);
|
||||
Movie = Movie.ToTasMovie();
|
||||
Movie.Save();
|
||||
Movie.SwitchToPlay();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores;
|
||||
|
||||
|
@ -92,6 +93,17 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public IStringLog GetLogEntries() => Log;
|
||||
|
||||
public void CopyLog(IEnumerable<string> log)
|
||||
{
|
||||
Log.Clear();
|
||||
foreach (var entry in log)
|
||||
{
|
||||
Log.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendFrame(IController source)
|
||||
{
|
||||
var lg = LogGeneratorInstance(source);
|
||||
|
|
|
@ -15,20 +15,11 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
|||
{
|
||||
public static class MovieConversionExtensions
|
||||
{
|
||||
public static ITasMovie ToTasMovie(this IMovie old, IMovieSession session)
|
||||
public static ITasMovie ToTasMovie(this IMovie old)
|
||||
{
|
||||
string newFilename = GetNewFileName(old.Filename);
|
||||
var tas = (ITasMovie)MovieService.Get(newFilename);
|
||||
|
||||
// TODO: this relies on the fact that the emulator core here will be the same as when it is load
|
||||
// so this specifically only works in the scenario of a running bk2 converted to tasproj in tastudio
|
||||
// need to untangle and not be so dependent on core loading behavior
|
||||
tas.Attach(session, old.Emulator);
|
||||
for (var i = 0; i < old.InputLogLength; i++)
|
||||
{
|
||||
var input = old.GetInputState(i);
|
||||
tas.AppendFrame(input);
|
||||
}
|
||||
tas.CopyLog(old.GetLogEntries());
|
||||
|
||||
old.Truncate(0); // Trying to minimize ram usage
|
||||
|
||||
|
@ -63,12 +54,7 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
|
|||
public static IMovie ToBk2(this IMovie old)
|
||||
{
|
||||
var bk2 = MovieService.Get(old.Filename.Replace(old.PreferredExtension, Bk2Movie.Extension));
|
||||
|
||||
for (var i = 0; i < old.InputLogLength; i++)
|
||||
{
|
||||
var input = old.GetInputState(i);
|
||||
bk2.AppendFrame(input);
|
||||
}
|
||||
bk2.CopyLog(old.GetLogEntries());
|
||||
|
||||
bk2.HeaderEntries.Clear();
|
||||
foreach (var kvp in old.HeaderEntries)
|
||||
|
|
|
@ -240,6 +240,9 @@ namespace BizHawk.Client.Common
|
|||
/// The currently attached core or null if not yet attached
|
||||
/// </summary>
|
||||
IEmulator Emulator { get; }
|
||||
|
||||
IStringLog GetLogEntries();
|
||||
void CopyLog(IEnumerable<string> log);
|
||||
}
|
||||
|
||||
public static class MovieExtensions
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace BizHawk.Client.Common
|
|||
string DisplayValue(int frame, string buttonName);
|
||||
void FlagChanges();
|
||||
void ClearChanges();
|
||||
IStringLog GetLogEntries();
|
||||
|
||||
void GreenzoneCurrentFrame();
|
||||
void ToggleBoolState(int frame, string buttonName);
|
||||
|
@ -48,7 +47,6 @@ namespace BizHawk.Client.Common
|
|||
|
||||
void LoadBranch(TasBranch branch);
|
||||
|
||||
void CopyLog(IEnumerable<string> log);
|
||||
void CopyVerificationLog(IEnumerable<string> log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,15 +165,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public void CopyLog(IEnumerable<string> log)
|
||||
{
|
||||
Log.Clear();
|
||||
foreach (var entry in log)
|
||||
{
|
||||
Log.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CopyVerificationLog(IEnumerable<string> log)
|
||||
{
|
||||
foreach (string entry in log)
|
||||
|
@ -182,8 +174,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public IStringLog GetLogEntries() => Log;
|
||||
|
||||
// TODO: this is 99% copy pasting of bad code
|
||||
public override bool ExtractInputLog(TextReader reader, out string errorMessage)
|
||||
{
|
||||
|
|
|
@ -46,11 +46,10 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void Attach(IEmulator emulator)
|
||||
{
|
||||
// TODO: we aren't ready for this, attach is called when converting a bk2 to tasproj and again to officially load the emulator
|
||||
//if (!_emulator.IsNull())
|
||||
//{
|
||||
// throw new InvalidOperationException("A core has already been attached!");
|
||||
//}
|
||||
if (!_emulator.IsNull())
|
||||
{
|
||||
throw new InvalidOperationException("A core has already been attached!");
|
||||
}
|
||||
|
||||
if (!emulator.HasSavestates())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue