File tree Expand file tree Collapse file tree 2 files changed +68
-65
lines changed Expand file tree Collapse file tree 2 files changed +68
-65
lines changed Original file line number Diff line number Diff line change 1
1
import { InputSource } from '../input.js' ;
2
2
3
+ const BUTTON_CODES = /** @type {const } */ ( {
4
+ A : 0 ,
5
+ B : 1 ,
6
+ X : 2 ,
7
+ Y : 3 ,
8
+ LB : 4 ,
9
+ RB : 5 ,
10
+ LT : 6 ,
11
+ RT : 7 ,
12
+ SELECT : 8 ,
13
+ START : 9 ,
14
+ LEFT_STICK : 10 ,
15
+ RIGHT_STICK : 11
16
+ } ) ;
17
+ const BUTTON_COUNT = Object . keys ( BUTTON_CODES ) . length ;
18
+
3
19
/**
4
20
* Game pad input source class
5
21
*
@@ -18,30 +34,17 @@ class GamepadSource extends InputSource {
18
34
*
19
35
* @readonly
20
36
*/
21
- static buttonCode = {
22
- A : 0 ,
23
- B : 1 ,
24
- X : 2 ,
25
- Y : 3 ,
26
- LB : 4 ,
27
- RB : 5 ,
28
- LT : 6 ,
29
- RT : 7 ,
30
- SELECT : 8 ,
31
- START : 9 ,
32
- LEFT_STICK : 10 ,
33
- RIGHT_STICK : 11
34
- } ;
37
+ static buttonCode = BUTTON_CODES ;
35
38
36
39
/**
37
40
* @type {number[] }
38
41
* @private
39
42
*/
40
- _buttonPrev = Array ( 11 ) . fill ( 0 ) ;
43
+ _buttonPrev = Array ( BUTTON_COUNT ) . fill ( 0 ) ;
41
44
42
45
constructor ( ) {
43
46
super ( {
44
- buttons : Array ( 11 ) . fill ( 0 ) ,
47
+ buttons : Array ( BUTTON_COUNT ) . fill ( 0 ) ,
45
48
leftStick : [ 0 , 0 ] ,
46
49
rightStick : [ 0 , 0 ]
47
50
} ) ;
@@ -71,7 +74,7 @@ class GamepadSource extends InputSource {
71
74
}
72
75
73
76
// check if gamepad has enough buttons
74
- if ( gp . buttons . length < 12 ) {
77
+ if ( gp . buttons . length < BUTTON_COUNT ) {
75
78
continue ;
76
79
}
77
80
Original file line number Diff line number Diff line change 1
1
import { InputSource } from '../input.js' ;
2
2
3
- /** @type {AddEventListenerOptions & EventListenerOptions } */
4
- const PASSIVE = { passive : false } ;
5
- const KEY_COUNT = 42 ;
3
+ const PASSIVE = /** @type {AddEventListenerOptions & EventListenerOptions } */ ( { passive : false } ) ;
4
+ const KEY_CODES = /** @type {const } */ ( {
5
+ A : 0 ,
6
+ B : 1 ,
7
+ C : 2 ,
8
+ D : 3 ,
9
+ E : 4 ,
10
+ F : 5 ,
11
+ G : 6 ,
12
+ H : 7 ,
13
+ I : 8 ,
14
+ J : 9 ,
15
+ K : 10 ,
16
+ L : 11 ,
17
+ M : 12 ,
18
+ N : 13 ,
19
+ O : 14 ,
20
+ P : 15 ,
21
+ Q : 16 ,
22
+ R : 17 ,
23
+ S : 18 ,
24
+ T : 19 ,
25
+ U : 20 ,
26
+ V : 21 ,
27
+ W : 22 ,
28
+ X : 23 ,
29
+ Y : 24 ,
30
+ Z : 25 ,
31
+ '0' : 26 ,
32
+ '1' : 27 ,
33
+ '2' : 28 ,
34
+ '3' : 29 ,
35
+ '4' : 30 ,
36
+ '5' : 31 ,
37
+ '6' : 32 ,
38
+ '7' : 33 ,
39
+ '8' : 34 ,
40
+ '9' : 35 ,
41
+ UP : 36 ,
42
+ DOWN : 37 ,
43
+ LEFT : 38 ,
44
+ RIGHT : 39 ,
45
+ SPACE : 40 ,
46
+ SHIFT : 41 ,
47
+ CTRL : 42
48
+ } ) ;
49
+ const KEY_COUNT = Object . keys ( KEY_CODES ) . length ;
6
50
7
51
const array = Array ( KEY_COUNT ) . fill ( 0 ) ;
8
52
@@ -25,51 +69,7 @@ class KeyboardMouseSource extends InputSource {
25
69
*
26
70
* @readonly
27
71
*/
28
- static keyCode = {
29
- A : 0 ,
30
- B : 1 ,
31
- C : 2 ,
32
- D : 3 ,
33
- E : 4 ,
34
- F : 5 ,
35
- G : 6 ,
36
- H : 7 ,
37
- I : 8 ,
38
- J : 9 ,
39
- K : 10 ,
40
- L : 11 ,
41
- M : 12 ,
42
- N : 13 ,
43
- O : 14 ,
44
- P : 15 ,
45
- Q : 16 ,
46
- R : 17 ,
47
- S : 18 ,
48
- T : 19 ,
49
- U : 20 ,
50
- V : 21 ,
51
- W : 22 ,
52
- X : 23 ,
53
- Y : 24 ,
54
- Z : 25 ,
55
- '0' : 26 ,
56
- '1' : 27 ,
57
- '2' : 28 ,
58
- '3' : 29 ,
59
- '4' : 30 ,
60
- '5' : 31 ,
61
- '6' : 32 ,
62
- '7' : 33 ,
63
- '8' : 34 ,
64
- '9' : 35 ,
65
- UP : 36 ,
66
- DOWN : 37 ,
67
- LEFT : 38 ,
68
- RIGHT : 39 ,
69
- SPACE : 40 ,
70
- SHIFT : 41 ,
71
- CTRL : 42
72
- } ;
72
+ static keyCode = KEY_CODES ;
73
73
74
74
/**
75
75
* @type {number }
You can’t perform that action at this time.
0 commit comments