From 62b9146a960e441dc3a184f73e488e73e41186ed Mon Sep 17 00:00:00 2001 From: Alvaro Montoro Date: Sun, 1 Sep 2019 00:24:04 -0500 Subject: [PATCH] Release preparation - Added changes to log - Upgraded dist files - Bumped versions --- changelog.md | 7 +++++++ dist/gamecontroller.js | 2 +- dist/gamecontroller.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 1829514..d5e2506 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +## [v1.3.0] - 2019-08-31 + +### Added + +- New vibration capability (experimental feature) +- New demo page with example for axe/joystick threshold + ## [v1.2.1] - 2019-08-31 ### Added diff --git a/dist/gamecontroller.js b/dist/gamecontroller.js index e6f52ea..f0ea301 100644 --- a/dist/gamecontroller.js +++ b/dist/gamecontroller.js @@ -106,7 +106,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _too /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools */ \"./src/tools.js\");\n\n\nconst gamepad = {\n init: function(gpad) {\n let gamepadPrototype = {\n id: gpad.index,\n buttons: gpad.buttons.length,\n axes: Math.floor(gpad.axes.length / 2),\n axeValues: [],\n axeThreshold: [1.0],\n mapping: gpad.mapping,\n buttonActions: {},\n axesActions: {},\n set: function(property, value) {\n const properties = ['axeThreshold'];\n if (properties.indexOf(property) >= 0) {\n if (property === 'axeThreshold' && (!parseFloat(value) || value < 0.0 || value > 1.0)) {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Invalid axeThreshold. The value must be a number between 0.00 and 1.00.`, 'error');\n return;\n }\n this[property] = value;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Invalid property (${property}).`, 'error');\n }\n },\n checkStatus: function() {\n let gp = {};\n const gps = navigator.getGamepads\n ? navigator.getGamepads()\n : navigator.webkitGetGamepads\n ? navigator.webkitGetGamepads\n : [];\n if (gps.length) {\n gp = gps[this.id];\n if (gp.buttons) {\n for (let x = 0; x < this.buttons; x++) {\n if (gp.buttons[x].pressed === true) {\n this.buttonActions[x].action();\n }\n }\n }\n if (gp.axes) {\n const modifier = gp.axes.length % 2; // Firefox hack: detects one additional axe\n for (let x = 0; x < this.axes * 2; x++) {\n const val = gp.axes[x + modifier].toFixed(4);\n const axe = Math.floor(x / 2);\n this.axeValues[axe][x % 2] = val;\n if (val >= this.axeThreshold[0] && x % 2 === 0) {\n this.axesActions[axe].right.action();\n } else if (val <= -this.axeThreshold[0] && x % 2 === 0) {\n this.axesActions[axe].left.action();\n } else if (val >= this.axeThreshold[0] && x % 2 === 1) {\n this.axesActions[axe].down.action();\n } else if (val <= -this.axeThreshold[0] && x % 2 === 1) {\n this.axesActions[axe].up.action();\n }\n }\n }\n }\n },\n on: function(eventName, callback) {\n if (eventName.match(/^button\\d+$/)) {\n const buttonId = parseInt(eventName.match(/^button(\\d+)$/)[1]);\n if (buttonId >= 0 && buttonId < this.buttons) {\n this.buttonActions[buttonId].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot associate event to button that does not exist (${buttonId}).`, 'error');\n }\n } else if (eventName === 'start') {\n this.buttonActions[9].action = callback;\n } else if (eventName === 'select') {\n this.buttonActions[8].action = callback;\n } else if (eventName === 'r1') {\n this.buttonActions[5].action = callback;\n } else if (eventName === 'r2') {\n this.buttonActions[7].action = callback;\n } else if (eventName === 'l1') {\n this.buttonActions[4].action = callback;\n } else if (eventName === 'l2') {\n this.buttonActions[6].action = callback;\n } else if (eventName === 'power') {\n if (this.buttons >= 17) {\n this.buttonActions[16].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])('No power button available on this gamepad.', 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)(\\d+)$/)) {\n const matches = eventName.match(/^(up|down|left|right)(\\d+)$/);\n const direction = matches[1];\n const axe = parseInt(matches[2]);\n if (axe >= 0 && axe < this.axes) {\n this.axesActions[axe][direction].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot associate '${direction}' to axe that does not exist (${axe}).`, 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)$/)) {\n const direction = eventName.match(/^(up|down|left|right)$/)[1];\n this.axesActions[0][direction].action = callback;\n }\n\n return this;\n },\n off: function(eventName) {\n if (eventName.match(/^button\\d+$/)) {\n const buttonId = parseInt(eventName.match(/^button(\\d+)$/)[1]);\n if (buttonId >= 0 && buttonId < this.buttons) {\n this.buttonActions[buttonId].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot deassociate event to button that does not exist (${buttonId})`, 'error');\n }\n } else if (eventName === 'start') {\n this.buttonActions[9].action = function() {};\n } else if (eventName === 'select') {\n this.buttonActions[8].action = function() {};\n } else if (eventName === 'r1') {\n this.buttonActions[5].action = function() {};\n } else if (eventName === 'r2') {\n this.buttonActions[7].action = function() {};\n } else if (eventName === 'l1') {\n this.buttonActions[4].action = function() {};\n } else if (eventName === 'l2') {\n this.buttonActions[6].action = function() {};\n } else if (eventName === 'power') {\n if (this.buttons >= 17) {\n this.buttonActions[16].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])('No power button available on this gamepad.', 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)(\\d+)$/)) {\n const matches = eventName.match(/^(up|down|left|right)(\\d+)$/);\n const direction = matches[1];\n const axe = parseInt(matches[2]);\n if (axe >= 0 && axe < this.axes) {\n this.axesActions[axe][direction].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot deassociate '${direction}' to axe that does not exist (${axe}).`, 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)$/)) {\n const direction = eventName.match(/^(up|down|left|right)$/)[1];\n this.axesActions[0][direction].action = function() {};\n }\n return this;\n }\n };\n\n for (let x = 0; x < gamepadPrototype.buttons; x++) {\n gamepadPrototype.buttonActions[x] = {\n action: function() {}\n };\n }\n for (let x = 0; x < gamepadPrototype.axes; x++) {\n gamepadPrototype.axesActions[x] = {\n down: { action: function() {} },\n left: { action: function() {} },\n right: { action: function() {} },\n up: { action: function() {} }\n };\n gamepadPrototype.axeValues[x] = [0, 0];\n }\n\n return gamepadPrototype;\n }\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (gamepad);\n\n\n//# sourceURL=webpack:///./src/gamepad.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _tools__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./tools */ \"./src/tools.js\");\n\n\nconst gamepad = {\n init: function(gpad) {\n let gamepadPrototype = {\n id: gpad.index,\n buttons: gpad.buttons.length,\n axes: Math.floor(gpad.axes.length / 2),\n axeValues: [],\n axeThreshold: [1.0],\n hapticActuator: null,\n vibrationMode: -1,\n vibration: false,\n mapping: gpad.mapping,\n buttonActions: {},\n axesActions: {},\n set: function(property, value) {\n const properties = ['axeThreshold'];\n if (properties.indexOf(property) >= 0) {\n if (property === 'axeThreshold' && (!parseFloat(value) || value < 0.0 || value > 1.0)) {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Invalid axeThreshold. The value must be a number between 0.00 and 1.00.`, 'error');\n return;\n }\n this[property] = value;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Invalid property (${property}).`, 'error');\n }\n },\n vibrate: function(value = 0.75, duration = 500) {\n if (this.hapticActuator) {\n switch (this.vibrationMode) {\n case 0:\n this.hapticActuator.pulse(value, duration);\n break;\n case 1:\n this.hapticActuator.playEffect('dual-rumble', {\n duration: duration,\n strongMagnitude: value,\n weakMagnitude: value\n });\n break;\n }\n }\n },\n checkStatus: function() {\n let gp = {};\n const gps = navigator.getGamepads\n ? navigator.getGamepads()\n : navigator.webkitGetGamepads\n ? navigator.webkitGetGamepads\n : [];\n if (gps.length) {\n gp = gps[this.id];\n if (gp.buttons) {\n for (let x = 0; x < this.buttons; x++) {\n if (gp.buttons[x].pressed === true) {\n this.buttonActions[x].action();\n }\n }\n }\n if (gp.axes) {\n const modifier = gp.axes.length % 2; // Firefox hack: detects one additional axe\n for (let x = 0; x < this.axes * 2; x++) {\n const val = gp.axes[x + modifier].toFixed(4);\n const axe = Math.floor(x / 2);\n this.axeValues[axe][x % 2] = val;\n if (val >= this.axeThreshold[0] && x % 2 === 0) {\n this.axesActions[axe].right.action();\n } else if (val <= -this.axeThreshold[0] && x % 2 === 0) {\n this.axesActions[axe].left.action();\n } else if (val >= this.axeThreshold[0] && x % 2 === 1) {\n this.axesActions[axe].down.action();\n } else if (val <= -this.axeThreshold[0] && x % 2 === 1) {\n this.axesActions[axe].up.action();\n }\n }\n }\n }\n },\n on: function(eventName, callback) {\n if (eventName.match(/^button\\d+$/)) {\n const buttonId = parseInt(eventName.match(/^button(\\d+)$/)[1]);\n if (buttonId >= 0 && buttonId < this.buttons) {\n this.buttonActions[buttonId].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot associate event to button that does not exist (${buttonId}).`, 'error');\n }\n } else if (eventName === 'start') {\n this.buttonActions[9].action = callback;\n } else if (eventName === 'select') {\n this.buttonActions[8].action = callback;\n } else if (eventName === 'r1') {\n this.buttonActions[5].action = callback;\n } else if (eventName === 'r2') {\n this.buttonActions[7].action = callback;\n } else if (eventName === 'l1') {\n this.buttonActions[4].action = callback;\n } else if (eventName === 'l2') {\n this.buttonActions[6].action = callback;\n } else if (eventName === 'power') {\n if (this.buttons >= 17) {\n this.buttonActions[16].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])('No power button available on this gamepad.', 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)(\\d+)$/)) {\n const matches = eventName.match(/^(up|down|left|right)(\\d+)$/);\n const direction = matches[1];\n const axe = parseInt(matches[2]);\n if (axe >= 0 && axe < this.axes) {\n this.axesActions[axe][direction].action = callback;\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot associate '${direction}' to axe that does not exist (${axe}).`, 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)$/)) {\n const direction = eventName.match(/^(up|down|left|right)$/)[1];\n this.axesActions[0][direction].action = callback;\n }\n\n return this;\n },\n off: function(eventName) {\n if (eventName.match(/^button\\d+$/)) {\n const buttonId = parseInt(eventName.match(/^button(\\d+)$/)[1]);\n if (buttonId >= 0 && buttonId < this.buttons) {\n this.buttonActions[buttonId].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot deassociate event to button that does not exist (${buttonId})`, 'error');\n }\n } else if (eventName === 'start') {\n this.buttonActions[9].action = function() {};\n } else if (eventName === 'select') {\n this.buttonActions[8].action = function() {};\n } else if (eventName === 'r1') {\n this.buttonActions[5].action = function() {};\n } else if (eventName === 'r2') {\n this.buttonActions[7].action = function() {};\n } else if (eventName === 'l1') {\n this.buttonActions[4].action = function() {};\n } else if (eventName === 'l2') {\n this.buttonActions[6].action = function() {};\n } else if (eventName === 'power') {\n if (this.buttons >= 17) {\n this.buttonActions[16].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])('No power button available on this gamepad.', 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)(\\d+)$/)) {\n const matches = eventName.match(/^(up|down|left|right)(\\d+)$/);\n const direction = matches[1];\n const axe = parseInt(matches[2]);\n if (axe >= 0 && axe < this.axes) {\n this.axesActions[axe][direction].action = function() {};\n } else {\n Object(_tools__WEBPACK_IMPORTED_MODULE_0__[\"log\"])(`Cannot deassociate '${direction}' to axe that does not exist (${axe}).`, 'error');\n }\n } else if (eventName.match(/^(up|down|left|right)$/)) {\n const direction = eventName.match(/^(up|down|left|right)$/)[1];\n this.axesActions[0][direction].action = function() {};\n }\n return this;\n }\n };\n\n for (let x = 0; x < gamepadPrototype.buttons; x++) {\n gamepadPrototype.buttonActions[x] = {\n action: function() {}\n };\n }\n for (let x = 0; x < gamepadPrototype.axes; x++) {\n gamepadPrototype.axesActions[x] = {\n down: { action: function() {} },\n left: { action: function() {} },\n right: { action: function() {} },\n up: { action: function() {} }\n };\n gamepadPrototype.axeValues[x] = [0, 0];\n }\n\n // check if vibration actuator exists\n if (gpad.hapticActuators) {\n // newer standard\n if (typeof gpad.hapticActuators.pulse === 'function') {\n this.hapticActuator = gpad.hapticActuators;\n this.vibrationMode = 0;\n this.vibration = true;\n } else if (gpad.hapticActuators[0] && typeof gpad.hapticActuators[0].pulse === 'function') {\n this.hapticActuator = gpad.hapticActuators[0];\n this.vibrationMode = 0;\n this.vibration = true;\n }\n } else if (gamepad.vibrationActuator) {\n // old chrome stuff\n if (typeof gamepad.vibrationActuator.playEffect === 'function') {\n this.hapticActuator = gamepad.vibrationActuator.playEffect;\n this.vibrationMode = 1;\n this.vibration = true;\n }\n }\n\n return gamepadPrototype;\n }\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (gamepad);\n\n\n//# sourceURL=webpack:///./src/gamepad.js?"); /***/ }), diff --git a/dist/gamecontroller.min.js b/dist/gamecontroller.min.js index 855798d..3ae6ba5 100644 --- a/dist/gamecontroller.min.js +++ b/dist/gamecontroller.min.js @@ -1 +1 @@ -!function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);const o=(t,e="log")=>{"error"===e?console&&"function"==typeof console.error&&console.error(t):console&&"function"==typeof console.log&&console.log(t)},i=()=>navigator.getGamepads&&"function"==typeof navigator.getGamepads||navigator.getGamepads&&"function"==typeof navigator.webkitGetGamepads;var s={init:function(t){let e={id:t.index,buttons:t.buttons.length,axes:Math.floor(t.axes.length/2),axeValues:[],axeThreshold:[1],mapping:t.mapping,buttonActions:{},axesActions:{},set:function(t,e){if(["axeThreshold"].indexOf(t)>=0){if("axeThreshold"===t&&(!parseFloat(e)||e<0||e>1))return void o("Invalid axeThreshold. The value must be a number between 0.00 and 1.00.","error");this[t]=e}else o(`Invalid property (${t}).`,"error")},checkStatus:function(){let t={};const e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[];if(e.length){if((t=e[this.id]).buttons)for(let e=0;e=this.axeThreshold[0]&&n%2==0?this.axesActions[i].right.action():o<=-this.axeThreshold[0]&&n%2==0?this.axesActions[i].left.action():o>=this.axeThreshold[0]&&n%2==1?this.axesActions[i].down.action():o<=-this.axeThreshold[0]&&n%2==1&&this.axesActions[i].up.action()}}}},on:function(t,e){if(t.match(/^button\d+$/)){const n=parseInt(t.match(/^button(\d+)$/)[1]);n>=0&&n=17?this.buttonActions[16].action=e:o("No power button available on this gamepad.","error");else if(t.match(/^(up|down|left|right)(\d+)$/)){const n=t.match(/^(up|down|left|right)(\d+)$/),i=n[1],s=parseInt(n[2]);s>=0&&s=0&&e=17?this.buttonActions[16].action=function(){}:o("No power button available on this gamepad.","error");else if(t.match(/^(up|down|left|right)(\d+)$/)){const e=t.match(/^(up|down|left|right)(\d+)$/),n=e[1],i=parseInt(e[2]);i>=0&&i=0){if("axeThreshold"===t&&(!parseFloat(e)||e<0||e>1))return void o("Invalid axeThreshold. The value must be a number between 0.00 and 1.00.","error");if(this[t]=e,"axeThreshold"===t){const t=this.getGamepads(),e=Object.keys(t);for(let n=0;n0&&t(a.checkStatus)},init:function(){window.addEventListener("gamepadconnected",t=>{if(o("Gamepad detected."),window.gamepads||(window.gamepads={}),!window.gamepads[t.gamepad.index]){window.gamepads[t.gamepad.index]=t.gamepad;const e=s.init(t.gamepad);e.set("axeThreshold",this.axeThreshold),this.gamepads[e.id]=e,this.onConnect(this.gamepads[e.id])}1===Object.keys(this.gamepads).length&&this.checkStatus()}),window.addEventListener("gamepaddisconnected",t=>{o("Gamepad disconnected."),delete window.gamepads[t.gamepad.index],delete this.gamepads[t.gamepad.index],this.onDisconnect(t.gamepad.index)})},on:function(t,e){switch(t){case"connect":this.onConnect=e;break;case"disconnect":this.onDisconnect=e;break;case"beforeCycle":case"beforecycle":this.onBeforeCycle=e;break;case"afterCycle":case"aftercycle":this.onAfterCycle=e;break;default:o("Unknown event name","error")}return this},off:function(t){switch(t){case"connect":this.onConnect=function(){};break;case"disconnect":this.onDisconnect=function(){};break;case"beforeCycle":case"beforecycle":this.onBeforeCycle=function(){};break;case"afterCycle":case"aftercycle":this.onAfterCycle=function(){};break;default:o("Unknown event name","error")}return this}};a.init();var c=a;i()?window.gameControl=c:o("Your web browser does not support the Gamepad API.","error")}]); \ No newline at end of file +!function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);const o=(t,e="log")=>{"error"===e?console&&"function"==typeof console.error&&console.error(t):console&&"function"==typeof console.log&&console.log(t)},i=()=>navigator.getGamepads&&"function"==typeof navigator.getGamepads||navigator.getGamepads&&"function"==typeof navigator.webkitGetGamepads,a={init:function(t){let e={id:t.index,buttons:t.buttons.length,axes:Math.floor(t.axes.length/2),axeValues:[],axeThreshold:[1],hapticActuator:null,vibrationMode:-1,vibration:!1,mapping:t.mapping,buttonActions:{},axesActions:{},set:function(t,e){if(["axeThreshold"].indexOf(t)>=0){if("axeThreshold"===t&&(!parseFloat(e)||e<0||e>1))return void o("Invalid axeThreshold. The value must be a number between 0.00 and 1.00.","error");this[t]=e}else o(`Invalid property (${t}).`,"error")},vibrate:function(t=.75,e=500){if(this.hapticActuator)switch(this.vibrationMode){case 0:this.hapticActuator.pulse(t,e);break;case 1:this.hapticActuator.playEffect("dual-rumble",{duration:e,strongMagnitude:t,weakMagnitude:t})}},checkStatus:function(){let t={};const e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[];if(e.length){if((t=e[this.id]).buttons)for(let e=0;e=this.axeThreshold[0]&&n%2==0?this.axesActions[i].right.action():o<=-this.axeThreshold[0]&&n%2==0?this.axesActions[i].left.action():o>=this.axeThreshold[0]&&n%2==1?this.axesActions[i].down.action():o<=-this.axeThreshold[0]&&n%2==1&&this.axesActions[i].up.action()}}}},on:function(t,e){if(t.match(/^button\d+$/)){const n=parseInt(t.match(/^button(\d+)$/)[1]);n>=0&&n=17?this.buttonActions[16].action=e:o("No power button available on this gamepad.","error");else if(t.match(/^(up|down|left|right)(\d+)$/)){const n=t.match(/^(up|down|left|right)(\d+)$/),i=n[1],a=parseInt(n[2]);a>=0&&a=0&&e=17?this.buttonActions[16].action=function(){}:o("No power button available on this gamepad.","error");else if(t.match(/^(up|down|left|right)(\d+)$/)){const e=t.match(/^(up|down|left|right)(\d+)$/),n=e[1],i=parseInt(e[2]);i>=0&&i=0){if("axeThreshold"===t&&(!parseFloat(e)||e<0||e>1))return void o("Invalid axeThreshold. The value must be a number between 0.00 and 1.00.","error");if(this[t]=e,"axeThreshold"===t){const t=this.getGamepads(),e=Object.keys(t);for(let n=0;n0&&t(c.checkStatus)},init:function(){window.addEventListener("gamepadconnected",t=>{if(o("Gamepad detected."),window.gamepads||(window.gamepads={}),!window.gamepads[t.gamepad.index]){window.gamepads[t.gamepad.index]=t.gamepad;const e=s.init(t.gamepad);e.set("axeThreshold",this.axeThreshold),this.gamepads[e.id]=e,this.onConnect(this.gamepads[e.id])}1===Object.keys(this.gamepads).length&&this.checkStatus()}),window.addEventListener("gamepaddisconnected",t=>{o("Gamepad disconnected."),delete window.gamepads[t.gamepad.index],delete this.gamepads[t.gamepad.index],this.onDisconnect(t.gamepad.index)})},on:function(t,e){switch(t){case"connect":this.onConnect=e;break;case"disconnect":this.onDisconnect=e;break;case"beforeCycle":case"beforecycle":this.onBeforeCycle=e;break;case"afterCycle":case"aftercycle":this.onAfterCycle=e;break;default:o("Unknown event name","error")}return this},off:function(t){switch(t){case"connect":this.onConnect=function(){};break;case"disconnect":this.onDisconnect=function(){};break;case"beforeCycle":case"beforecycle":this.onBeforeCycle=function(){};break;case"afterCycle":case"aftercycle":this.onAfterCycle=function(){};break;default:o("Unknown event name","error")}return this}};c.init();var r=c;i()?window.gameControl=r:o("Your web browser does not support the Gamepad API.","error")}]); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 65cba7c..db73ef1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gamecontroller.js", - "version": "1.2.1", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 468df68..670aae5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gamecontroller.js", - "version": "1.2.1", + "version": "1.3.0", "description": "A JavaScript library that lets you handle, configure, and use gamepad and controllers on a browser, using the Gamepad API", "main": "dist/index.js", "scripts": {