pxt-common-packages 9.5.6 → 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.
- package/built/common-sim.d.ts +84 -0
- package/built/common-sim.js +232 -1
- package/libs/azureiot/built/debug/binary.js +461 -461
- package/libs/base/sim/core.ts +1 -1
- 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 +7659 -7665
- package/libs/controller---none/built/debug/binary.js +7638 -7644
- 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 +14 -0
- package/libs/game/_locales/game-strings.json +3 -0
- package/libs/game/built/debug/binary.js +7551 -7557
- package/libs/game/hitbox.ts +2 -2
- package/libs/game/keymap.cpp +12 -0
- package/libs/game/keymap.ts +169 -0
- package/libs/game/multiplayer.cpp +25 -0
- package/libs/game/multiplayer.ts +24 -0
- package/libs/game/pxt.json +5 -1
- package/libs/game/scene.ts +1 -0
- package/libs/game/sim/keymap.ts +167 -0
- package/libs/game/sim/multiplayer.ts +132 -0
- 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 +9339 -9345
- package/libs/palette/built/debug/binary.js +7550 -7556
- 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 +7550 -7556
- package/libs/storyboard/built/debug/binary.js +7550 -7556
- package/package.json +2 -2
package/libs/game/hitbox.ts
CHANGED
|
@@ -17,11 +17,11 @@ namespace game {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
get left() {
|
|
20
|
-
return Fx.add(this.ox,
|
|
20
|
+
return Fx.add(this.ox, this.parent._x);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
get top() {
|
|
24
|
-
return Fx.add(this.oy,
|
|
24
|
+
return Fx.add(this.oy, this.parent._y);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
get right() {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "pxt.h"
|
|
2
|
+
|
|
3
|
+
namespace multiplayer {
|
|
4
|
+
//%
|
|
5
|
+
void postImage(Image_ im, String goal) {
|
|
6
|
+
// no support >:(
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//%
|
|
10
|
+
void setOrigin(String origin) {
|
|
11
|
+
// no
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//%
|
|
15
|
+
Image_ getCurrentImage() {
|
|
16
|
+
// nah
|
|
17
|
+
return NULL;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//%
|
|
21
|
+
String getOrigin() {
|
|
22
|
+
return NULL;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
namespace multiplayer {
|
|
2
|
+
//% shim=multiplayer::getCurrentImage
|
|
3
|
+
declare function getCurrentImage(): Image;
|
|
4
|
+
|
|
5
|
+
//% shim=multiplayer::setOrigin
|
|
6
|
+
declare function setOrigin(origin: string): void;
|
|
7
|
+
|
|
8
|
+
//% shim=multiplayer::getOrigin
|
|
9
|
+
declare function getOrigin(): string;
|
|
10
|
+
|
|
11
|
+
export function init() {
|
|
12
|
+
game.addScenePushHandler(() => {
|
|
13
|
+
game.eventContext().registerFrameHandler(scene.MULTIPLAYER_SCREEN_PRIORITY, () => {
|
|
14
|
+
if (getOrigin() === "client") {
|
|
15
|
+
const im: Image = getCurrentImage();
|
|
16
|
+
scene.setBackgroundImage(im);
|
|
17
|
+
// clear default menu button behavior
|
|
18
|
+
controller.menu.onEvent(ControllerButtonEvent.Pressed, () => { });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
game.pushScene();
|
|
23
|
+
}
|
|
24
|
+
}
|
package/libs/game/pxt.json
CHANGED
package/libs/game/scene.ts
CHANGED
|
@@ -63,6 +63,7 @@ namespace scene {
|
|
|
63
63
|
export const RENDER_BACKGROUND_PRIORITY = 60;
|
|
64
64
|
export const RENDER_SPRITES_PRIORITY = 90;
|
|
65
65
|
export const RENDER_DIAGNOSTICS_PRIORITY = 150;
|
|
66
|
+
export const MULTIPLAYER_SCREEN_PRIORITY = 190;
|
|
66
67
|
export const UPDATE_SCREEN_PRIORITY = 200;
|
|
67
68
|
|
|
68
69
|
// default rendering z indices
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
namespace pxsim.multiplayer {
|
|
2
|
+
export function postImage(im: pxsim.RefImage, goal: string) {
|
|
3
|
+
const asBuf = pxsim.image.toBuffer(im);
|
|
4
|
+
getMultiplayerState().send(<MultiplayerImageMessage>{
|
|
5
|
+
content: "Image",
|
|
6
|
+
image: asBuf,
|
|
7
|
+
goal
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getCurrentImage(): pxsim.RefImage {
|
|
12
|
+
return getMultiplayerState().backgroundImage;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setOrigin(origin: "client" | "server" | undefined) {
|
|
16
|
+
getMultiplayerState().origin = origin;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getOrigin(): string {
|
|
20
|
+
return getMultiplayerState().origin;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
namespace pxsim {
|
|
25
|
+
export interface MultiplayerBoard extends EventBusBoard {
|
|
26
|
+
multiplayerState: MultiplayerState;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getMultiplayerState() {
|
|
30
|
+
return (board() as EventBusBoard as MultiplayerBoard).multiplayerState;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface SimulatorMultiplayerMessage extends SimulatorBroadcastMessage {
|
|
34
|
+
broadcast: true
|
|
35
|
+
type: "multiplayer";
|
|
36
|
+
content: string;
|
|
37
|
+
origin?: "server" | "client";
|
|
38
|
+
clientNumber?: number;
|
|
39
|
+
id?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MultiplayerImageMessage extends SimulatorMultiplayerMessage {
|
|
43
|
+
content: "Image";
|
|
44
|
+
goal: string; // goal of message; e.g. "broadcast-screen"
|
|
45
|
+
image: RefImage;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface MultiplayerButtonEvent extends SimulatorMultiplayerMessage {
|
|
49
|
+
content: "Button";
|
|
50
|
+
button: number; // pxsim.Key.A, ...
|
|
51
|
+
state: "Pressed" | "Released" | "Held";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class MultiplayerState {
|
|
55
|
+
lastMessageId: number;
|
|
56
|
+
origin: string;
|
|
57
|
+
backgroundImage: RefImage;
|
|
58
|
+
|
|
59
|
+
constructor() {
|
|
60
|
+
this.lastMessageId = 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
send(msg: SimulatorMultiplayerMessage) {
|
|
64
|
+
Runtime.postMessage(<SimulatorMultiplayerMessage>{
|
|
65
|
+
...msg,
|
|
66
|
+
broadcast: true,
|
|
67
|
+
toParentIFrameOnly: true,
|
|
68
|
+
type: "multiplayer",
|
|
69
|
+
origin: this.origin,
|
|
70
|
+
id: this.lastMessageId++
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
init(origin: string) {
|
|
75
|
+
this.origin = origin;
|
|
76
|
+
runtime.board.addMessageListener(msg => this.messageHandler(msg));
|
|
77
|
+
setInterval(() => {
|
|
78
|
+
if (this.origin === "server") {
|
|
79
|
+
const b = board() as ScreenBoard;
|
|
80
|
+
const screenState = b && b.screenState;
|
|
81
|
+
const lastImage = screenState && screenState.lastImage;
|
|
82
|
+
lastImage && pxsim.multiplayer.postImage(lastImage, "broadcast-screen");
|
|
83
|
+
}
|
|
84
|
+
}, 50);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setButton(key: number, isPressed: boolean) {
|
|
88
|
+
if (this.origin === "client") {
|
|
89
|
+
this.send(<pxsim.MultiplayerButtonEvent>{
|
|
90
|
+
content: "Button",
|
|
91
|
+
button: key,
|
|
92
|
+
state: isPressed ? "Pressed" : "Released"
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected messageHandler(msg: SimulatorMessage) {
|
|
98
|
+
if (!isMultiplayerMessage(msg)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isImageMessage(msg)) {
|
|
103
|
+
if (this.origin === "client") {
|
|
104
|
+
// HACK: peer js can convert Uint8Array into ArrayBuffer when transmitting; fix this.
|
|
105
|
+
if (!ArrayBuffer.isView(msg.image.data)) {
|
|
106
|
+
msg.image.data = new Uint8Array(msg.image.data);
|
|
107
|
+
}
|
|
108
|
+
this.backgroundImage = pxsim.image.ofBuffer(msg.image);
|
|
109
|
+
}
|
|
110
|
+
} else if (isButtonMessage(msg)) {
|
|
111
|
+
if (this.origin === "server") {
|
|
112
|
+
(board() as any).setButton(
|
|
113
|
+
msg.button + (7 * (msg.clientNumber || 1)), // + 7 to make it player 2 controls,
|
|
114
|
+
msg.state === "Pressed" || msg.state === "Held"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isMultiplayerMessage(msg: SimulatorMessage): msg is SimulatorMultiplayerMessage {
|
|
122
|
+
return msg && msg.type === "multiplayer";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isImageMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerImageMessage {
|
|
126
|
+
return msg && msg.content === "Image";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isButtonMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerButtonEvent {
|
|
130
|
+
return msg && msg.content === "Button";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
|
|
|
56
56
|
const pxsim_numops = pxsim.numops;
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
function
|
|
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.
|
|
70
|
-
globals.
|
|
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
|
-
|
|
76
|
-
|
|
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
|
|
78
|
+
function _main___P48182_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
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___P48928_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
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
|
|
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.
|
|
70
|
-
globals.
|
|
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
|
-
|
|
76
|
-
|
|
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
|
|
78
|
+
function _main___P96878_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
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___P97400_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
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
|
|
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.
|
|
70
|
-
globals.
|
|
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
|
-
|
|
76
|
-
|
|
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
|
|
78
|
+
function _main___P59484_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
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___P60230_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
91
|
+
return _main___P59484
|
|
92
92
|
})
|