@vnejs/plugins.subfeature.controls.gamepad 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/modules/gamepad.js +31 -10
  2. package/package.json +1 -1
@@ -5,11 +5,13 @@ import { Module } from "@vnejs/module";
5
5
  export class Gamepad extends Module {
6
6
  name = "controls.gamepad";
7
7
 
8
- init = async () => {
8
+ isTriggerAllowedToPress = false;
9
+
10
+ init = () => {
9
11
  const [ABSTRACT, GAMEPAD] = [this.CONST.CONTROLS.BUTTONS, this.CONST.GAMEPAD.BUTTONS];
10
12
 
11
13
  const BUTTON_PRESS_TO_KEYS_MAP = {
12
- button_0: [GAMEPAD.MAIN_BUTTON_BOTTOM, GAMEPAD.ANY, ABSTRACT.INTERACT, ABSTRACT.ANY],
14
+ button_0: [GAMEPAD.MAIN_BUTTON_BOTTOM, GAMEPAD.ANY, ABSTRACT.ACCEPT, ABSTRACT.ANY],
13
15
  button_1: [GAMEPAD.MAIN_BUTTON_RIGHT, GAMEPAD.ANY, ABSTRACT.BACK, ABSTRACT.ANY],
14
16
  button_2: [GAMEPAD.MAIN_BUTTON_LEFT, GAMEPAD.ANY, ABSTRACT.INTERACT, ABSTRACT.ANY],
15
17
  button_3: [GAMEPAD.MAIN_BUTTON_UP, GAMEPAD.ANY, ABSTRACT.MENU, ABSTRACT.ANY],
@@ -17,30 +19,49 @@ export class Gamepad extends Module {
17
19
  button_4: [GAMEPAD.BUMPER_LEFT, GAMEPAD.ANY, ABSTRACT.TAB_PREV, ABSTRACT.ANY],
18
20
  button_5: [GAMEPAD.BUMPER_RIGHT, GAMEPAD.ANY, ABSTRACT.TAB_NEXT, ABSTRACT.ANY],
19
21
 
20
- button_6: [GAMEPAD.TRIGGER_LEFT_KEYDOWN, GAMEPAD.ANY, ABSTRACT.FASTFORWARD_START, ABSTRACT.ANY],
21
- // button_7: [GAMEPAD.TRIGGER_RIGHT_KEYDOWN, GAMEPAD.ANY, ABSTRACT.FASTFORWARD_START, ABSTRACT.ANY],
22
-
23
22
  button_8: [GAMEPAD.MENU, GAMEPAD.ANY, ABSTRACT.GAMEMENU, ABSTRACT.ANY],
24
23
  button_9: [GAMEPAD.START, GAMEPAD.ANY, ABSTRACT.MENU, ABSTRACT.ANY],
24
+
25
+ button_12: [GAMEPAD.ARROW_UP, GAMEPAD.ANY, ABSTRACT.ARROW_UP, ABSTRACT.ANY],
26
+ button_13: [GAMEPAD.ARROW_BOTTOM, GAMEPAD.ANY, ABSTRACT.ARROW_BOTTOM, ABSTRACT.ANY],
27
+ button_14: [GAMEPAD.ARROW_LEFT, GAMEPAD.ANY, ABSTRACT.ARROW_LEFT, ABSTRACT.ANY],
28
+ button_15: [GAMEPAD.ARROW_RIGHT, GAMEPAD.ANY, ABSTRACT.ARROW_RIGHT, ABSTRACT.ANY],
25
29
  };
26
30
 
27
31
  const BUTTON_RELEASE_TO_KEYS_MAP = {
28
32
  button_6: [GAMEPAD.TRIGGER_LEFT_KEYUP, GAMEPAD.ANY, ABSTRACT.FASTFORWARD_FINISH, ABSTRACT.ANY],
29
- // button_7: [GAMEPAD.TRIGGER_RIGHT_KEYUP, GAMEPAD.ANY, ABSTRACT.FASTFORWARD_FINISH, ABSTRACT.ANY],
33
+ button_7: [GAMEPAD.TRIGGER_RIGHT_KEYUP, GAMEPAD.ANY, ABSTRACT.ANY],
30
34
  };
31
35
 
32
- // button_7 - click
36
+ const BUTTON_TRIGGERS_PRESS_TO_KEYS_MAP = {
37
+ button_6: [GAMEPAD.TRIGGER_LEFT_KEYDOWN, GAMEPAD.ANY, ABSTRACT.FASTFORWARD_START, ABSTRACT.ANY],
38
+ button_7: [GAMEPAD.TRIGGER_RIGHT_KEYDOWN, GAMEPAD.ANY, ABSTRACT.ANY],
39
+ };
33
40
 
34
41
  joypad.on("button_press", (e) => this.emitControlEvent(BUTTON_PRESS_TO_KEYS_MAP[e.detail.buttonName]));
35
- joypad.on("button_release", (e) => this.emitControlEvent(BUTTON_RELEASE_TO_KEYS_MAP[e.detail.buttonName]));
36
- joypad.on("axis_move", (e) => {
37
- // move cursor
42
+
43
+ joypad.on("button_release", (e) => {
44
+ if (!BUTTON_RELEASE_TO_KEYS_MAP[e.detail.buttonName]) return;
45
+
46
+ return this.emitControlEvent(BUTTON_RELEASE_TO_KEYS_MAP[e.detail.buttonName]);
47
+ });
48
+
49
+ joypad.on("button_press", (e) => {
50
+ if (!BUTTON_TRIGGERS_PRESS_TO_KEYS_MAP[e.detail.buttonName]) return;
51
+
52
+ if (this.isTriggerAllowedToPress) {
53
+ return this.emitControlEvent(BUTTON_TRIGGERS_PRESS_TO_KEYS_MAP[e.detail.buttonName]);
54
+ }
55
+
56
+ this.isTriggerAllowedToPress = true;
38
57
  });
39
58
  };
40
59
 
41
60
  emitControlEvent = async (keys) => {
42
61
  if (this.inProcess || !keys) return;
43
62
 
63
+ this.isTriggerAllowedToPress = true;
64
+
44
65
  this.inProcess = true;
45
66
  await this.emit(this.EVENTS.CONTROLS.EMIT, { keys });
46
67
  this.inProcess = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.subfeature.controls.gamepad",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",