{"_id":"joypad-manager","_rev":"38-b7d7d9a1481dba123064eef03cde41a2","name":"joypad-manager","description":"This is a wrapper for the HTML5 Gamepad API that adds event and button mapping.","dist-tags":{"latest":"0.6.0"},"versions":{"0.6.0":{"name":"joypad-manager","version":"0.6.0","author":{"name":"Nicolas Vitaterna","email":"nvitaterna@gmail.com"},"license":"MIT","_id":"joypad-manager@0.6.0","maintainers":[{"name":"nvitaterna","email":"nvitaterna@gmail.com"}],"homepage":"https://github.com/nvitaterna/joypad-manager","bugs":{"url":"https://github.com/nvitaterna/joypad-manager/issues"},"dist":{"shasum":"84206cbb0823e08954de821103ffff9ca3e3635f","tarball":"https://registry.npmjs.org/joypad-manager/-/joypad-manager-0.6.0.tgz","fileCount":54,"integrity":"sha512-O2sQh77OgLJaC1VIKozjDlAu4sL5mpKTI86vZRevjw81aDHUnGjRLoj7gDyYWQr/S+w2a4sst8R6Sdo5S6i66A==","signatures":[{"sig":"MEQCIBwhpZqLRlaooeK4patz2VGSFD6xTPPUh+O7UPC18fi1AiAnAtU4UjtBcBWj+bex0yp+uMomrj3jRr81tJPy5DCDUQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":287252,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe9pE9CRA9TVsSAnZWagAAg1UP/RG19frohW/AnVmLqAuV\nuzWMH0IULC+D14H+cYvtcZPAVXdABoCJK9POHHuVU5opKvRtP/KbdipctvR7\nwjZwDFi17kUSqrqG+gL7xXm6paymSpSG+T1LupOh8kMINnP1QC3abkOFCjCr\nfkBlKQf/IX2jpwkZbP18wCkK/wt+9rB3VeQiXiFXIagO8Rmaw3XUynW6RkAU\nB09k46dI2hLk2Oaht2nBh1396cIf26/1HiSINs377lh+oUeAdFXZDTer+b5H\nw97te+idBlPFRrBCtR7iN+IQVMPYcOnbsZtdvm/gBINPF4mlvMQwb8Pd2iEe\n1XHTykHe5L0fvM9X1RgHtksdvrAaKpZrtGsSvfq0sNreKmtOtRswm2wsFt3m\nOicDUL7eM0zx6Yumf3YkKOC4DFRlv/vFA4LaxjZt3jrZBzfQzBx2aFLghme5\nHAObWZ5kV4f1j6OrLmRTqSZFkN2RYqcNU6lGANDEbda5e/0Q0qz2ehzYgh9Y\n88c77a5WU1DycWCnuri5KnGuWQ5MmHvfQyZ0rTDd2spqx9o5p6TTAI9cIM9u\nSMWJ6rJDtvhH6qiw/1vVCLs6ZK6LQNVc114D7YR1tfWMgucnC6nj2L51sLE4\nrLqoSnJEBXwip8TPdl9HoYPqv+Tj+85IV9vwRyEsereScgtVmA+5x+Cma91U\ngj6/\r\n=25KU\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/joypad-manager.js","husky":{"hooks":{"pre-commit":"yarn build && yarn docs && git add ."}},"types":"lib/index.d.ts","module":"lib/index.js","gitHead":"3e2c8df34b31cd0b811d7d8a32bacddb1cbf7cfd","scripts":{"dev":"NODE_ENV=development webpack-dev-server","docs":"typedoc src","lint":"eslint --fix ./src","build":"yarn build:web && yarn build:lib && yarn docs","version":"git add .","build:lib":"rm -rf lib && tsc -p tsconfig.lib.json","build:web":"NODE_ENV=production webpack","preversion":"yarn build && yarn docs","postversion":"git push && git push --tags"},"_npmUser":{"name":"nvitaterna","email":"nvitaterna@gmail.com"},"repository":{"url":"git+ssh://git@github.com/nvitaterna/joypad-manager.git","type":"git"},"_npmVersion":"6.14.5","description":"This is a wrapper for the HTML5 Gamepad API that adds event and button mapping.","directories":{},"_nodeVersion":"12.18.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"husky":"^4.2.5","eslint":"^7.3.1","typedoc":"^0.17.7","webpack":"^4.43.0","prettier":"^2.0.5","ts-loader":"^7.0.5","typescript":"^3.9.5","@babel/core":"^7.10.2","webpack-cli":"^3.3.11","babel-loader":"^8.1.0","@babel/runtime":"^7.10.2","@babel/preset-env":"^7.10.2","webpack-dev-server":"^3.11.0","html-webpack-plugin":"^4.3.0","clean-webpack-plugin":"^3.0.0","terser-webpack-plugin":"^3.0.6","typedoc-plugin-markdown":"^2.3.1","@babel/preset-typescript":"^7.10.1","html-webpack-harddisk-plugin":"^1.0.2","fork-ts-checker-webpack-plugin":"^5.0.5","@babel/plugin-transform-runtime":"^7.10.1","@nvitaterna/eslint-config-prettier":"^1.0.1","@babel/plugin-proposal-class-properties":"^7.10.1","@babel/plugin-proposal-optional-chaining":"^7.10.1"},"_npmOperationalInternal":{"tmp":"tmp/joypad-manager_0.6.0_1593217340808_0.6008765578198991","host":"s3://npm-registry-packages"},"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."}},"time":{"created":"2020-06-27T00:22:20.807Z","modified":"2024-06-22T12:05:54.589Z","0.4.0":"2020-06-24T18:01:51.290Z","0.6.0":"2020-06-27T00:22:20.939Z"},"maintainers":[{"name":"nvitaterna","email":"nvitaterna@gmail.com"}],"author":{"name":"Nicolas Vitaterna","email":"nvitaterna@gmail.com"},"repository":{"url":"git+ssh://git@github.com/nvitaterna/joypad-manager.git","type":"git"},"license":"MIT","homepage":"https://github.com/nvitaterna/joypad-manager","bugs":{"url":"https://github.com/nvitaterna/joypad-manager/issues"},"readme":"# joypad-manager\n\n[![dependencies Status](https://flat.badgen.net/david/dep/nvitaterna/joypad-manager)](https://david-dm.org/nvitaterna/joypad-manager)\n[![npm version](https://flat.badgen.net/npm/v/joypad-manager)](https://www.npmjs.com/package/joypad-manager)\n\n`joypad-manager` is a wrapper for the [Gamepad API](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API) that adds events and button mapping.\n\n## Install\n\njoypad-manager is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). `joypad-manager` can be installed in a project's directory like any other package:\n\nNPM  \n`npm i joypad-manager`\n\nYarn  \n`yarn add joypad-manager`\n\nIt works in the browser too:\n```html\n<script src=\"https://cdn.jsdelivr.net/gh/nvitaterna/joypad-manager/dist/joypad-manager.min.js\"></script>\n```\n## Quick Start\n\n```js\nconst joypadManager = new JoypadManager();\n\nconst joypad = joypadManager.joypads[0];\n\n// place 'joypadManager.update()' at the top of your game's update loop\n\njoypad.addEventListener('buttonpress', (event) => {\n  if (event.button.name === 'buttonSouth') {\n    // do something!\n  }\n});\n```\n\n## Documentation\n\nThis library is fully typed and should support out-of-the-box typings and intellisense when using supported editors (developed using VSCode).\n\n### Setup\n```js\nconst JoypadManager = require('joypad-manager');\n```\nor\n```js\nimport JoypadManager from 'joypad-manager';\n```\n\nIn the browser it is globally available on the window object:\n```js\nwindow.JoypadManager\n```\n\n### Usage\n\n#### Setup\nInitiate the [`JoypadManager`](/docs/classes/_joypadmanager_.joypadmanager.md):\n\n```js\nconst joypadManager = new Joypadmanager();\n```\n#### Update Loop\nAdd the `joypadManager`'s update function to the start of your the game's update loop:\n```js\n...\nfunction update() {\n  joypadManager.update();\n  ...\n}\n...\n```\nOr create a separte loop that will use requestAnimationFrame to process events:\n```js\nfunction update() {\n  joypadManager.update();\n  requestAnimationFrame(update);\n}\n\nupdate();\n```\n#### Access Joypads\n\n[Joypads](/docs/classes/_joypad_.joypad.md) may be accessed via the `joypadManager.joypads` property:\n```js\nconst joypads = joypadManager.joypads;\nconst joypad = joypads[0];\nconst joypadTwo = joypads[1];\n...\n```\nThe default number of joypads is 4. It will create the joypad instances even if there is no gamepad connected. The [`joypad.isConnected`](/docs/classes/_joypad_.joypad.md#isconnected) property can be used to check if a joypad is connected:\n```js\n// after connecting one gamepad to your device:\njoypad.isConnected; // true\njoypadTwo.isConnected; // false\n```\n\n#### Add Event Listeners\n\nAdding event listeners is done through the [`joypad.addEventListener`](/docs/classes/_joypad_.joypad.md#addeventlistener) function. Event listeners may be added to both connected and disconnected joypads.\n```js\njoypad.addEventListener('connect', (event) => {\n  // do something with this joypad on connect\n})\n```\nAll [events](/docs/interfaces/_joypadeventemitter_.joypadevent.md) include the following properties:\n\n* `joypad` - the Joypad instance.  \n* `nativePad` - the native Gamepad instance.\n\n##### Button Events\n\nThere are three [button events](docs/interfaces/_joypadeventemitter_.joypadbuttonevent.md):\n\n* `buttonpress` - dispatched when a button is pressed.  \n* `buttonrelease` - dispatched when a button is released.\n* `buttonchange` - dispatched when the value of an analog button is changed. `buttonpress` and `buttonrelease` are still dispatched when analog values change to 1 or 0.\n\n```js\njoypad.addEventListener('buttonpress', (event) => {\n  // do something on button press\n})\n```\nAll button events include the previously mentioned `joypad` and `nativePad` properties as well as the following:\n\n* `button`  - the current button state, includes the following properties:  \n  * `name` - the name of the button - this can be changed via custom mappings.\n  * `value` - the value of the mapped button\n* `index` - the index of the button in the native gamepad's buttons array.\n* `nativeButton` - the native gamepad button object\n\n#### Stick Events\nThere is one [stick event](docs/interfaces/_joypadeventemitter_.joypadstickevent.md): \n* `stickmove` - dispatched when one of the axes for a stick is changed.\n```js\njoypad.addEventListener('stickmove', (event) => {\n  // do something on button press\n})\n```\nAll stick events include the previously mentioned `joypad` and `nativePad` properties as well as the following:\n\n* `stick`  - the current stick state, includes the following properties:  \n  * `name` - the name of the stick - this can be changed via custom mappings.\n  * `value` - the values of the stick axes, as well as angle:\n    * `x` - this will be zero if less than the configured axis deadzone\n    * `y` - this will be zero if less than the configured axis deadzone\n    * `angle` - in radians\n* `index` - the indexes of the axes in the native gamepad's axes array.\n* `nativeAxes` - the native values of the x and y axes\n  * `x`\n  * `y`\n\n#### Vibration\nAs of now - [vibration](/docs/classes/_joypad_.joypad.md#vibrate) is only available in Chrome:\n```js\njoypad.vibrate(params)\n```\nThe vibration paramaters are taken from the native Chrome paramaters, and will likely be changed in the future as other browsers add support:\n* `startDelay` - delay in milliseconds before starting the vibration effect.\n* `duration` - duration in milliseconds to play the effect.\n* `weakMagnitude` - the magnitude of the weak motor between 0 and 1.\n* `strongMagnitude` - the magnitude of the strong motor between 0 and 1.\n\nA vibration may be stopped prematurely by calling [`joypad.stopVibrate()`](/docs/classes/_joypad_.joypad.md#stopvibrate).\n","readmeFilename":"README.md"}