pxt-common-packages 9.4.13 → 9.4.16
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.
- package/built/common-sim.d.ts +44 -0
- package/built/common-sim.js +202 -63
- package/libs/azureiot/built/debug/binary.js +461 -461
- package/libs/color/built/debug/binary.js +8 -8
- package/libs/color-sensor/built/debug/binary.js +8 -8
- package/libs/controller/built/debug/binary.js +8290 -8027
- package/libs/controller---none/built/debug/binary.js +8269 -8006
- package/libs/datalogger/built/debug/binary.js +63 -63
- package/libs/edge-connector/built/debug/binary.js +8 -8
- package/libs/esp32/built/debug/binary.js +462 -462
- package/libs/game/_locales/game-jsdoc-strings.json +19 -0
- package/libs/game/_locales/game-strings.json +2 -0
- package/libs/game/built/debug/binary.js +8182 -7919
- package/libs/game/extendableSprite.ts +80 -0
- package/libs/game/hitbox.ts +42 -1
- package/libs/game/keymap.cpp +12 -0
- package/libs/game/keymap.ts +169 -0
- package/libs/game/pxt.json +4 -1
- package/libs/game/sim/keymap.ts +167 -0
- package/libs/game/sprite.ts +73 -95
- package/libs/lcd/built/debug/binary.js +8 -8
- package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
- package/libs/lora/built/debug/binary.js +8 -8
- package/libs/matrix-keypad/built/debug/binary.js +8 -8
- package/libs/mqtt/built/debug/binary.js +176 -176
- package/libs/net/built/debug/binary.js +176 -176
- package/libs/net-game/built/debug/binary.js +9970 -9707
- package/libs/palette/built/debug/binary.js +8181 -7918
- package/libs/pixel/built/debug/binary.js +8 -8
- package/libs/power/built/debug/binary.js +8 -8
- package/libs/proximity/built/debug/binary.js +8 -8
- package/libs/radio/built/debug/binary.js +8 -8
- package/libs/radio-broadcast/built/debug/binary.js +8 -8
- package/libs/rotary-encoder/built/debug/binary.js +8 -8
- package/libs/screen/built/debug/binary.js +50 -50
- package/libs/servo/built/debug/binary.js +8 -8
- package/libs/sprite-scaling/built/debug/binary.js +8181 -7918
- package/libs/storyboard/built/debug/binary.js +8181 -7918
- package/package.json +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
namespace sprites {
|
|
2
|
+
/**
|
|
3
|
+
* A version of the Sprite class that is easier to extend.
|
|
4
|
+
*
|
|
5
|
+
* Unlike the normal Sprite class, this class will automatically add
|
|
6
|
+
* itself to the physics engine and run all sprite created handlers
|
|
7
|
+
* in the constructor
|
|
8
|
+
*/
|
|
9
|
+
export class ExtendableSprite extends Sprite {
|
|
10
|
+
protected hasCustomDimensions: boolean;
|
|
11
|
+
|
|
12
|
+
constructor(spriteImage: Image, kind?: number) {
|
|
13
|
+
super(spriteImage);
|
|
14
|
+
|
|
15
|
+
const scene = game.currentScene();
|
|
16
|
+
this.setKind(kind);
|
|
17
|
+
scene.physicsEngine.addSprite(this);
|
|
18
|
+
|
|
19
|
+
// run on created handlers
|
|
20
|
+
scene.createdHandlers
|
|
21
|
+
.filter(h => h.kind == kind)
|
|
22
|
+
.forEach(h => h.handler(this));
|
|
23
|
+
|
|
24
|
+
this.hasCustomDimensions = false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Override to change how the sprite is drawn to the screen
|
|
29
|
+
*
|
|
30
|
+
* @param drawLeft The left position to draw the sprite at (already adjusted for camera)
|
|
31
|
+
* @param drawTop The top position to draw the sprite at (already adjusted for camera)
|
|
32
|
+
*/
|
|
33
|
+
draw(drawLeft: number, drawTop: number) {
|
|
34
|
+
super.drawSprite(drawLeft, drawTop);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Override to add update logic for a sprite. This method runs once per frame
|
|
39
|
+
*
|
|
40
|
+
* @param deltaTimeMillis The time that has elapsed since the last frame in milliseconds
|
|
41
|
+
*/
|
|
42
|
+
update(deltaTimeMillis: number) {
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets the width and height of this sprite. Once set, this will also prevent
|
|
47
|
+
* this width and height from automatically changing whenever scale or the image
|
|
48
|
+
* changes
|
|
49
|
+
*/
|
|
50
|
+
setDimensions(width: number, height: number) {
|
|
51
|
+
this._width = Fx8(width);
|
|
52
|
+
this._height = Fx8(height);
|
|
53
|
+
this.hasCustomDimensions = true;
|
|
54
|
+
this.resetHitbox();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
__update(camera: scene.Camera, dt: number) {
|
|
58
|
+
super.__update(camera, dt);
|
|
59
|
+
this.update(game.currentScene().eventContext.deltaTimeMillis)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setHitbox() {
|
|
63
|
+
if (this.hasCustomDimensions) {
|
|
64
|
+
this._hitbox = new game.Hitbox(this, this._width, this._height, Fx.zeroFx8, Fx.zeroFx8)
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
super.setHitbox();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected drawSprite(drawLeft: number, drawTop: number): void {
|
|
72
|
+
this.draw(drawLeft, drawTop);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected recalcSize() {
|
|
76
|
+
if (this.hasCustomDimensions) return;
|
|
77
|
+
super.recalcSize();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
package/libs/game/hitbox.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
namespace game {
|
|
2
2
|
export class Hitbox {
|
|
3
|
-
hash:
|
|
3
|
+
hash: number;
|
|
4
4
|
parent: Sprite;
|
|
5
5
|
ox: Fx8;
|
|
6
6
|
oy: Fx8;
|
|
@@ -46,7 +46,48 @@ namespace game {
|
|
|
46
46
|
return (x >= this.left) && (x <= this.right) && (y >= this.top) && (y <= this.bottom);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
updateIfInvalid() {
|
|
50
|
+
if (this.isValid())
|
|
51
|
+
return;
|
|
52
|
+
|
|
53
|
+
const newHitBox = game.calculateHitBox(this.parent);
|
|
54
|
+
|
|
55
|
+
const oMinX = this.ox;
|
|
56
|
+
const oMinY = this.oy;
|
|
57
|
+
const oMaxX = Fx.add(oMinX, this.width);
|
|
58
|
+
const oMaxY = Fx.add(oMinY, this.height);
|
|
59
|
+
|
|
60
|
+
const nMinX = newHitBox.ox;
|
|
61
|
+
const nMinY = newHitBox.oy;
|
|
62
|
+
const nMaxX = Fx.add(nMinX, newHitBox.width);
|
|
63
|
+
const nMaxY = Fx.add(nMinY, newHitBox.height);
|
|
64
|
+
|
|
65
|
+
// total diff in x / y corners between the two hitboxes
|
|
66
|
+
const xDiff = Fx.add(
|
|
67
|
+
Fx.abs(Fx.sub(oMinX, nMinX)),
|
|
68
|
+
Fx.abs(Fx.sub(oMaxX, nMaxX))
|
|
69
|
+
);
|
|
70
|
+
const yDiff = Fx.add(
|
|
71
|
+
Fx.abs(Fx.sub(oMinY, nMinY)),
|
|
72
|
+
Fx.abs(Fx.sub(oMaxY, nMaxY))
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// If it's just a small change to the hitbox on one axis,
|
|
76
|
+
// don't change the dimensions to avoid random clipping
|
|
77
|
+
if (xDiff > Fx.twoFx8) {
|
|
78
|
+
this.ox = nMinX;
|
|
79
|
+
this.width = newHitBox.width;
|
|
80
|
+
}
|
|
81
|
+
if (yDiff > Fx.twoFx8) {
|
|
82
|
+
this.oy = nMinY;
|
|
83
|
+
this.height = newHitBox.height;
|
|
84
|
+
}
|
|
85
|
+
this.hash = newHitBox.hash;
|
|
86
|
+
}
|
|
87
|
+
|
|
49
88
|
overlapsWith(other: Hitbox): boolean {
|
|
89
|
+
this.updateIfInvalid();
|
|
90
|
+
other.updateIfInvalid();
|
|
50
91
|
if (this.contains(other.left, other.top)) return true;
|
|
51
92
|
if (this.contains(other.left, other.bottom)) return true;
|
|
52
93
|
if (this.contains(other.right, other.top)) return true;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
namespace keymap {
|
|
2
|
+
//% shim=keymap::_setPlayerKeys
|
|
3
|
+
declare function _setPlayerKeys(
|
|
4
|
+
player: number, // player number is 1-based
|
|
5
|
+
up: number,
|
|
6
|
+
down: number,
|
|
7
|
+
left: number,
|
|
8
|
+
right: number,
|
|
9
|
+
A: number,
|
|
10
|
+
B: number
|
|
11
|
+
): void;
|
|
12
|
+
|
|
13
|
+
//% shim=keymap::_setSystemKeys
|
|
14
|
+
declare function _setSystemKeys(screenshot: number, gif: number, menu: number, reset: number): void;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sets the keyboard input map for the given player.
|
|
18
|
+
* @param player The player number. 1 = Player1, etc.
|
|
19
|
+
* @param up The key code for 'up'.
|
|
20
|
+
* @param down The key code for 'down'
|
|
21
|
+
* @param left The key code for 'left'
|
|
22
|
+
* @param right The key code for 'right'
|
|
23
|
+
* @param A The key code for 'A'
|
|
24
|
+
* @param B The key code for 'B'
|
|
25
|
+
*/
|
|
26
|
+
export function setPlayerKeys(
|
|
27
|
+
player: number, // player number is 1-based
|
|
28
|
+
up: KeyCode,
|
|
29
|
+
down: KeyCode,
|
|
30
|
+
left: KeyCode,
|
|
31
|
+
right: KeyCode,
|
|
32
|
+
A: KeyCode,
|
|
33
|
+
B: KeyCode
|
|
34
|
+
) {
|
|
35
|
+
_setPlayerKeys(player, up, down, left, right, A, B);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sets the keyboard input map for system keys.
|
|
40
|
+
* @param screenshot The key code for 'screenshot'
|
|
41
|
+
* @param gif The key code for 'gif'
|
|
42
|
+
* @param menu The key code for 'menu'
|
|
43
|
+
* @param reset The key code for 'reset'
|
|
44
|
+
*/
|
|
45
|
+
export function setSystemKeys(screenshot: KeyCode, gif: KeyCode, menu: KeyCode, reset: KeyCode) {
|
|
46
|
+
_setSystemKeys(screenshot, gif, menu, reset);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Key codes
|
|
51
|
+
*/
|
|
52
|
+
export enum KeyCode {
|
|
53
|
+
None = 0,
|
|
54
|
+
|
|
55
|
+
Backspace = 8,
|
|
56
|
+
Tab = 9,
|
|
57
|
+
Enter = 13,
|
|
58
|
+
Shift = 16,
|
|
59
|
+
Ctrl = 17,
|
|
60
|
+
Alt = 18,
|
|
61
|
+
PauseBreak = 19,
|
|
62
|
+
CapsLock = 20,
|
|
63
|
+
Escape = 27,
|
|
64
|
+
Space = 32,
|
|
65
|
+
PageUp = 33,
|
|
66
|
+
PageDown = 34,
|
|
67
|
+
End = 35,
|
|
68
|
+
Home = 36,
|
|
69
|
+
|
|
70
|
+
LeftArrow = 37,
|
|
71
|
+
UpArrow = 38,
|
|
72
|
+
RightArrow = 39,
|
|
73
|
+
DownArrow = 40,
|
|
74
|
+
|
|
75
|
+
Insert = 45,
|
|
76
|
+
Delete = 46,
|
|
77
|
+
|
|
78
|
+
Zero = 48,
|
|
79
|
+
One = 49,
|
|
80
|
+
Two = 50,
|
|
81
|
+
Three = 51,
|
|
82
|
+
Four = 52,
|
|
83
|
+
Five = 53,
|
|
84
|
+
Six = 54,
|
|
85
|
+
Seven = 55,
|
|
86
|
+
Eight = 56,
|
|
87
|
+
Nine = 57,
|
|
88
|
+
|
|
89
|
+
A = 65,
|
|
90
|
+
B = 66,
|
|
91
|
+
C = 67,
|
|
92
|
+
D = 68,
|
|
93
|
+
E = 69,
|
|
94
|
+
F = 70,
|
|
95
|
+
G = 71,
|
|
96
|
+
H = 72,
|
|
97
|
+
I = 73,
|
|
98
|
+
J = 74,
|
|
99
|
+
K = 75,
|
|
100
|
+
L = 76,
|
|
101
|
+
M = 77,
|
|
102
|
+
N = 78,
|
|
103
|
+
O = 79,
|
|
104
|
+
P = 80,
|
|
105
|
+
Q = 81,
|
|
106
|
+
R = 82,
|
|
107
|
+
S = 83,
|
|
108
|
+
T = 84,
|
|
109
|
+
U = 85,
|
|
110
|
+
V = 86,
|
|
111
|
+
W = 87,
|
|
112
|
+
X = 88,
|
|
113
|
+
Y = 89,
|
|
114
|
+
Z = 90,
|
|
115
|
+
|
|
116
|
+
LeftWindowsKey = 91,
|
|
117
|
+
RightWindowsKey = 92,
|
|
118
|
+
|
|
119
|
+
Numpad0 = 96,
|
|
120
|
+
Numpad1 = 97,
|
|
121
|
+
Numpad2 = 98,
|
|
122
|
+
Numpad3 = 99,
|
|
123
|
+
Numpad4 = 100,
|
|
124
|
+
Numpad5 = 101,
|
|
125
|
+
Numpad6 = 102,
|
|
126
|
+
Numpad7 = 103,
|
|
127
|
+
Numpad8 = 104,
|
|
128
|
+
Numpad9 = 105,
|
|
129
|
+
|
|
130
|
+
Multiply = 106,
|
|
131
|
+
Add = 107,
|
|
132
|
+
Subtract = 109,
|
|
133
|
+
DecimalPoint = 110,
|
|
134
|
+
Divide = 111,
|
|
135
|
+
|
|
136
|
+
F1 = 112,
|
|
137
|
+
F2 = 113,
|
|
138
|
+
F3 = 114,
|
|
139
|
+
F4 = 115,
|
|
140
|
+
F5 = 116,
|
|
141
|
+
F6 = 117,
|
|
142
|
+
F7 = 118,
|
|
143
|
+
F8 = 119,
|
|
144
|
+
F9 = 120,
|
|
145
|
+
F10 = 121,
|
|
146
|
+
F11 = 122,
|
|
147
|
+
F12 = 123,
|
|
148
|
+
|
|
149
|
+
NumLock = 144,
|
|
150
|
+
ScrollLock = 145,
|
|
151
|
+
|
|
152
|
+
SemiColon = 186,
|
|
153
|
+
Equals = 187,
|
|
154
|
+
Comma = 188,
|
|
155
|
+
Dash = 189,
|
|
156
|
+
Period = 190,
|
|
157
|
+
ForwardSlash = 191,
|
|
158
|
+
Tilde = 192,
|
|
159
|
+
|
|
160
|
+
OpenBracket = 219,
|
|
161
|
+
ClosedBracket = 221,
|
|
162
|
+
SingleQuote = 222,
|
|
163
|
+
|
|
164
|
+
// Mouse
|
|
165
|
+
MouseLeftButton = -1,
|
|
166
|
+
MouseRightButton = -2,
|
|
167
|
+
MouseCenterButton = -3,
|
|
168
|
+
}
|
|
169
|
+
}
|
package/libs/game/pxt.json
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"spritesay.ts",
|
|
14
14
|
"sprites.ts",
|
|
15
15
|
"sprite.ts",
|
|
16
|
+
"extendableSprite.ts",
|
|
16
17
|
"sprite.d.ts",
|
|
17
18
|
"spritemap.ts",
|
|
18
19
|
"spriteevents.ts",
|
|
@@ -48,7 +49,9 @@
|
|
|
48
49
|
"effects.ts",
|
|
49
50
|
"texteffects.ts",
|
|
50
51
|
"assetTemplates.ts",
|
|
51
|
-
"animation.ts"
|
|
52
|
+
"animation.ts",
|
|
53
|
+
"keymap.cpp",
|
|
54
|
+
"keymap.ts"
|
|
52
55
|
],
|
|
53
56
|
"public": true,
|
|
54
57
|
"dependencies": {
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
namespace pxsim.keymap {
|
|
2
|
+
// Keep in sync with pxt-arcade-sim/api.ts
|
|
3
|
+
export enum Key {
|
|
4
|
+
None = 0,
|
|
5
|
+
|
|
6
|
+
// Player 1
|
|
7
|
+
Left = 1,
|
|
8
|
+
Up = 2,
|
|
9
|
+
Right = 3,
|
|
10
|
+
Down = 4,
|
|
11
|
+
A = 5,
|
|
12
|
+
B = 6,
|
|
13
|
+
|
|
14
|
+
Menu = 7,
|
|
15
|
+
|
|
16
|
+
// Player 2 = Player 1 + 7
|
|
17
|
+
// Player 3 = Player 2 + 7
|
|
18
|
+
// Player 4 = Player 3 + 7
|
|
19
|
+
|
|
20
|
+
// system keys
|
|
21
|
+
Screenshot = -1,
|
|
22
|
+
Gif = -2,
|
|
23
|
+
Reset = -3,
|
|
24
|
+
TogglePause = -4
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function _setPlayerKeys(
|
|
28
|
+
player: number, // player number is 1-based
|
|
29
|
+
up: number,
|
|
30
|
+
down: number,
|
|
31
|
+
left: number,
|
|
32
|
+
right: number,
|
|
33
|
+
A: number,
|
|
34
|
+
B: number
|
|
35
|
+
) {
|
|
36
|
+
getKeymapState().setPlayerKeys(player, up, down, left, right, A, B);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function _setSystemKeys(screenshot: number, gif: number, menu: number, reset: number) {
|
|
40
|
+
getKeymapState().setSystemKeys(screenshot, gif, menu, reset);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
namespace pxsim {
|
|
45
|
+
import Key = pxsim.keymap.Key;
|
|
46
|
+
|
|
47
|
+
export interface KeymapBoard extends EventBusBoard {
|
|
48
|
+
keymapState: KeymapState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getKeymapState() {
|
|
52
|
+
return (board() as EventBusBoard as KeymapBoard).keymapState;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const reservedKeyCodes = [
|
|
56
|
+
27, // Escape
|
|
57
|
+
9 // Tab
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export class KeymapState {
|
|
61
|
+
keymap: { [keyCode: number]: Key } = {};
|
|
62
|
+
altmap: { [keyCode: number]: Key } = {};
|
|
63
|
+
mappings: { [name: string]: number[] } = {};
|
|
64
|
+
|
|
65
|
+
constructor() {
|
|
66
|
+
// Player 1 keymap
|
|
67
|
+
this.setPlayerKeys(
|
|
68
|
+
1, // Player 1
|
|
69
|
+
87, // W - Up
|
|
70
|
+
83, // S - Down
|
|
71
|
+
65, // A - Left
|
|
72
|
+
68, // D - Right
|
|
73
|
+
32, // Space - A
|
|
74
|
+
13 // Enter - B
|
|
75
|
+
);
|
|
76
|
+
// Player 2 keymap
|
|
77
|
+
this.setPlayerKeys(
|
|
78
|
+
2, // Player 2
|
|
79
|
+
73, // I - Up
|
|
80
|
+
75, // K - Down
|
|
81
|
+
74, // J - Left
|
|
82
|
+
76, // L - Right
|
|
83
|
+
85, // U - A
|
|
84
|
+
79 // O - B
|
|
85
|
+
);
|
|
86
|
+
// Note: Player 3 and 4 have no default keyboard mapping
|
|
87
|
+
|
|
88
|
+
// System keymap
|
|
89
|
+
this.setSystemKeys(
|
|
90
|
+
80, // P - Screenshot
|
|
91
|
+
82, // R - Gif
|
|
92
|
+
0, // Menu - not mapped
|
|
93
|
+
0 // Reset - not mapped
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Player 1 alternate mapping. This is cleared when the game sets any player keys explicitly
|
|
97
|
+
this.altmap[38] = Key.Up; // UpArrow
|
|
98
|
+
this.altmap[37] = Key.Left; // LeftArrow
|
|
99
|
+
this.altmap[40] = Key.Down; // DownArrow
|
|
100
|
+
this.altmap[39] = Key.Right; // RightArrow
|
|
101
|
+
this.altmap[81] = Key.A; // Q
|
|
102
|
+
this.altmap[90] = Key.A; // Z
|
|
103
|
+
this.altmap[88] = Key.B; // X
|
|
104
|
+
this.altmap[69] = Key.B; // E
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public setPlayerKeys(
|
|
108
|
+
player: number, // player number is 1-based
|
|
109
|
+
up: number,
|
|
110
|
+
down: number,
|
|
111
|
+
left: number,
|
|
112
|
+
right: number,
|
|
113
|
+
A: number,
|
|
114
|
+
B: number
|
|
115
|
+
) {
|
|
116
|
+
// We only support four players
|
|
117
|
+
if (player < 1 || player > 4) return;
|
|
118
|
+
const keyCodes = [up, down, left, right, A, B];
|
|
119
|
+
// Check for reserved key codes
|
|
120
|
+
// TODO: How to surface this runtime error to the user?
|
|
121
|
+
// TODO: Send message to UI: "Keyboard mapping contains a reserved key code"
|
|
122
|
+
const filtered = keyCodes.filter(keyCode => reservedKeyCodes.includes(keyCode));
|
|
123
|
+
if (filtered.length) return;
|
|
124
|
+
// Clear existing mapped keys for player
|
|
125
|
+
const mapName = `player-${player}`;
|
|
126
|
+
this.clearMap(mapName);
|
|
127
|
+
// Clear altmap When explicitly setting the player keys
|
|
128
|
+
this.altmap = {};
|
|
129
|
+
// Map the new keys
|
|
130
|
+
const offset = (player - 1) * 7; // +7 for player 2's keys
|
|
131
|
+
this.keymap[up] = Key.Up + offset;
|
|
132
|
+
this.keymap[down] = Key.Down + offset;
|
|
133
|
+
this.keymap[left] = Key.Left + offset;
|
|
134
|
+
this.keymap[right] = Key.Right + offset;
|
|
135
|
+
this.keymap[A] = Key.A + offset;
|
|
136
|
+
this.keymap[B] = Key.B + offset;
|
|
137
|
+
// Remember this mapping
|
|
138
|
+
this.saveMap(mapName, keyCodes);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public setSystemKeys(screenshot: number, gif: number, menu: number, reset: number) {
|
|
142
|
+
const mapName = "system";
|
|
143
|
+
// Clear existing mapped keys for system
|
|
144
|
+
this.clearMap(mapName);
|
|
145
|
+
this.keymap[screenshot] = Key.Screenshot;
|
|
146
|
+
this.keymap[gif] = Key.Gif;
|
|
147
|
+
this.keymap[menu] = Key.Menu;
|
|
148
|
+
this.keymap[reset] = Key.Reset;
|
|
149
|
+
// Remember this mapping
|
|
150
|
+
this.saveMap(mapName, [screenshot, gif, menu, reset]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public getKey(keyCode: number): Key {
|
|
154
|
+
return keyCode ? this.keymap[keyCode] || this.altmap[keyCode] || Key.None : Key.None;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private saveMap(name: string, keyCodes: number[]) {
|
|
158
|
+
this.mappings[name] = keyCodes;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private clearMap(name: string) {
|
|
162
|
+
const keyCodes = this.mappings[name];
|
|
163
|
+
keyCodes?.forEach(keyCode => delete this.keymap[keyCode]);
|
|
164
|
+
delete this.mappings[name];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|