pxt-common-packages 10.3.10 → 10.3.12

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 (34) hide show
  1. package/built/common-sim.d.ts +6 -0
  2. package/built/common-sim.js +15 -2
  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 +8627 -8381
  7. package/libs/controller---none/built/debug/binary.js +8606 -8360
  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/built/debug/binary.js +9031 -8785
  12. package/libs/game/controller.ts +5 -0
  13. package/libs/game/multiplayer.ts +39 -0
  14. package/libs/game/sim/multiplayer.ts +23 -2
  15. package/libs/lcd/built/debug/binary.js +8 -8
  16. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  17. package/libs/lora/built/debug/binary.js +8 -8
  18. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  19. package/libs/mqtt/built/debug/binary.js +176 -176
  20. package/libs/multiplayer/player.ts +15 -0
  21. package/libs/net/built/debug/binary.js +176 -176
  22. package/libs/net-game/built/debug/binary.js +10613 -10367
  23. package/libs/palette/built/debug/binary.js +9030 -8784
  24. package/libs/pixel/built/debug/binary.js +8 -8
  25. package/libs/power/built/debug/binary.js +8 -8
  26. package/libs/proximity/built/debug/binary.js +8 -8
  27. package/libs/radio/built/debug/binary.js +8 -8
  28. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  29. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  30. package/libs/screen/built/debug/binary.js +50 -50
  31. package/libs/servo/built/debug/binary.js +8 -8
  32. package/libs/sprite-scaling/built/debug/binary.js +9030 -8784
  33. package/libs/storyboard/built/debug/binary.js +9030 -8784
  34. package/package.json +1 -1
@@ -169,6 +169,11 @@ namespace controller {
169
169
  this._moveSpriteInternal(sprite, vx, vy);
170
170
  }
171
171
 
172
+ stopControllingSprite(sprite: Sprite) {
173
+ if (!sprite) return;
174
+ this._controlledSprites = this._controlledSprites.filter(s => s.s.id !== sprite.id);
175
+ }
176
+
172
177
  // use this instead of movesprite internally to avoid adding the "multiplayer" part
173
178
  // to the compiled program
174
179
  _moveSpriteInternal(sprite: Sprite, vx: number = 100, vy: number = 100) {
@@ -25,6 +25,8 @@ namespace multiplayer {
25
25
  game.pushScene();
26
26
  }
27
27
 
28
+ const MULTIPLAYER_PLAYER_JOINED_ID = 3241;
29
+ const MULTIPLAYER_PLAYER_LEFT_ID = 3242;
28
30
  export function initServer() {
29
31
  if (getOrigin() === "server") {
30
32
  game.eventContext().registerFrameHandler(scene.MULTIPLAYER_POST_SCREEN_PRIORITY, () => {
@@ -32,7 +34,44 @@ namespace multiplayer {
32
34
  postImage(screen);
33
35
  }
34
36
  })
37
+
38
+ for (let p = 1; p <= 4; p++) {
39
+ registerPlayerConnectionListeners(p);
40
+ }
41
+ }
42
+ }
43
+
44
+ function registerPlayerConnectionListeners(playerNumber: number) {
45
+ control.onEvent(
46
+ MULTIPLAYER_PLAYER_JOINED_ID,
47
+ playerNumber,
48
+ () => receiveConnectionChangedEvent(playerNumber, true)
49
+ );
50
+ control.onEvent(
51
+ MULTIPLAYER_PLAYER_LEFT_ID,
52
+ playerNumber,
53
+ () => receiveConnectionChangedEvent(playerNumber, false)
54
+ );
55
+ }
56
+
57
+ function receiveConnectionChangedEvent(playerNumber: number, connected: boolean) {
58
+ let c: controller.Controller;
59
+ switch (playerNumber) {
60
+ case 1:
61
+ c = controller.player1;
62
+ break;
63
+ case 2:
64
+ c = controller.player2;
65
+ break;
66
+ case 3:
67
+ c = controller.player3;
68
+ break;
69
+ case 4:
70
+ c = controller.player4;
71
+ break;
35
72
  }
73
+ if (c)
74
+ c.connected = connected;
36
75
  }
37
76
  }
38
77
 
@@ -17,8 +17,6 @@ namespace pxsim.multiplayer {
17
17
  }
18
18
 
