pxt-common-packages 9.5.8 → 9.5.9

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 (36) hide show
  1. package/built/common-sim.d.ts +44 -0
  2. package/built/common-sim.js +139 -0
  3. package/libs/azureiot/built/debug/binary.js +461 -461
  4. package/libs/color/built/debug/binary.js +8 -8
  5. package/libs/color-sensor/built/debug/binary.js +8 -8
  6. package/libs/controller/built/debug/binary.js +6864 -6864
  7. package/libs/controller---none/built/debug/binary.js +6844 -6844
  8. package/libs/datalogger/built/debug/binary.js +63 -63
  9. package/libs/edge-connector/built/debug/binary.js +8 -8
  10. package/libs/esp32/built/debug/binary.js +462 -462
  11. package/libs/game/_locales/game-jsdoc-strings.json +14 -0
  12. package/libs/game/_locales/game-strings.json +2 -0
  13. package/libs/game/built/debug/binary.js +6784 -6784
  14. package/libs/game/keymap.cpp +12 -0
  15. package/libs/game/keymap.ts +169 -0
  16. package/libs/game/pxt.json +3 -1
  17. package/libs/game/sim/keymap.ts +167 -0
  18. package/libs/lcd/built/debug/binary.js +8 -8
  19. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  20. package/libs/lora/built/debug/binary.js +8 -8
  21. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  22. package/libs/mqtt/built/debug/binary.js +176 -176
  23. package/libs/net/built/debug/binary.js +176 -176
  24. package/libs/net-game/built/debug/binary.js +8372 -8372
  25. package/libs/palette/built/debug/binary.js +6782 -6782
  26. package/libs/pixel/built/debug/binary.js +8 -8
  27. package/libs/power/built/debug/binary.js +8 -8
  28. package/libs/proximity/built/debug/binary.js +8 -8
  29. package/libs/radio/built/debug/binary.js +8 -8
  30. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  31. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  32. package/libs/screen/built/debug/binary.js +50 -50
  33. package/libs/servo/built/debug/binary.js +8 -8
  34. package/libs/sprite-scaling/built/debug/binary.js +6782 -6782
  35. package/libs/storyboard/built/debug/binary.js +6782 -6782
  36. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ #include "pxt.h"
2
+
3
+ namespace keymap {
4
+
5
+ void _setPlayerKeys(int player, int up, int down, int left, int right, int A, int B) {
6
+ // not supported
7
+ }
8
+
9
+ void _setSystemKeys(int screenshot, int gif) {
10
+ // not supported
11
+ }
12
+ }
@@ -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
+ }
@@ -50,7 +50,9 @@
50
50
  "assetTemplates.ts",
51
51
  "animation.ts",
52
52
  "multiplayer.cpp",
53
- "multiplayer.ts"
53
+ "multiplayer.ts",
54
+ "keymap.cpp",
55
+ "keymap.ts"
54
56
  ],
55
57
  "public": true,
56
58
  "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, // D - Down
71
+ 65, // A - Left
72
+ 83, // S - 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
+ 75, // K - 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
+ }
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48096(s) {
59
+ function _main___P48182(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___48339 = (undefined);
70
- globals._pollEventQueue___48352 = (undefined);
69
+ globals._intervals___48425 = (undefined);
70
+ globals._pollEventQueue___48438 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48096.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48096.continuations = [ ]
75
+ _main___P48182.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48182.continuations = [ ]
77
77
 
78
- function _main___P48096_mk(s) {
78
+ function _main___P48182_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48096, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48182, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P48096_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48096
91
+ return _main___P48182
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P96578(s) {
59
+ function _main___P96878(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___96821 = (undefined);
70
- globals._pollEventQueue___96834 = (undefined);
69
+ globals._intervals___97121 = (undefined);
70
+ globals._pollEventQueue___97134 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P96578.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P96578.continuations = [ ]
75
+ _main___P96878.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P96878.continuations = [ ]
77
77
 
78
- function _main___P96578_mk(s) {
78
+ function _main___P96878_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P96578, depth: s.depth + 1,
81
+ parent: s, fn: _main___P96878, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P96578_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P96578
91
+ return _main___P96878
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P59398(s) {
59
+ function _main___P59484(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___59641 = (undefined);
70
- globals._pollEventQueue___59654 = (undefined);
69
+ globals._intervals___59727 = (undefined);
70
+ globals._pollEventQueue___59740 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P59398.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P59398.continuations = [ ]
75
+ _main___P59484.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P59484.continuations = [ ]
77
77
 
78
- function _main___P59398_mk(s) {
78
+ function _main___P59484_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P59398, depth: s.depth + 1,
81
+ parent: s, fn: _main___P59484, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P59398_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P59398
91
+ return _main___P59484
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P187087(s) {
59
+ function _main___P187794(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___187330 = (undefined);
70
- globals._pollEventQueue___187343 = (undefined);
69
+ globals._intervals___188037 = (undefined);
70
+ globals._pollEventQueue___188050 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P187087.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P187087.continuations = [ ]
75
+ _main___P187794.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P187794.continuations = [ ]
77
77
 
78
- function _main___P187087_mk(s) {
78
+ function _main___P187794_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P187087, depth: s.depth + 1,
81
+ parent: s, fn: _main___P187794, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P187087_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P187087
91
+ return _main___P187794
92
92
  })