Simplify `EmulatorExtensions.ToControlNameList`

also fixes it for controllerNum >= 10
This commit is contained in:
YoshiRulz 2025-03-29 04:41:46 +10:00
parent 5f76e3cc74
commit f25b992a4e
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 7 additions and 12 deletions

View File

@ -390,20 +390,15 @@ namespace BizHawk.Emulation.Common
private static List<string> ToControlNameList(IEnumerable<string> buttonList, int? controllerNum = null)
{
var buttons = new List<string>();
foreach (var button in buttonList)
var buttons = buttonList;
if (controllerNum is int n)
{
if (controllerNum != null && button.Length > 2 && button.Substring(0, 2) == $"P{controllerNum}")
{
var sub = button.Substring(3);
buttons.Add(sub);
}
else if (controllerNum == null)
{
buttons.Add(button);
}
var pfx = $"P{n} ";
buttons = buttons.Select(buttonName => (ButtonName: buttonName, Tail: buttonName.RemovePrefix(pfx)))
.Where(static tuple => !object.ReferenceEquals(tuple.Tail, tuple.ButtonName))
.Select(static tuple => tuple.Tail);
}
return buttons;
return buttons.ToList();
}
public static IReadOnlyDictionary<string, object> ToDictionary(this IController controller, int? controllerNum = null)