make mnemonic constant classes static

This commit is contained in:
adelikat 2020-04-14 18:08:14 -05:00
parent cc15bb2841
commit c325286169
4 changed files with 52 additions and 63 deletions

View File

@ -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<string, string> _baseMnemonicLookupTable = new Dictionary<string, string>
private static readonly Dictionary<string, string> BaseMnemonicLookupTable = new Dictionary<string, string>
{
["Zapper X"] = "zapX",
["Zapper Y"] = "zapY",
@ -48,7 +45,7 @@ namespace BizHawk.Client.Common
["Disc Select"] = "Disc"
};
private readonly Dictionary<string, Dictionary<string, string>> _systemOverrides = new Dictionary<string, Dictionary<string, string>>
private static readonly Dictionary<string, Dictionary<string, string>> SystemOverrides = new Dictionary<string, Dictionary<string, string>>
{
["A78"] = new Dictionary<string, string>
{

View File

@ -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 ? ' ' : '.');
}
}
}

View File

@ -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<string, char> _baseMnemonicLookupTable = new Dictionary<string, char>
private static readonly Dictionary<string, char> BaseMnemonicLookupTable = new Dictionary<string, char>
{
["Power"] = 'P',
["Reset"] = 'r',
@ -142,7 +139,7 @@ namespace BizHawk.Client.Common
["Previous Disk"] = '<'
};
private readonly Dictionary<string, Dictionary<string, char>> _systemOverrides = new Dictionary<string, Dictionary<string, char>>
private static readonly Dictionary<string, Dictionary<string, char>> SystemOverrides = new Dictionary<string, Dictionary<string, char>>
{
["NES"] = new Dictionary<string, char>
{

View File

@ -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()
: "";
}