From 63da3d7bd3fef379b0ca3cdb8edd4a0a0bced401 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 13 Jan 2020 15:48:02 -0600 Subject: [PATCH] expose GenerateLogKey and Map as methods on ILogEntryGenerator and remove all the direct casting that was happening in tastudio code --- .../movie/bk2/Bk2LogEntryGenerator.cs | 15 +++------------ .../movie/interfaces/ILogEntryGenerator.cs | 16 +++++++++++++++- .../tools/Macros/MacroInput.ButtonSelect.cs | 2 +- BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs | 4 ++-- .../tools/TAStudio/TAStudio.cs | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 1df809e86b..bb116c0548 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -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 diff --git a/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs b/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs index 897dd79281..37fc502473 100644 --- a/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/interfaces/ILogEntryGenerator.cs @@ -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 /// string GenerateLogEntry(); + /// + /// 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 + /// + string GenerateLogKey(); + + /// + /// Generates a dictionary of button names to their corresponding mnemonic values + /// + Dictionary Map(); + /// /// Generates a display friendly version of the input log entry /// diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs index ee24e4eaad..faa6d4ea12 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.ButtonSelect.cs @@ -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("#", ""); diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index a6fce3140d..904e1ddee9 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -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("#", ""); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 1fc18e0037..530206ce5e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -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]