Movie importers - fix importers, broken with recent movie refactors, fix bkm importer, most systems were broken due to contorller definition names changing over the years

This commit is contained in:
adelikat 2020-06-06 17:17:50 -05:00
parent 4d3ef71c8a
commit 4d80b5d4e8
6 changed files with 42 additions and 24 deletions

View File

@ -11,7 +11,7 @@
for (var i = 0; i < bkm.InputLogLength; i++)
{
var input = bkm.GetInputState(i);
var input = bkm.GetInputState(i, Result.Movie.Emulator.ControllerDefinition, bkm.Header[HeaderKeys.Platform]);
Result.Movie.AppendFrame(input);
}

View File

@ -1,4 +1,5 @@
using System;
using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -7,7 +8,7 @@ namespace BizHawk.Client.Common
{
public interface IMovieImport
{
ImportResult Import(IMovieSession session, string path, Config config);
ImportResult Import(IMovieSession session, IEmulator emulator, string path, Config config);
}
internal abstract class MovieImporter : IMovieImport
@ -16,7 +17,7 @@ namespace BizHawk.Client.Common
protected const string Md5 = "MD5";
protected const string MovieOrigin = "MovieOrigin";
public ImportResult Import(IMovieSession session, string path, Config config)
public ImportResult Import(IMovieSession session, IEmulator emulator, string path, Config config)
{
SourceFile = new FileInfo(path);
Config = config;
@ -29,7 +30,7 @@ namespace BizHawk.Client.Common
var newFileName = $"{SourceFile.FullName}.{Bk2Movie.Extension}";
Result.Movie = session.Get(newFileName);
Result.Movie.Attach(emulator);
RunImport();
if (!Result.Errors.Any())

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Reflection;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
@ -30,7 +31,7 @@ namespace BizHawk.Client.Common
);
// Attempt to import another type of movie file into a movie object.
public static ImportResult ImportFile(IMovieSession session, string path, Config config)
public static ImportResult ImportFile(IMovieSession session, IEmulator emulator, string path, Config config)
{
string ext = Path.GetExtension(path) ?? "";
var importerType = ImporterForExtension(ext);
@ -47,7 +48,7 @@ namespace BizHawk.Client.Common
return importer == null
? ImportResult.Error($"No importer found for file type {ext}")
: importer.Import(session, path, config);
: importer.Import(session, emulator, path, config);
}
private static Type ImporterForExtension(string ext)

View File

@ -5,6 +5,34 @@ namespace BizHawk.Client.Common
{
internal class BkmControllerAdapter : IController
{
public BkmControllerAdapter(ControllerDefinition definition, string systemId)
{
Definition = definition;
// We do need to map the definition name to the legacy
// controller names that were used back in the bkm days
Definition.Name = systemId switch
{
"Lynx" => "Lynx Controller",
"SNES" => "SNES Controller",
"C64" => "Commodore 64 Controller",
"GBA" => "GBA Controller",
"A78" => "Atari 7800 ProLine Joystick Controller",
"DGB" => "Dual Gameboy Controller",
"WSWAN" => "WonderSwan Controller",
"N64" => "Nintendo 64 Controller",
"SAT" => "Saturn Controller",
"GEN" => "GPGX Genesis Controller",
"NES" => "NES Controller",
"GB" => "Gameboy Controller",
"A26" => "Atari 2600 Basic Controller",
"TI83" => "TI83 Controller",
"Coleco" => "ColecoVision Basic Controller",
"SMS Controller" => "SMS",
_ => "Null Controller",
};
}
public ControllerDefinition Definition { get; set; }
public bool IsPressed(string button)
@ -128,16 +156,6 @@ namespace BizHawk.Client.Common
Force("Power", mnemonic[1] != '.');
}
if (ControlType == "Genesis 3-Button Controller")
{
if (mnemonic.Length < 2)
{
return;
}
Force("Reset", mnemonic[1] != '.');
}
if (ControlType == "SMS Controller" || ControlType == "TI83 Controller" || ControlType == "ColecoVision Basic Controller")
{
start = 1;

View File

@ -1,4 +1,5 @@
using System;
using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.IO;
@ -12,14 +13,11 @@ namespace BizHawk.Client.Common
public bool Loaded { get; private set; }
public int InputLogLength => Loaded ? _log.Count : 0;
public BkmControllerAdapter GetInputState(int frame)
public BkmControllerAdapter GetInputState(int frame, ControllerDefinition definition, string sytemId)
{
if (frame < InputLogLength && frame >= 0)
{
var adapter = new BkmControllerAdapter
{
Definition = Global.MovieSession.MovieController.Definition
};
var adapter = new BkmControllerAdapter(definition, sytemId);
adapter.SetControllersAsMnemonic(_log[frame]);
return adapter;
}

View File

@ -3982,7 +3982,7 @@ namespace BizHawk.Client.EmuHawk
private void ProcessMovieImport(string fn, bool start)
{
var result = MovieImport.ImportFile(MovieSession, fn, Config);
var result = MovieImport.ImportFile(MovieSession, Emulator, fn, Config);
if (result.Errors.Any())
{