expose GenerateLogKey and Map as methods on ILogEntryGenerator and remove all the direct casting that was happening in tastudio code

This commit is contained in:
adelikat 2020-01-13 15:48:02 -06:00
parent 2c019794f5
commit 63da3d7bd3
5 changed files with 22 additions and 17 deletions

View File

@ -23,24 +23,15 @@ namespace BizHawk.Client.Common
#region ILogEntryGenerator Implementation
public void SetSource(IController source)
{
_source = source;
}
public void SetSource(IController source) => _source = source;
public string GenerateInputDisplay()
{
return CreateLogEntry(forInputDisplay: true);
}
public string GenerateInputDisplay() => CreateLogEntry(forInputDisplay: true);
public bool IsEmpty => EmptyEntry == GenerateLogEntry();
public string EmptyEntry => CreateLogEntry(createEmpty: true);
public string GenerateLogEntry()
{
return CreateLogEntry();
}
public string GenerateLogEntry() => CreateLogEntry();
#endregion

View File

@ -1,4 +1,5 @@
using BizHawk.Emulation.Common;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
@ -14,6 +15,19 @@ namespace BizHawk.Client.Common
/// </summary>
string GenerateLogEntry();
/// <summary>
/// Generates a human readable key that will specify the names of the
/// buttons and the order they are in. This is intended to simply be
/// documentation of the meaning of the mnemonics and not to be used to
/// enforce the mnemonic values
/// </summary>
string GenerateLogKey();
/// <summary>
/// Generates a dictionary of button names to their corresponding mnemonic values
/// </summary>
Dictionary<string, string> Map();
/// <summary>
/// Generates a display friendly version of the input log entry
/// </summary>

View File

@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
s.Refresh();
// Update the selected zone's key
var lg = (Bk2LogEntryGenerator)Global.MovieSession.LogGeneratorInstance();
var lg = Global.MovieSession.LogGeneratorInstance();
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
string key = lg.GenerateLogKey();
key = key.Replace("LogKey:", "").Replace("#", "");

View File

@ -20,7 +20,7 @@ namespace BizHawk.Client.EmuHawk
{
_emulator = emulator;
_tools = tools;
var lg = (Bk2LogEntryGenerator)movie.LogGeneratorInstance();
var lg = movie.LogGeneratorInstance();
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
_targetController = new Bk2ControllerAdapter { Definition = _emulator.ControllerDefinition };
_targetController.LatchFromSource(_targetController); // Reference and create all buttons
@ -224,7 +224,7 @@ namespace BizHawk.Client.EmuHawk
// If the LogKey contains buttons/controls not accepted by the emulator,
// tell the user and display the macro's controller name and player count
_inputKey = readText[0];
Bk2LogEntryGenerator lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator;
var lg = Global.MovieSession.LogGeneratorInstance();
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
string key = lg.GenerateLogKey();
key = key.Replace("LogKey:", "").Replace("#", "");

View File

@ -46,7 +46,7 @@ namespace BizHawk.Client.EmuHawk
{
var lg = Global.MovieSession.LogGeneratorInstance();
lg.SetSource(Global.MovieSession.MovieControllerAdapter);
return ((Bk2LogEntryGenerator)lg).Map();
return lg.Map();
}
[ConfigPersist]