diff --git a/BizHawk.Client.Common/movie/bk2/Bk2AxisMnemonicConstants.cs b/BizHawk.Client.Common/movie/bk2/Bk2AxisMnemonicConstants.cs index 59f1b1fac6..d68b13a152 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2AxisMnemonicConstants.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2AxisMnemonicConstants.cs @@ -2,34 +2,31 @@ namespace BizHawk.Client.Common { - public class Bk2AxisMnemonicConstants + internal static class Bk2AxisMnemonicConstants { - public string this[string button] + public static string Lookup(string button) { - get + var key = button + .Replace("P1 ", "") + .Replace("P2 ", "") + .Replace("P3 ", "") + .Replace("P4 ", "") + .Replace("Key ", ""); + + if (SystemOverrides.ContainsKey(Global.Emulator.SystemId) && SystemOverrides[Global.Emulator.SystemId].ContainsKey(key)) { - var key = button - .Replace("P1 ", "") - .Replace("P2 ", "") - .Replace("P3 ", "") - .Replace("P4 ", "") - .Replace("Key ", ""); - - if (_systemOverrides.ContainsKey(Global.Emulator.SystemId) && _systemOverrides[Global.Emulator.SystemId].ContainsKey(key)) - { - return _systemOverrides[Global.Emulator.SystemId][key]; - } - - if (_baseMnemonicLookupTable.ContainsKey(key)) - { - return _baseMnemonicLookupTable[key]; - } - - return button; + return SystemOverrides[Global.Emulator.SystemId][key]; } + + if (BaseMnemonicLookupTable.ContainsKey(key)) + { + return BaseMnemonicLookupTable[key]; + } + + return button; } - private readonly Dictionary _baseMnemonicLookupTable = new Dictionary + private static readonly Dictionary BaseMnemonicLookupTable = new Dictionary { ["Zapper X"] = "zapX", ["Zapper Y"] = "zapY", @@ -48,7 +45,7 @@ namespace BizHawk.Client.Common ["Disc Select"] = "Disc" }; - private readonly Dictionary> _systemOverrides = new Dictionary> + private static readonly Dictionary> SystemOverrides = new Dictionary> { ["A78"] = new Dictionary { diff --git a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index 8b75e5c52c..1758c2b4bb 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -8,9 +8,6 @@ namespace BizHawk.Client.Common { public class Bk2LogEntryGenerator : ILogEntryGenerator { - private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants(); - private readonly Bk2AxisMnemonicConstants _axisMnemonics = new Bk2AxisMnemonicConstants(); - private readonly string _logKey; private IController _source; @@ -59,11 +56,11 @@ namespace BizHawk.Client.Common { if (_source.Definition.BoolButtons.Contains(button)) { - dict.Add(button, _mnemonics[button].ToString()); + dict.Add(button, Bk2MnemonicConstants.Lookup(button).ToString()); } else if (_source.Definition.AxisControls.Contains(button)) { - dict.Add(button, _axisMnemonics[button]); + dict.Add(button, Bk2AxisMnemonicConstants.Lookup(button)); } } } @@ -118,7 +115,7 @@ namespace BizHawk.Client.Common } else { - sb.Append(_source.IsPressed(button) ? _mnemonics[button] : forInputDisplay ? ' ' : '.'); + sb.Append(_source.IsPressed(button) ? Bk2MnemonicConstants.Lookup(button) : forInputDisplay ? ' ' : '.'); } } } diff --git a/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs b/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs index c3468fa7c7..bf7635fe19 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2MnemonicConstants.cs @@ -3,46 +3,43 @@ // ReSharper disable StyleCop.SA1509 namespace BizHawk.Client.Common { - public class Bk2MnemonicConstants + internal static class Bk2MnemonicConstants { - public char this[string button] + public static char Lookup(string button) { - get + var key = button.Replace("Key ", ""); + if (key.StartsWith("P")) { - var key = button.Replace("Key ", ""); - if (key.StartsWith("P")) + if (key.Length > 2 && key[1] == '1' && key[2] >= '0' && key[2] <= '9') // Hack to support 10-20 controllers, TODO: regex this thing instead { - if (key.Length > 2 && key[1] == '1' && key[2] >= '0' && key[2] <= '9') // Hack to support 10-20 controllers, TODO: regex this thing instead - { - key = key.Substring(4); - } - else if (key.Length > 1 && key[1] >= '0' && key[1] <= '9') - { - key = key.Substring(3); - } + key = key.Substring(4); } - - - if (_systemOverrides.ContainsKey(Global.Emulator.SystemId) && _systemOverrides[Global.Emulator.SystemId].ContainsKey(key)) + else if (key.Length > 1 && key[1] >= '0' && key[1] <= '9') { - return _systemOverrides[Global.Emulator.SystemId][key]; + key = key.Substring(3); } - - if (_baseMnemonicLookupTable.ContainsKey(key)) - { - return _baseMnemonicLookupTable[key]; - } - - if (key.Length == 1) - { - return key[0]; - } - - return '!'; } + + + if (SystemOverrides.ContainsKey(Global.Emulator.SystemId) && SystemOverrides[Global.Emulator.SystemId].ContainsKey(key)) + { + return SystemOverrides[Global.Emulator.SystemId][key]; + } + + if (BaseMnemonicLookupTable.ContainsKey(key)) + { + return BaseMnemonicLookupTable[key]; + } + + if (key.Length == 1) + { + return key[0]; + } + + return '!'; } - private readonly Dictionary _baseMnemonicLookupTable = new Dictionary + private static readonly Dictionary BaseMnemonicLookupTable = new Dictionary { ["Power"] = 'P', ["Reset"] = 'r', @@ -142,7 +139,7 @@ namespace BizHawk.Client.Common ["Previous Disk"] = '<' }; - private readonly Dictionary> _systemOverrides = new Dictionary> + private static readonly Dictionary> SystemOverrides = new Dictionary> { ["NES"] = new Dictionary { diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 91e6c02c76..5e63c2f15b 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -11,8 +11,6 @@ namespace BizHawk.Client.Common { public sealed partial class TasMovie : Bk2Movie, INotifyPropertyChanged { - private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants(); - public IStringLog VerificationLog { get; } = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state public TasBranchCollection Branches { get; } = new TasBranchCollection(); public TasSession Session { get; private set; } = new TasSession(); @@ -99,7 +97,7 @@ namespace BizHawk.Client.Common if (adapter.Definition.BoolButtons.Contains(buttonName)) { return adapter.IsPressed(buttonName) - ? _mnemonics[buttonName].ToString() + ? Bk2MnemonicConstants.Lookup(buttonName).ToString() : ""; }