/* == Draf API == == current API == gamepad.press(); // press one --> gamepad.press([BUTTONS.A]); gamepad.press([, , ..]); // press many --> gamepad.press([BUTTONS.A, BUTTONS.SELECT, BUTTONS.START]); gamepad..press(); // press one --> gamepad.A.press(); gamepad..press(); // same for joysticks buttons gamepad..release // release one --> gamepad.A.release(); gamepad.release(, , ..]); // release many --> gamepad.release([BUTTONS.A, BUTTONS.SELECT, BUTTONS.START]); // joysticks only: range [-127..127] gamepad..move(, ); --> gamepad.LJOY_X.move(45); gamepad..moveX(); gamepad..moveY(); // triggers only: range [0..255] gamepad..press(); // if analog, 'll range [0..255] // global gamepad.set({ :, .. }); --> gamepad.set({START:1, SELECT: 1, LJOY_X: 120}) gamepad.unset(); --> gamepad.unset(); // update gamepad.sendState(); // or '.update()' ? --> gamepad.sendState(); */ /* TODO: thnk of the following when rewriting the below stuff ; '0b' + (btnState | BUTTONS.SELECT | BUTTONS.START | BUTTONS.R3).toString(2) // setting stuff '0b' + (btnState | BUTTONS.SELECT | BUTTONS.START | BUTTONS.R3 &~ BUTTONS.R3 ).toString(2) // AND-NOT-ing stuff to unset the above fixed it ;) gamepad.release( Object.values(BUTTONS) ); gamepad state: 0b1111111111111110 debugger eval code:118:5 gamepad state: 0b1111111111111100 debugger eval code:118:5 gamepad state: 0b1111111111111000 debugger eval code:118:5 gamepad state: 0b1111111111110000 debugger eval code:118:5 gamepad state: 0b1111111111100000 debugger eval code:118:5 gamepad state: 0b1111111111000000 debugger eval code:118:5 gamepad state: 0b1111111110000000 debugger eval code:118:5 gamepad state: 0b1111111100000000 debugger eval code:118:5 gamepad state: 0b1111111000000000 debugger eval code:118:5 gamepad state: 0b1111110000000000 debugger eval code:118:5 gamepad state: 0b1111100000000000 debugger eval code:118:5 gamepad state: 0b1111000000000000 debugger eval code:118:5 gamepad state: 0b1110000000000000 debugger eval code:118:5 gamepad state: 0b1100000000000000 debugger eval code:118:5 gamepad state: 0b1000000000000000 debugger eval code:118:5 gamepad state: 0b0 debugger eval code:118:5 */ var BUTTONS = { START: 0x0001, // SELECT: 0x0002, // PAD_UP: 0x0004, // PAD_DOWN: 0x0008, // works gamepad.btnState = ( gamepad.btnState | (1<<0x0008) ) PAD_LEFT: 0x0010, // stop working from here ? :| but gamepad.btnState = ( gamepad.btnState | (1<<0x0010) ) works ??! PAD_RIGHT: 0x0020, // Y: 0x0040, // YELLOW: 0x0040, // A: 0x0080, // GREEN: 0x0080, // X: 0x0100, // BLUE: 0x0100, // B: 0x0200, // RED: 0x0200, // L1: 0x0400, // R1: 0x0800, // L2: 0x1000, // R2: 0x2000, // L3: 0x4000, // R3: 0x8000, // }; var button = function(bLabel, bValue){ this.bLabel = bLabel; this.bValue = bValue & 0xFFFF; }; button.prototype.bLabel = ''; button.prototype.bValue = 0; // set corresponding bit in gamepad obj button.prototype.press = function(){ //gamepad.btnState = ( gamepad.btnState | (1<' + ( gamepad.btnState | ( (1<' + ( gamepad.btnState | 1<' + ( gamepad.btnState | this.bValue) ); // NOT SILLY FIX ? //gamepad.btnState = gamepad.btnState | ( (1< we want to // if the label is present in the BUTTONS consts, then we act depending on the value passed to set or unset correspondign bit if(typeof BUTTONS[opt] !== 'undefined'){ if(optsObj[opt] === 1) that.btnState = that.btnState | (1<>8) & 0xFF, // Byte1 this.x1, // Byte2 this.y1, // Byte3 this.x2, // Byte4 this.y2, // Byte5 ]); };