Closed quinton-ashley closed 4 years ago
If you want to add support for these controllers keep in mind that the B button is the lowest button in the face button diamond layout. This is how the face buttons are mapped:
button 0 = Y button 1 = B button 2 = A button 3 = X
any progress on this?
Sorry for not responding for so long, but I was never motivated enough to work on this issue, so I eventually just forgot about it. The problem with implementing support for non-standard gamepads is that it's so much more complex than it seems.
Every library supporting non-standard gamepads I've seen so far is either unreliable because it "guesses" button and axis indices or includes hundreds of lines of code for mapping between generic names and model-specific indices (see the mappings included input.js and gamepad.js). I'm not really interested in maintaining my own mappings and I also haven't seen a great collection of mappings yet that I could pull in.
Even if you have mappings for a lot of devices, you'll still have to deal with recognizing devices. This can be very difficult because browsers and operating systems are not very consistent when it comes to how they present gamepads (in terms of labels/IDs). Then there's also special editions and third-party clones of gamepads that might be functionally equivalent to a device already included in the mappings but presented very differently, making it hard to recognize them too.
Say that you've figured all of that out, there's still one big problem: Now that you're accepting non-standard gamepads with (even just slightly) different buttons and axes, you'll have to implement additional functionality to make sure that alternative button labels (like the Switch Pro Controller's swapped buttons) are correctly displayed and that there's a way to check whether a particular button is supported on a gamepad (since it might be missing on some devices).
As you can see, there's many things that make adding support for non-standard gamepads quite challenging. I'm not saying it's impossible, but I'm just not really motivated to spend a lot of time on this at the moment. If you know any libraries that have found a way to solve some or all of these problems or if you have some ideas of your own, please let me know!
Funnily enough I just finished implementing support for them in my app Nostlan. I made my own UI library called contro-ui but sadly I had to drop my dependence on contro and use the HTML gamepad API directly. https://github.com/quinton-ashley/contro-ui/blob/13d0bc57a6d729786cca69a3a56d870672a4a6fe/dist/js/contro-ui.js#L756 I had to map a lot of the buttons and the dpad on the Switch Pro controller has to be translated from an axis value, no clue why that's a thing but I managed to integrate it. contro-ui also does a lot of other weird mapping stuff cause of the nature of my app Nostlan, it's an emulator frontend, https://github.com/quinton-ashley/nostlan/wiki/Adaptive-Button-Mapping.
So yeah when I started looking into it yesterday I realized that it's a real mess indeed! I wouldn't bother with it, doubt there's many people who actually need Switch Pro controller or non-standard controller support for it to be worth the trouble.
Could you post a screenshot of what you can see on https://html5gamepad.com?