Skip to content

Commit

Permalink
improve usage explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
lunarcloud committed Jul 4, 2024
1 parent 535328f commit 6db8db6
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,42 @@
=============
A client-side JavaScript module one can import to add good gamepad support to web-powered games or other gamepad-powered web applications.

## Installation

GameinputJS's `src` and `img` folders need to be accessible in the distributed version of your website.

I would recommend setting up a `package.json` script to help update a distributable copy of the library outside node_modules:
```json
{
"name": "@me/my-client-webapp",
"scripts": {
"deps2lib": "shx rm -rf lib && shx cp -r node_modules/gameinputjs lib/"
}
...
}
```
Which would allow you to run:

```sh
npm i --save-dev shx
npm i gameinputjs
npm run deps2lib
```


## Usage
Import from within a Javascript module, construct it, and then use either the events or make a game loop that uses the properties.

```js
import { GameInput, DetectedOS } from './lib/gameinputjs/src/gameinput.js'
import { GameInputSchemaSectionNames, GameInputSchemaButtonNames } from './lib/gameinputjs/src/gameinput-schema.js'

/** @type {GameInput} */
const gameInput = new GameInput()
// Events style
```

### Event-Driven Style
```js
gameInput
.onReinitialize(() => {
console.debug("Players updated")
const firstPlayer = gameInput.getPlayer(0)
Expand Down Expand Up @@ -38,8 +65,10 @@ const gameInput = new GameInput()
console.debug('Jump / Confirm pushed')
}
})
```
// Game-Loop Style
### Game-Loop Style
```js
function gameLoop() {
for (const player of gameInput.Players) {
if (!player)
Expand All @@ -55,25 +84,3 @@ function gameLoop() {
}
requestAnimationFrame(() => gameLoop()) // kick off
```
## Installation
GameinputJS's `src` and `img` folders need to be accessible in the distributed version of your website.
I would recommend setting up a `package.json` script to help update a distributable copy of the library outside node_modules:
```json
{
"name": "@me/my-client-webapp",
"scripts": {
"deps2lib": "shx rm -rf lib && shx cp -r node_modules/gameinputjs lib/"
}
...
}
```
Which would allow you to run:
```sh
npm i --save-dev shx
npm i gameinputjs
npm run deps2lib
```

0 comments on commit 6db8db6

Please sign in to comment.