19
19
  export function postIcon(iconType: IconType, slot: number, im: pxsim.RefImage) {
20
- if (getMultiplayerState().origin !== "server")
21
- return;
22
20
  if (im._width * im._height > 64 * 64) {
23
21
  // setting 64x64 as max size for icon for now
24
22
  return;
@@ -100,6 +98,15 @@ namespace pxsim {
100
98
  soundbuf?: Uint8Array;
101
99
  }
102
100
 
101
+ export interface MultiplayerConnectionEvent extends SimulatorMultiplayerMessage {
102
+ content: "Connection";
103
+ slot: number;
104
+ connected: boolean;
105
+ }
106
+
107
+ const MULTIPLAYER_PLAYER_JOINED_ID = 3241;
108
+ const MULTIPLAYER_PLAYER_LEFT_ID = 3242;
109
+
103
110
  export class MultiplayerState {
104
111
  lastMessageId: number;
105
112
  origin: string;
@@ -146,6 +153,12 @@ namespace pxsim {
146
153
  }
147
154
  }
148
155
 
156
+ registerConnectionState(player: number, connected: boolean) {
157
+ const evId = connected ? MULTIPLAYER_PLAYER_JOINED_ID : MULTIPLAYER_PLAYER_LEFT_ID;
158
+ const b = board();
159
+ b.bus.queue(evId, player);
160
+ }
161
+
149
162
  protected messageHandler(msg: SimulatorMessage) {
150
163
  if (!isMultiplayerMessage(msg)) {
151
164
  return;
@@ -178,6 +191,10 @@ namespace pxsim {
178
191
  pxsim.AudioContextManager.muteAllChannels();
179
192
  }
180
193
  }
194
+ } else if (isConnectionMessage(msg)) {
195
+ if (this.origin === "server") {
196
+ this.registerConnectionState(msg.slot, msg.connected);
197
+ }
181
198
  }
182
199
  }
183
200
  }
@@ -197,4 +214,8 @@ namespace pxsim {
197
214
  function isAudioMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerAudioEvent {
198
215
  return msg && msg.content === "Audio";
199
216
  }
217
+
218
+ function isConnectionMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerConnectionEvent {
219
+ return msg && msg.content === "Connection";
220
+ }
200
221
  }
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48702(s) {
59
+ function _main___P48755(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___48945 = (undefined);
70
- globals._pollEventQueue___48958 = (undefined);
69
+ globals._intervals___48998 = (undefined);
70
+ globals._pollEventQueue___49011 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48702.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48702.continuations = [ ]
75
+ _main___P48755.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48755.continuations = [ ]
77
77
 
78
- function _main___P48702_mk(s) {
78
+ function _main___P48755_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48702, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48755, 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___P48702_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48702
91
+ return _main___P48755
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___P98438(s) {
59
+ function _main___P98597(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___98681 = (undefined);
70
- globals._pollEventQueue___98694 = (undefined);
69
+ globals._intervals___98840 = (undefined);
70
+ globals._pollEventQueue___98853 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P98438.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P98438.continuations = [ ]
75
+ _main___P98597.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P98597.continuations = [ ]
77
77
 
78
- function _main___P98438_mk(s) {
78
+ function _main___P98597_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P98438, depth: s.depth + 1,
81
+ parent: s, fn: _main___P98597, 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___P98438_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P98438
91
+ return _main___P98597
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___P60004(s) {
59
+ function _main___P60057(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___60247 = (undefined);
70
- globals._pollEventQueue___60260 = (undefined);
69
+ globals._intervals___60300 = (undefined);
70
+ globals._pollEventQueue___60313 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P60004.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P60004.continuations = [ ]
75
+ _main___P60057.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P60057.continuations = [ ]
77
77
 
78
- function _main___P60004_mk(s) {
78
+ function _main___P60057_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P60004, depth: s.depth + 1,
81
+ parent: s, fn: _main___P60057, 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___P60004_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P60004
91
+ return _main___P60057
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___P191434(s) {
59
+ function _main___P191805(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___191677 = (undefined);
70
- globals._pollEventQueue___191690 = (undefined);
69
+ globals._intervals___192048 = (undefined);
70
+ globals._pollEventQueue___192061 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P191434.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P191434.continuations = [ ]
75
+ _main___P191805.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P191805.continuations = [ ]
77
77
 
78
- function _main___P191434_mk(s) {
78
+ function _main___P191805_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P191434, depth: s.depth + 1,
81
+ parent: s, fn: _main___P191805, 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___P191434_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P191434
91
+ return _main___P191805
92
92
  })