-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converted to typescript, published to npm
- Loading branch information
1 parent
986608d
commit e8225c8
Showing
25 changed files
with
1,322 additions
and
3,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = crlf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
# Matches the exact files either *.json or *.yml | ||
[*.{json,yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// https://eslint.org/docs/user-guide/configuring/ | ||
|
||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true, | ||
"commonjs": true, | ||
"shared-node-browser": true | ||
}, | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"quotes": ["warn", "double"], | ||
"semi": ["warn", "always"], | ||
"no-unused-vars": ["warn", { "args": "none" }], | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-empty-function": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
############################### | ||
# Git Line Endings # | ||
############################### | ||
|
||
# Set default behaviour to automatically normalize line endings. | ||
* text=auto eol=crlf | ||
|
||
# Force batch scripts to always use CRLF line endings so that if a repo is accessed | ||
# in Windows via a file share from Linux, the scripts will work. | ||
*.{cmd,[cC][mM][dD]} text eol=crlf | ||
*.{bat,[bB][aA][tT]} text eol=crlf | ||
|
||
# Force bash scripts to always use LF line endings so that if a repo is accessed | ||
# in Unix via a file share from Windows, the scripts will work. | ||
*.sh text eol=lf | ||
|
||
############################### | ||
# Git Large File System (LFS) # | ||
############################### | ||
|
||
# Archives | ||
*.7z filter=lfs diff=lfs merge=lfs -text | ||
*.br filter=lfs diff=lfs merge=lfs -text | ||
*.gz filter=lfs diff=lfs merge=lfs -text | ||
*.tar filter=lfs diff=lfs merge=lfs -text | ||
*.zip filter=lfs diff=lfs merge=lfs -text | ||
|
||
# Documents | ||
*.pdf filter=lfs diff=lfs merge=lfs -text | ||
|
||
# Images | ||
*.gif filter=lfs diff=lfs merge=lfs -text | ||
*.ico filter=lfs diff=lfs merge=lfs -text | ||
*.jpg filter=lfs diff=lfs merge=lfs -text | ||
*.jpeg filter=lfs diff=lfs merge=lfs -text | ||
*.pdf filter=lfs diff=lfs merge=lfs -text | ||
*.png filter=lfs diff=lfs merge=lfs -text | ||
*.psd filter=lfs diff=lfs merge=lfs -text | ||
*.webp filter=lfs diff=lfs merge=lfs -text | ||
|
||
# Fonts | ||
*.woff2 filter=lfs diff=lfs merge=lfs -text | ||
*.ttf filter=lfs diff=lfs merge=lfs -text | ||
|
||
# Other | ||
*.exe filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: publish | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: use node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
cache: yarn | ||
|
||
- run: yarn install --frozen-lockfile | ||
|
||
- run: yarn format | ||
|
||
- run: yarn build | ||
|
||
- run: | | ||
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_ACCESS_TOKEN }}" > .npmrc | ||
npm pack | ||
npm publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.vscode | ||
node_modules | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!lib/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
16.6.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 100, | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"editorconfig.editorconfig", | ||
"esbenp.prettier-vscode", | ||
"mike-co.import-sorter" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.detectIndentation": false, | ||
"editor.formatOnPaste": true, | ||
"editor.formatOnSave": true, | ||
"editor.insertSpaces": false, | ||
"editor.tabSize": 4, | ||
"eslint.validate": ["javascript", "typescript"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,60 @@ | ||
The ```GamepadHelper``` class in ```gamepadhelper.js``` can be copied into any project, imported as a module into existing code, instantiated, and then used by calling the ```GamepadHelper.update()``` method within the game loop (see ```game.js``` for a simple example). Supports up to 4 gamepads connected simultaneously. | ||
```bash | ||
npm install gamepad-helper | ||
or | ||
yarn add gamepad-helper | ||
``` | ||
|
||
The `GamepadHelper` class imported as a module into existing code and used by calling the static `GamepadHelper.update()` method within the game loop. Supports up to 4 gamepads connected simultaneously. | ||
|
||
```javascript | ||
import GamepadHelper from "gamepad-helper"; | ||
|
||
When a button on a connected gamepad is pressed or released, a custom event will be dispatched to the document containing the respective indexes of the gamepad and button that was pressed/released in the ```detail``` property of the event. | ||
// call inside game loop | ||
GamepadHelper.update(); | ||
``` | ||
|
||
When a button on a connected gamepad is pressed or released, a custom event will be dispatched to the document containing a `detail` property identifying the gamepad/button that was pressed/released. | ||
|
||
There are two custom event types: | ||
- ```gamepadbuttondown``` - dispatched when the ```value``` property of any button changes from 0 to 1 | ||
- ```gamepadbuttonup``` - dispatched when the ```value``` property of any button changes from 1 to 0 | ||
|
||
Here is an example event listener that simply logs the gamepad/button that was pressed down: | ||
- `gamepadbuttondown` - dispatched when the `value` property of any button changes from `0` to `1` | ||
- `gamepadbuttonup` - dispatched when the `value` property of any button changes from `1` to `0` | ||
|
||
Here is an example that simply logs the gamepad/button that was pressed down: | ||
|
||
```javascript | ||
document.addEventListener('gamepadbuttondown', (event) => { | ||
console.log('button ' + event.detail.button + ' on gamepad ' + event.detail.gamepad + ' was pressed down'); | ||
document.addEventListener("gamepadbuttondown", (event) => { | ||
console.log( | ||
"button " + | ||
event.detail.button + | ||
" on gamepad " + | ||
event.detail.gamepad + | ||
" was pressed down" | ||
); | ||
}); | ||
``` | ||
|
||
Here is a code sample which causes player 1 to jump if button 0 on gamepad 0 is released: | ||
Here is an example which causes player 1 to jump if button 0 on gamepad 0 is released: | ||
|
||
```javascript | ||
document.addEventListener('gamepadbuttonup', (event) => { | ||
if (event.detail.gamepad == 0 && event.detail.button == 0) { | ||
player1.jump(); | ||
} | ||
document.addEventListener("gamepadbuttonup", (event) => { | ||
if (event.detail.gamepad == 0 && event.detail.button == 0) { | ||
player1.jump(); | ||
} | ||
}); | ||
``` | ||
|
||
The current state of any button or axis on a connected gamepad can also be queried via the ```getButtonValue(gamepad, button)``` and ```getAxisValue(gamepad, axis)``` methods. | ||
The instantaneous state of any button or axis on a connected gamepad can also be queried via the `getButtonValue()` and `getAxisValue()` methods. | ||
|
||
The ```mode``` property of an instance of the ```GamepadHelper``` class can be set 'default' to 'xbox' or 'playstation' to change the button labels if desired: | ||
The `mode` property of an instance of the `GamepadHelper` class can be set to `default` (numeric labels), `xbox`, or `playstation` to change the button labels if desired: | ||
|
||
```javascript | ||
let gamepadhelper = new GamepadHelper(); | ||
gamepadhelper.mode = 'xbox'; | ||
gamepadhelper.mode = 'playstation'; | ||
GamepadHelper.setMode("default"); | ||
GamepadHelper.setMode("xbox"); | ||
GamepadHelper.setMode("playstation"); | ||
``` | ||
|
||
More info on the Gamepad API: | ||
- https://www.w3.org/TR/gamepad/ | ||
- https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API | ||
|
||
- https://www.w3.org/TR/gamepad/ | ||
- https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API |
Oops, something went wrong.