Open lukekarrys opened 10 years ago
Multiple controller support would be :sparkles:, I think what you're describing is basically how the https://github.com/andrew/node-xbox-controller library works as well if you need another example.
Thanks @andrew, and yeah this is pretty close to what I was thinking. As for proposed multicontroller support, here's what I was thinking for possible syntax:
Option1: Have the user manage it themselves
var snes1 = new GamePad('snes').connect();
var snes2 = new GamePad('snes', { usedPaths: snes1.getPath() }).connect();
Option 2: pass an array to the constructor
var snes = new GamePad(['snes', 'snes']);
snes.connect();
snes[0].on('a:press', console.log);
snes[1].on('a:press', console.log);
Option 2 would require a lot more changes under the hood, but then node-gamepad could keep track of what paths have already been used. Or tell me both of these are bad, and there's something better :smile:
Great idea for multi-controller support! I'm not sold on the idea of passing an array in simply because they really should be separate objects.
Just thinking through a few different options here:
Option A:
Have GamePad
detect any controllers that are found and store meta information about each controller...
var detectedControllers = GamePad.detectControllers();
var playerOne = new GamePad( detectedControllers.snes[0].path );
var playerTwo = new GamePad( detectedControllers.snes[1].path );
var ps3 = new GamePad( detectedControllers.ps3.path );
Option B:
Do they really need to specify which controller they want to use? This feature would be really cool but it also scares me (potentially something extra we'd have to support).
var controllers = GamePad.loadControllers();
controllers.snes[0].on( 'connected', callback );
controllers.snes[1].on( 'connected', callback );
controllers.ps3.on( 'connected', callback );
I like Option B. It is something extra to support, but I think it'd very useful as a kind of auto-setup feature. Any other opinions/options? I might try to take a stab at this in the coming week.
Any update on this? I would like support for multiple controllers.
hey @mikeytdan: yes! when I get back from Boston, I'll test the code I have against multiple controllers and PR it for others to test. I only have a PS4 controller with me atm.
Thanks! I can't wait to hear how the testing goes.
@carldanley Let me know if you need help testing or anything. I have multiple controllers (2 SNES and 2 N64) and would be happy to help. I've had a todo task in my "later" folder for this for 2 months :grin:
@lukekarrys I'll def. need your help with testing the double controllers :)
For a couple reasons:
node-hid
docs: https://github.com/node-hid/node-hid#opening-a-deviceI think this wouldn't require too much code after #6 since we already can look through the output from
HID.devices
.I can have a PR for this sometime soon (with a multicontroller example), but wanted to make sure there was interest first.