Fix reading joystick hat config values

Use the wxString-returning form of wxRegex.GetMatch() because the bool
form always returns true if the initial match succeeded, causing every
hat direction in the config to be interpreted as north, the first
condition in the if statement.

Fix #1192

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2023-10-20 17:45:54 +00:00
parent d8d3ee2b48
commit 7e1afcd37c
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 4 additions and 4 deletions

View File

@ -214,13 +214,13 @@ UserInput StringToUserInput(const wxString& string) {
if (kHatRegex.Matches(remainder)) { if (kHatRegex.Matches(remainder)) {
kHatRegex.GetMatch(&start, &length, 1); kHatRegex.GetMatch(&start, &length, 1);
const int key = StringToInt(remainder.Mid(start, length)); const int key = StringToInt(remainder.Mid(start, length));
if (kHatRegex.GetMatch(&start, &length, 3)) { if (kHatRegex.GetMatch(remainder, 3).Length()) {
return UserInput(key, wxJoyControl::HatNorth, joy); return UserInput(key, wxJoyControl::HatNorth, joy);
} else if (kHatRegex.GetMatch(&start, &length, 4)) { } else if (kHatRegex.GetMatch(remainder, 4).Length()) {
return UserInput(key, wxJoyControl::HatSouth, joy); return UserInput(key, wxJoyControl::HatSouth, joy);
} else if (kHatRegex.GetMatch(&start, &length, 5)) { } else if (kHatRegex.GetMatch(remainder, 5).Length()) {
return UserInput(key, wxJoyControl::HatEast, joy); return UserInput(key, wxJoyControl::HatEast, joy);
} else if (kHatRegex.GetMatch(&start, &length, 6)) { } else if (kHatRegex.GetMatch(remainder, 6).Length()) {
return UserInput(key, wxJoyControl::HatWest, joy); return UserInput(key, wxJoyControl::HatWest, joy);
} }
} }