Skip to content

Commit

Permalink
Refactor the entire package to match the phaser3 standard
Browse files Browse the repository at this point in the history
  • Loading branch information
florianvazelle committed Feb 13, 2022
1 parent 28886eb commit 23740c8
Show file tree
Hide file tree
Showing 28 changed files with 231,647 additions and 942 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
103 changes: 103 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"root": true,
"env": {
"browser": true,
"es6": true,
"commonjs": true
},
"plugins": [
"es5"
],
"extends": [
"eslint:recommended"
],
"globals": {
"WEBGL_RENDERER": true,
"CANVAS_RENDERER": true,
"Phaser": true,
"process": true,
"ActiveXObject": true,
"FBInstant": true
},
"rules": {

"es5/no-arrow-functions": 2,
"es5/no-binary-and-octal-literals": 2,
"es5/no-block-scoping": 2,
"es5/no-classes": 2,
"es5/no-computed-properties": 2,
"es5/no-default-parameters": 2,
"es5/no-destructuring": 2,
"es5/no-es6-static-methods": 2,
"es5/no-for-of": 2,
"es5/no-generators": 2,
"es5/no-modules": 2,
"es5/no-object-super": 2,
"es5/no-rest-parameters": 2,
"es5/no-shorthand-properties": 2,
"es5/no-spread": 2,
"es5/no-template-literals": 2,
"es5/no-typeof-symbol": 2,
"es5/no-unicode-code-point-escape": 2,
"es5/no-unicode-regex": 2,

"no-cond-assign": [ "error", "except-parens" ],
"no-duplicate-case": [ "error" ],

"accessor-pairs": "error",
"curly": "error",
"eqeqeq": [ "error", "smart" ],
"no-alert": "error",
"no-caller": "error",
"no-console": [ "error", { "allow": ["warn", "log"] } ],
"no-floating-decimal": "error",
"no-invalid-this": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-redeclare": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"yoda": [ "error", "never" ],

"array-bracket-spacing": [ "error", "always" ],
"block-spacing": [ "error", "always" ],
"brace-style": [ "error", "allman", { "allowSingleLine": true } ],
"camelcase": "error",
"comma-dangle": [ "error", "never" ],
"comma-style": [ "error", "last" ],
"computed-property-spacing": [ "error", "never" ],
"consistent-this": [ "error", "_this" ],
"eol-last": [ "error" ],
"func-call-spacing": [ "error", "never" ],
"indent": [ "error", 4, { "SwitchCase": 1 } ],
"key-spacing": [ "error", { "beforeColon": false, "afterColon": true } ],
"keyword-spacing": [ "error", { "after": true } ],
"linebreak-style": [ "off" ],
"lines-around-comment": [ "error", { "beforeBlockComment": true, "afterBlockComment": false, "beforeLineComment": true, "afterLineComment": false, "allowBlockStart": true, "allowBlockEnd": false, "allowObjectStart": true, "allowArrayStart": true }],
"new-parens": "error",
"no-constant-condition": 0,
"no-array-constructor": "error",
"no-lonely-if": "error",
"no-mixed-spaces-and-tabs": "error",
"no-plusplus": "off",
"no-prototype-builtins": "off",
"no-trailing-spaces": [ "error", { "skipBlankLines": true, "ignoreComments": true } ],
"no-underscore-dangle": "off",
"no-whitespace-before-property": "error",
"object-curly-newline": [ "error", { "multiline": true, "minProperties": 0, "consistent": true } ],
"one-var-declaration-per-line": [ "error", "initializations" ],
"quote-props": [ "error", "as-needed" ],
"quotes": [ "error", "single" ],
"semi-spacing": [ "error", { "before": false, "after": true } ],
"semi": [ "error", "always" ],
"space-before-blocks": "error",
"space-before-function-paren": "error",
"space-in-parens": [ "error", "never" ],
"space-infix-ops": [ "error", { "int32Hint": true } ],
"wrap-regex": "error",
"spaced-comment": [ "error", "always", { "block": { "balanced": true, "exceptions": ["*", "!"] }} ]

}
}
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.js text
*.ts text
*.md text
*.json text
*.vert text
*.frag text

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.ico binary
*.gif binary
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on: push

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10
- run: npm install
- run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
phaser-version: [3.24.1, 3.52.0]
env:
PHASER_VERSION: ${{ matrix.phaser-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10
- run: npm install
- run: npm test
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 10
- run: npm install
- run: mv -r dist old-dist
- run: npm run build
- run: diff dist old-dist
13 changes: 13 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on:
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Thumbs.db
.DS_Store
.idea
.vscode
*.suo
*.sublime-project
*.sublime-workspace
Expand All @@ -12,3 +13,4 @@ node_modules/
# Build
build/
/npm-debug.log
.parcel-cache
76 changes: 76 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

**/.*
art
build
config
demo
src
.editorconfig
.eslintignore
.eslintrc
.gitignore
webpack.*
jest.config.js
*.map
*.iml
.idea/*
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018-2021 Florian Vazelle

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
# Phaser 3 VJoy Plugin

A simple plugin for Phaser 3 to allow you to use a joystick in your game.
[![Package version](https://img.shields.io/npm/v/phaser3-vjoy-plugin)](https://nodei.co/npm/phaser3-vjoy-plugin/)
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/phaser3-vjoy-plugin)
![npm bundle size](https://img.shields.io/bundlephobia/min/phaser3-vjoy-plugin)
![Total downloads](https://img.shields.io/npm/dt/phaser3-vjoy-plugin)
[![License](https://img.shields.io/npm/l/phaser3-vjoy-plugin)](https://opensource.org/licenses/MIT)

- Inspired by [InformalPenguins/phaser-vjoy-plugin](https://github.com/InformalPenguins/phaser-vjoy-plugin)
A simple plugin for Phaser 3, to allow you to use a joystick in your computer or mobile game.

The output javascript package is a classic script that could be loaded in a `<script>` tag in the browser, or loaded by Node.js or another bundler.

## Getting Started

To install it with [npm](https://www.npmjs.com), run :

```
npm i phaser3-vjoy-plugin --save
```

## Usage

### Load the Plugin

As in the [phaser documentation](https://photonstorm.github.io/phaser3-docs/Phaser.Plugins.PluginManager.html#installScenePlugin__anchor), do something like this :

```javascript
import 'phaser';
import VJoyPlugin from 'phaser3-vjoy-plugin';

...

this.plugins.installScenePlugin('VJoyPlugin', VJoyPlugin, 'vjoy', this);

// and from within the scene :
this.sys.VJoyPlugin; // key value
this.vjoy; // mapping value
```

or, if you just use the dist file :

```javascript
this.load.scenePlugin('VJoyPlugin', './VJoyPlugin.js', null, 'vjoy');
```

### Examples

To test the plugin, check the [online demo](https://florianvazelle.github.io/phaser3-vjoy-plugin/).

If you want to see the full implementation, you can find an example in the `demo` directory. You can run `npm run demo` to test it.

Or, if you want to use `import` statement, you can go to [phaser3-vjoy-plugin-demo](https://github.com/florianvazelle/phaser3-vjoy-plugin-demo).

## Development

Run `npm install` and then `npm run build` to build the plugin.

Run `npm run demo` to try example.
## References

- Based on [Phaser VJoy Plugin by Informal Penguins](https://github.com/InformalPenguins/phaser-vjoy-plugin)
- Using of [Phaser3 Plugin Template by Photonstorm](https://github.com/photonstorm/phaser3-plugin-template)

Good plugin examples:
- [Phaser Lifecycle Plugin by Sporadic Labs](https://github.com/sporadic-labs/phaser-lifecycle-plugin)
- [Phaser3 Plugin Project Starter by Agogpixel](https://github.com/agogpixel/phaser3-plugin-project-starter)
Loading

0 comments on commit 23740c8

Please sign in to comment.