Skip to content

Commit b733cff

Browse files
committed
Wrote an example plugin
1 parent 350f969 commit b733cff

6 files changed

+25
-8
lines changed

Diff for: demo/examplePlugin.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Example Plugin for the libarary
2+
3+
export default function ExamplePlugin() {
4+
return {
5+
onAddPlugin: () => console.log('ExamplePlugin addPlugin()'),
6+
onGetState: (CurrentResponsiveGamepadState) => {
7+
CurrentResponsiveGamepadState.EXAMPLE_PLUGIN_ADDED = true;
8+
return CurrentResponsiveGamepadState;
9+
}
10+
}
11+
}

Diff for: demo/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import { h, render, Component } from 'preact';
22
import {ResponsiveGamepad} from '../dist/responsive-gamepad.esm';
33

4+
import ExamplePlugin from './examplePlugin';
5+
46
import ResponsiveGamepadState from './state';
57
import Touchpad from './touchpad';
68

79
import './index.css';
810

9-
ResponsiveGamepad.onInputsChange('DPAD_UP', state => {
10-
console.log('demo: DPAD_UP!', state.DPAD_UP);
11-
console.log('demo: state', state);
12-
});
11+
ResponsiveGamepad.onInputsChange(
12+
ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS.DPAD_UP,
13+
state => {
14+
console.log('demo: DPAD_UP!', state.DPAD_UP);
15+
console.log('demo: state', state);
16+
}
17+
);
1318

1419
class ResponsiveGamepadDemo extends Component {
1520
componentDidMount() {
21+
ResponsiveGamepad.addPlugin(ExamplePlugin());
1622
ResponsiveGamepad.enable();
1723
}
1824

Diff for: dist/responsive-gamepad.cjs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ class ResponsiveGamepadService {
949949
});
950950
this.plugins.forEach(plugin => {
951951
if (plugin.onGetState) {
952-
const response = plugin.onGetState(this.state);
952+
const response = plugin.onGetState(state);
953953

954954
if (response) {
955955
this.state = response;

Diff for: dist/responsive-gamepad.esm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ class ResponsiveGamepadService {
945945
});
946946
this.plugins.forEach(plugin => {
947947
if (plugin.onGetState) {
948-
const response = plugin.onGetState(this.state);
948+
const response = plugin.onGetState(state);
949949

950950
if (response) {
951951
this.state = response;

Diff for: dist/responsive-gamepad.umd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@
951951
});
952952
this.plugins.forEach(plugin => {
953953
if (plugin.onGetState) {
954-
const response = plugin.onGetState(this.state);
954+
const response = plugin.onGetState(state);
955955

956956
if (response) {
957957
this.state = response;

Diff for: lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ResponsiveGamepadService {
153153

154154
this.plugins.forEach(plugin => {
155155
if (plugin.onGetState) {
156-
const response = plugin.onGetState(this.state);
156+
const response = plugin.onGetState(state);
157157
if (response) {
158158
this.state = response;
159159
}

0 commit comments

Comments
 (0)