pxt-common-packages 9.5.6 → 9.5.7
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 +40 -0
- package/built/common-sim.js +93 -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 +6864 -6864
- package/libs/controller---none/built/debug/binary.js +6844 -6844
- 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-strings.json +1 -0
- package/libs/game/built/debug/binary.js +6784 -6784
- package/libs/game/multiplayer.cpp +25 -0
- package/libs/game/multiplayer.ts +24 -0
- package/libs/game/pxt.json +3 -1
- package/libs/game/scene.ts +1 -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 +8372 -8372
- package/libs/palette/built/debug/binary.js +6782 -6782
- 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 +6782 -6782
- package/libs/storyboard/built/debug/binary.js +6782 -6782
- package/package.json +2 -2
|
@@ -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,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___P48098(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___48341 = (undefined);
|
|
70
|
+
globals._pollEventQueue___48354 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P48098.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P48098.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P48098_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P48098, 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___P48098
|
|
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___P96584(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___96827 = (undefined);
|
|
70
|
+
globals._pollEventQueue___96840 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P96584.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P96584.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P96584_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P96584, 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___P96584
|
|
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___P59400(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___59643 = (undefined);
|
|
70
|
+
globals._pollEventQueue___59656 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P59400.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P59400.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P59400_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P59400, 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___P59400
|
|
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___P187101(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___187344 = (undefined);
|
|
70
|
+
globals._pollEventQueue___187357 = (undefined);
|
|
71
71
|
r0 = undefined;
|
|
72
72
|
return leave(s, r0)
|
|
73
73
|
default: oops()
|
|
74
74
|
} } }
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
_main___P187101.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
|
|
76
|
+
_main___P187101.continuations = [ ]
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function _main___P187101_mk(s) {
|
|
79
79
|
checkStack(s.depth);
|
|
80
80
|
return {
|
|
81
|
-
parent: s, fn:
|
|
81
|
+
parent: s, fn: _main___P187101, 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___P188726_mk(s) {
|
|
|
88
88
|
|
|
89
89
|
const breakpoints = setupDebugger(1, [])
|
|
90
90
|
|
|
91
|
-
return
|
|
91
|
+
return _main___P187101
|
|
92
92
|
})
|