From b8bea93cceddaf906804e74e2542ee60834ea009 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Mon, 15 Jun 2020 13:37:50 -0400 Subject: [PATCH] Rework nyma controller overrides --- ...NymaCore.Controller.ButtonNameOverrides.cs | 22 +++++++++++++++++++ .../Waterbox/NymaCore.Controller.cs | 9 ++++---- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs new file mode 100644 index 0000000000..26e2dbf9bd --- /dev/null +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.ButtonNameOverrides.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Text.RegularExpressions; + +namespace BizHawk.Emulation.Cores.Waterbox +{ + partial class NymaCore + { + /// + /// Override button names. Technically this should be per core, but a lot of the names and overrides are the same, + /// and an override that doesn't apply to a particular core will just be ignored + /// + private string OverrideButtonName(string original) + { + original = Regex.Replace(original, @"\s*(↑|↓|←|→)\s*", ""); + original = Regex.Replace(original, @"\s*\([^\)]+\)\s*", ""); + original = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(original.ToLowerInvariant()); + // TODO: Add dictionaries or whatever here as needed + return original; + } + } +} diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs index d40d6b07d9..1f701f0b33 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs @@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Waterbox private void InitControls(List allPorts, bool hasCds, ref SystemInfo si) { _controllerAdapter = new ControllerAdapter( - allPorts, _syncSettingsActual.PortDevices, ButtonNameOverrides, hasCds, ref si, ComputeHiddenPorts()); + allPorts, _syncSettingsActual.PortDevices, OverrideButtonName, hasCds, ref si, ComputeHiddenPorts()); _nyma.SetInputDevices(_controllerAdapter.Devices); ControllerDefinition = _controllerAdapter.Definition; } @@ -36,7 +36,7 @@ namespace BizHawk.Emulation.Cores.Waterbox public ControllerAdapter( List allPorts, IDictionary config, - IDictionary overrides, + Func overrideName, bool hasCds, ref SystemInfo systemInfo, HashSet hiddenPorts) @@ -100,8 +100,8 @@ namespace BizHawk.Emulation.Cores.Waterbox var byteStart = devByteStart + bitOffset / 8; bitOffset %= 8; var baseName = input.Name; - if (baseName != null && overrides.ContainsKey(baseName)) - baseName = overrides[baseName]; + if (baseName != null) + baseName = overrideName(baseName); var name = input.Type == InputType.ResetButton ? "Reset" : $"P{port + 1} {baseName}"; switch (input.Type) @@ -303,7 +303,6 @@ namespace BizHawk.Emulation.Cores.Waterbox } } - protected virtual IDictionary ButtonNameOverrides { get; } = new Dictionary(); /// /// On some cores, some controller ports are not relevant when certain settings are off (like multitap). /// Override this if your core has such an issue