pxt-common-packages 10.3.11 → 10.3.13

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 (37) hide show
  1. package/built/common-sim.d.ts +6 -0
  2. package/built/common-sim.js +15 -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 +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/_locales/game-jsdoc-strings.json +2 -2
  12. package/libs/game/_locales/game-strings.json +1 -1
  13. package/libs/game/built/debug/binary.js +8937 -8691
  14. package/libs/game/game.ts +9 -2
  15. package/libs/game/multiplayer.ts +39 -0
  16. package/libs/game/sim/multiplayer.ts +23 -0
  17. package/libs/lcd/built/debug/binary.js +8 -8
  18. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  19. package/libs/lora/built/debug/binary.js +8 -8
  20. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  21. package/libs/mixer/instrument.ts +7 -0
  22. package/libs/mixer/melody.ts +1 -0
  23. package/libs/mqtt/built/debug/binary.js +176 -176
  24. package/libs/net/built/debug/binary.js +176 -176
  25. package/libs/net-game/built/debug/binary.js +10613 -10367
  26. package/libs/palette/built/debug/binary.js +9030 -8784
  27. package/libs/pixel/built/debug/binary.js +8 -8
  28. package/libs/power/built/debug/binary.js +8 -8
  29. package/libs/proximity/built/debug/binary.js +8 -8
  30. package/libs/radio/built/debug/binary.js +8 -8
  31. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  32. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  33. package/libs/screen/built/debug/binary.js +50 -50
  34. package/libs/servo/built/debug/binary.js +8 -8
  35. package/libs/sprite-scaling/built/debug/binary.js +9030 -8784
  36. package/libs/storyboard/built/debug/binary.js +9030 -8784
  37. package/package.json +1 -1
package/libs/game/game.ts CHANGED
@@ -248,7 +248,7 @@ namespace game {
248
248
  * @param win whether the sound should play on a win (true) or lose (false)
249
249
  * @param effect
250
250
  */
251
- //% blockId=game_setgameoversound
251
+ //% blockId=game_setgameoverplayable
252
252
  //% block="use $sound looping $looping for $win"
253
253
  //% sound.shadow=music_melody_playable
254
254
  //% sound.defl=music.powerUp
@@ -260,12 +260,19 @@ namespace game {
260
260
  //% weight=80
261
261
  //% blockGap=8
262
262
  //% help=game/set-game-over-sound
263
- export function setGameOverSound(win: boolean, sound: music.Playable, looping: boolean) {
263
+ export function setGameOverPlayable(win: boolean, sound: music.Playable, looping: boolean) {
264
264
  init();
265
265
  const goc = game.gameOverConfig();
266
266
  goc.setSound(win, sound, looping, true);
267
267
  }
268
268
 
269
+ // Legacy api. Older extensions may still use this.
270
+ export function setGameOverSound(win: boolean, sound: music.Melody) {
271
+ init();
272
+ const goc = game.gameOverConfig();
273
+ goc.setSound(win, music.melodyPlayable(sound), false, true);
274
+ }
275
+
269
276
  /**
270
277
  * Set the message that displays when the game is over
271
278
  * @param win whether the message should show on a win (true) or lose (false)
@@ -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
 
@@ -98,6 +98,15 @@ namespace pxsim {
98
98
  soundbuf?: Uint8Array;
99
99
  }
100
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
+
101
110
  export class MultiplayerState {
102
111
  lastMessageId: number;
103
112
  origin: string;
@@ -144,6 +153,12 @@ namespace pxsim {
144
153
  }
145
154
  }
146
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
+
147
162
  protected messageHandler(msg: SimulatorMessage) {
148
163
  if (!isMultiplayerMessage(msg)) {
149
164
  return;
@@ -176,6 +191,10 @@ namespace pxsim {
176
191
  pxsim.AudioContextManager.muteAllChannels();
177
192
  }
178
193
  }
194
+ } else if (isConnectionMessage(msg)) {
195
+ if (this.origin === "server") {
196
+ this.registerConnectionState(msg.slot, msg.connected);
197
+ }
179
198
  }
180
199
  }
181
200
  }
@@ -195,4 +214,8 @@ namespace pxsim {
195
214
  function isAudioMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerAudioEvent {
196
215
  return msg && msg.content === "Audio";
197
216
  }
217
+
218
+ function isConnectionMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerConnectionEvent {
219
+ return msg && msg.content === "Connection";
220
+ }
198
221
  }
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48703(s) {
59
+ function _main___P48757(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___48946 = (undefined);
70
- globals._pollEventQueue___48959 = (undefined);
69
+ globals._intervals___49000 = (undefined);
70
+ globals._pollEventQueue___49013 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48703.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48703.continuations = [ ]
75
+ _main___P48757.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48757.continuations = [ ]
77
77
 
78
- function _main___P48703_mk(s) {
78
+ function _main___P48757_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48703, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48757, 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___P48703_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48703
91
+ return _main___P48757
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___P98441(s) {
59
+ function _main___P98603(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___98684 = (undefined);
70
- globals._pollEventQueue___98697 = (undefined);
69
+ globals._intervals___98846 = (undefined);
70
+ globals._pollEventQueue___98859 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P98441.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P98441.continuations = [ ]
75
+ _main___P98603.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P98603.continuations = [ ]
77
77
 
78
- function _main___P98441_mk(s) {
78
+ function _main___P98603_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P98441, depth: s.depth + 1,
81
+ parent: s, fn: _main___P98603, 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___P98441_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P98441
91
+ return _main___P98603
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___P60005(s) {
59
+ function _main___P60059(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___60248 = (undefined);
70
- globals._pollEventQueue___60261 = (undefined);
69
+ globals._intervals___60302 = (undefined);
70
+ globals._pollEventQueue___60315 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P60005.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P60005.continuations = [ ]
75
+ _main___P60059.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P60059.continuations = [ ]
77
77
 
78
- function _main___P60005_mk(s) {
78
+ function _main___P60059_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P60005, depth: s.depth + 1,
81
+ parent: s, fn: _main___P60059, 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___P60005_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P60005
91
+ return _main___P60059
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___P191441(s) {
59
+ function _main___P191819(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___191684 = (undefined);
70
- globals._pollEventQueue___191697 = (undefined);
69
+ globals._intervals___192062 = (undefined);
70
+ globals._pollEventQueue___192075 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P191441.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P191441.continuations = [ ]
75
+ _main___P191819.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P191819.continuations = [ ]
77
77
 
78
- function _main___P191441_mk(s) {
78
+ function _main___P191819_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P191441, depth: s.depth + 1,
81
+ parent: s, fn: _main___P191819, 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___P191441_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P191441
91
+ return _main___P191819
92
92
  })
@@ -811,4 +811,11 @@ namespace music.sequencer {
811
811
  // Use cosine to smooth out the value somewhat
812
812
  return Math.cos(((time / 1000) * lfo.frequency) * 2 * Math.PI) * lfo.amplitude
813
813
  }
814
+
815
+ export function _stopAllSongs() {
816
+ if (currentSequencer) {
817
+ currentSequencer.stop();
818
+ currentSequencer = undefined;
819
+ }
820
+ }
814
821
  }
@@ -184,6 +184,7 @@ namespace music {
184
184
  Melody.stopAll();
185
185
  stopPlaying();
186
186
  _stopPlayables();
187
+ sequencer._stopAllSongs();
187
188
  }
188
189
 
189
190
  //% fixedInstances