add a readonly interface for GameInfo for code that only needs to read, pass into SynclessRecordingTools instead of globals, refactor SynclessReocrdingTools a bit

This commit is contained in:
adelikat 2020-06-11 17:35:40 -05:00
parent 52cc0050b8
commit d9ef084e2f
7 changed files with 47 additions and 30 deletions

View File

@ -8,7 +8,7 @@ namespace BizHawk.Client.Common
public Dictionary<Type, IExternalApi> Libraries { get; set; }
public IEmu Emu => (IEmu) Libraries[typeof(IEmu)];
public IGameInfo GameInfo => (IGameInfo) Libraries[typeof(IGameInfo)];
public IGameInfoApi GameInfo => (IGameInfoApi) Libraries[typeof(IGameInfoApi)];
public IJoypad Joypad => (IJoypad) Libraries[typeof(IJoypad)];
public IMem Mem => (IMem) Libraries[typeof(IMem)];
public IMemEvents MemEvents => (IMemEvents) Libraries[typeof(IMemEvents)];

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
public interface IGameInfo : IExternalApi
public interface IGameInfoApi : IExternalApi
{
string GetRomName();
string GetRomHash();

View File

@ -7,34 +7,32 @@ using System.Windows.Forms;
using BizHawk.Bizware.BizwareGL;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using IGameInfo = BizHawk.Emulation.Common.IGameInfo;
namespace BizHawk.Client.EmuHawk
{
public partial class SynclessRecordingTools : Form
{
public SynclessRecordingTools()
{
InitializeComponent();
}
private void GetPaths(int index, out string png, out string wav)
{
string subPath = SynclessRecorder.GetPathFragmentForFrameNum(index);
string path = _mFramesDirectory;
path = Path.Combine(path, subPath);
png = $"{path}.png";
wav = $"{path}.wav";
}
private readonly List<FrameInfo> _mFrameInfos = new List<FrameInfo>();
private readonly IGameInfo _game;
private readonly string _avAbsolutePath;
private string _mSynclessConfigFile;
private string _mFramesDirectory;
public SynclessRecordingTools(IGameInfo game, string avAbsolutePath)
{
_game = game;
_avAbsolutePath = avAbsolutePath;
InitializeComponent();
}
public void Run()
{
var ofd = new OpenFileDialog
{
FileName = $"{GlobalWin.Game.FilesystemSafeName()}.syncless.txt",
InitialDirectory = GlobalWin.Config.PathEntries.AvAbsolutePath()
FileName = $"{_game.FilesystemSafeName()}.syncless.txt",
InitialDirectory = _avAbsolutePath
};
if (ofd.ShowDialog() == DialogResult.Cancel)
@ -73,8 +71,8 @@ namespace BizHawk.Client.EmuHawk
_mFrameInfos.Add(new FrameInfo
{
pngPath = png,
wavPath = wav
PngPath = png,
WavPath = wav
});
frame++;
@ -83,13 +81,20 @@ namespace BizHawk.Client.EmuHawk
ShowDialog();
}
private readonly List<FrameInfo> _mFrameInfos = new List<FrameInfo>();
struct FrameInfo
private void GetPaths(int index, out string png, out string wav)
{
public string wavPath, pngPath;
string subPath = SynclessRecorder.GetPathFragmentForFrameNum(index);
string path = _mFramesDirectory;
path = Path.Combine(path, subPath);
png = $"{path}.png";
wav = $"{path}.wav";
}
private class FrameInfo
{
public string WavPath { get; set; }
public string PngPath { get; set; }
}
private void btnExport_Click(object sender, EventArgs e)
{
@ -99,7 +104,7 @@ namespace BizHawk.Client.EmuHawk
}
int width, height;
using(var bmp = new Bitmap(_mFrameInfos[0].pngPath))
using(var bmp = new Bitmap(_mFrameInfos[0].PngPath))
{
width = bmp.Width;
height = bmp.Height;
@ -124,14 +129,14 @@ namespace BizHawk.Client.EmuHawk
avw.OpenFile(sfd.FileName);
foreach (var fi in _mFrameInfos)
{
using (var bb = new BitmapBuffer(fi.pngPath, new BitmapLoadOptions()))
using (var bb = new BitmapBuffer(fi.PngPath, new BitmapLoadOptions()))
{
var bbvp = new BitmapBufferVideoProvider(bb);
avw.AddFrame(bbvp);
}
// offset = 44 dec
var wavBytes = File.ReadAllBytes(fi.wavPath);
var wavBytes = File.ReadAllBytes(fi.WavPath);
var ms = new MemoryStream(wavBytes) { Position = 44 };
var br = new BinaryReader(ms);
var sampleData = new List<short>();

View File

@ -4,7 +4,7 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
public sealed class GameInfoApi : IGameInfo
public sealed class GameInfoApi : IGameInfoApi
{
[OptionalService]
private IBoardInfo BoardInfo { get; set; }

View File

@ -619,7 +619,7 @@ namespace BizHawk.Client.EmuHawk
private void SynclessRecordingMenuItem_Click(object sender, EventArgs e)
{
new SynclessRecordingTools().Run();
new SynclessRecordingTools(Game, Config.PathEntries.AvAbsolutePath()).Run();
}
private void CaptureOSDMenuItem_Click(object sender, EventArgs e)

View File

@ -6,7 +6,19 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Common
{
public class GameInfo
public interface IGameInfo
{
string Name { get; }
string System { get; }
string Hash { get; }
string Region { get; }
RomStatus Status { get; }
bool NotInDatabase { get; }
string FirmwareHash { get; }
string ForcedCore { get; }
}
public class GameInfo : IGameInfo
{
public string Name { get; set; }
public string System { get; set; }

View File

@ -375,7 +375,7 @@ namespace BizHawk.Emulation.Common
return buttons;
}
public static string FilesystemSafeName(this GameInfo game)
public static string FilesystemSafeName(this IGameInfo game)
{
var pass1 = game.Name
.Replace('/', '+') // '/' is the path dir separator, obviously (methods in Path will treat it as such, even on Windows)