pxt-microbit 6.1.2 → 6.1.4

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 (53) hide show
  1. package/built/hexcache/{a205d05d10c4848e8a9454ddb6b085235213690f446c18ac8eb610d69c8c0d98.hex → 02e118276d7ad61fd1e7913a87f10d8ffee34a65b883e7b8efce291712f45092.hex} +10499 -10480
  2. package/built/hexcache/{1a29827806d7ca2a8e55b95c99194503f7fdfaa45a3ebfcc25cda8e5c1e51824.hex → 56661ceac4d8678e416df6f0cb117457b277232c45f0a578a9298d26f8eaba35.hex} +9914 -9895
  3. package/built/hexcache/62b44871df9fdf64381631c44888c831f0e73d4a7a6221dc1b91aea7bd9aa76a.hex +14523 -0
  4. package/built/hexcache/f4b5733caac6970862b68d159aad886755259b131a794060ce8075730c534b64.hex +13996 -0
  5. package/built/sim-strings.json +1 -1
  6. package/built/sim.d.ts +10 -0
  7. package/built/sim.js +133 -23
  8. package/built/target.js +1 -1
  9. package/built/target.json +1 -1
  10. package/built/targetlight.json +1 -1
  11. package/built/web/react-common-authcode.css +1 -1
  12. package/built/web/react-common-multiplayer.css +1 -1
  13. package/built/web/react-common-skillmap.css +1 -1
  14. package/built/web/rtlreact-common-authcode.css +1 -1
  15. package/built/web/rtlreact-common-multiplayer.css +1 -1
  16. package/built/web/rtlreact-common-skillmap.css +1 -1
  17. package/built/web/rtlsemantic.css +3 -3
  18. package/built/web/semantic.css +3 -3
  19. package/docs/extensions.md +16 -0
  20. package/docs/projects/7-seconds.md +8 -8
  21. package/docs/projects/carnival/button-points.md +118 -0
  22. package/docs/projects/carnival/circuit-win.md +107 -0
  23. package/docs/projects/carnival/shake-lose.md +97 -0
  24. package/docs/projects/coin-flipper.md +8 -8
  25. package/docs/projects/compass.md +12 -17
  26. package/docs/projects/dice.md +15 -8
  27. package/docs/projects/flashing-heart.md +4 -4
  28. package/docs/projects/heads-guess.md +10 -10
  29. package/docs/projects/hot-potato.md +8 -8
  30. package/docs/projects/love-meter.md +12 -6
  31. package/docs/projects/magic-button-trick.md +2 -4
  32. package/docs/projects/multi-dice.md +7 -7
  33. package/docs/projects/name-tag.md +5 -5
  34. package/docs/projects/rock-paper-scissors-v2.md +13 -13
  35. package/docs/projects/rock-paper-scissors.md +12 -12
  36. package/docs/projects/smiley-buttons.md +7 -7
  37. package/docs/projects/v2-blow-away.md +17 -13
  38. package/docs/projects/v2-cat-napping.md +18 -14
  39. package/docs/projects/v2-clap-lights.md +19 -10
  40. package/docs/projects/v2-countdown.md +16 -8
  41. package/docs/projects/v2-morse-chat.md +13 -13
  42. package/docs/projects/v2-pet-hamster.md +26 -13
  43. package/docs/reference/input/compass-heading.md +9 -5
  44. package/docs/reference/input/magnetic-force.md +16 -8
  45. package/docs/static/orglogowide.png +0 -0
  46. package/docs/translate.md +4 -4
  47. package/package.json +3 -3
  48. package/pxtarget.json +12 -18
  49. package/sim/public/simulator.html +45 -0
  50. package/targetconfig.json +6 -2
  51. package/built/hexcache/215f0a9c22dcecda497365fd42b85e341eda40aa40d2d69d427265c77cc5f004.hex +0 -14333
  52. package/built/hexcache/704323c8559a596aec81e104e6d4bb8ae10bafd9dec77489fbb082158b23a4e4.hex +0 -14853
  53. package/sim/public/parts/.gitignore +0 -5
@@ -1 +1 @@
1
- {"Sound Level":"Sound Level","Thermometer":"Thermometer","acceleration.pitch":"acceleration.pitch","acceleration.roll":"acceleration.roll","acceleration.strength":"acceleration.strength","acceleration.x":"acceleration.x","acceleration.y":"acceleration.y","acceleration.z":"acceleration.z","heading":"heading","lightLevel":"lightLevel","logo touch (micro:bit v2 needed)":"logo touch (micro:bit v2 needed)","micro:bit v2 needed":"micro:bit v2 needed","microphone (micro:bit v2 needed)":"microphone (micro:bit v2 needed)","sound level":"sound level","temperature":"temperature"}
1
+ {"Sound Level":"Sound Level","Thermometer":"Thermometer","Unmute simulator":"Unmute simulator","acceleration.pitch":"acceleration.pitch","acceleration.roll":"acceleration.roll","acceleration.strength":"acceleration.strength","acceleration.x":"acceleration.x","acceleration.y":"acceleration.y","acceleration.z":"acceleration.z","heading":"heading","lightLevel":"lightLevel","logo touch (micro:bit v2 needed)":"logo touch (micro:bit v2 needed)","micro:bit v2 needed":"micro:bit v2 needed","microphone (micro:bit v2 needed)":"microphone (micro:bit v2 needed)","sound level":"sound level","temperature":"temperature"}
package/built/sim.d.ts CHANGED
@@ -573,6 +573,7 @@ declare namespace pxsim {
573
573
  recording: HTMLAudioElement;
574
574
  audioPlaying: boolean;
575
575
  recordTimeoutID: any;
576
+ currentlyErasing: boolean;
576
577
  handleAudioPlaying: () => void;
577
578
  handleAudioStopped: () => void;
578
579
  initListeners: () => void;
@@ -784,6 +785,15 @@ declare namespace pxsim.visuals {
784
785
  private attachAPlusBEvents;
785
786
  }
786
787
  }
788
+ declare namespace pxsim {
789
+ function createMuteButton(): HTMLDivElement;
790
+ function shouldShowMute(): boolean;
791
+ function hasNavigator(): boolean;
792
+ function isEdge(): boolean;
793
+ function isIE(): boolean;
794
+ function isChrome(): boolean;
795
+ function isSafari(): boolean;
796
+ }
787
797
  declare namespace pxsim.pxtcore {
788
798
  function registerWithDal(id: number, evid: number, handler: RefAction, mode?: number): void;
789
799
  function deepSleep(): void;
package/built/sim.js CHANGED
@@ -133,6 +133,11 @@ var pxsim;
133
133
  }), opts);
134
134
  document.body.innerHTML = ""; // clear children
135
135
  document.body.appendChild(this.view = this.viewHost.getView());
136
+ if (pxsim.shouldShowMute()) {
137
+ document.body.appendChild(pxsim.createMuteButton());
138
+ pxsim.AudioContextManager.mute(true);
139
+ pxsim.setParentMuteState("disabled");
140
+ }
136
141
  if (msg.theme === "mbcodal") {
137
142
  this.ensureHardwareVersion(2);
138
143
  }
@@ -2309,6 +2314,13 @@ var pxsim;
2309
2314
  (function (pxsim) {
2310
2315
  var record;
2311
2316
  (function (record_1) {
2317
+ let _initialized = false;
2318
+ function init() {
2319
+ if (!_initialized) {
2320
+ registerSimStop();
2321
+ _initialized = true;
2322
+ }
2323
+ }
2312
2324
  function stopRecorder(b) {
2313
2325
  b.recordingState.recorder.stop();
2314
2326
  b.recordingState.currentlyRecording = false;
@@ -2320,17 +2332,25 @@ var pxsim;
2320
2332
  });
2321
2333
  }
2322
2334
  }
2323
- function populateRecording(b) {
2324
- const blob = new Blob(b.recordingState.chunks, { type: "audio/ogg; codecs=opus" });
2325
- b.recordingState.audioURL = window.URL.createObjectURL(blob);
2326
- b.recordingState.recording = new Audio(b.recordingState.audioURL);
2327
- b.recordingState.initListeners();
2335
+ async function populateRecording(b) {
2336
+ if (b.recordingState.currentlyErasing) {
2337
+ await erasingAsync(b);
2338
+ }
2339
+ if (b.recordingState.chunks[0].size > 0) {
2340
+ b.recordingState.audioURL = null;
2341
+ const recordingType = pxsim.isSafari() ? "audio/mp4" : "audio/ogg; codecs=opus";
2342
+ const blob = new Blob(b.recordingState.chunks, { type: recordingType });
2343
+ b.recordingState.audioURL = window.URL.createObjectURL(blob);
2344
+ b.recordingState.recording = new Audio(b.recordingState.audioURL);
2345
+ b.recordingState.initListeners();
2346
+ }
2328
2347
  b.recordingState.currentlyRecording = false;
2329
2348
  b.recordingState.recorder = null;
2330
2349
  b.recordingState.chunks = [];
2331
2350
  }
2332
2351
  async function record() {
2333
2352
  let b = pxsim.board();
2353
+ init();
2334
2354
  if (b.recordingState.recorder) {
2335
2355
  b.recordingState.recorder.stop();
2336
2356
  clearTimeout(b.recordingState.recordTimeoutID);
@@ -2348,9 +2368,8 @@ var pxsim;
2348
2368
  b.recordingState.recorder.ondataavailable = (e) => {
2349
2369
  b.recordingState.chunks.push(e.data);
2350
2370
  };
2351
- b.recordingState.recorder.onstop = () => {
2352
- populateRecording(b);
2353
- registerSimStop(b);
2371
+ b.recordingState.recorder.onstop = async () => {
2372
+ await populateRecording(b);
2354
2373
  };
2355
2374
  }
2356
2375
  catch (error) {
@@ -2373,17 +2392,19 @@ var pxsim;
2373
2392
  return;
2374
2393
  if (b.recordingState.currentlyRecording && b.recordingState.recordTimeoutID) {
2375
2394
  clearTimeout(b.recordingState.recordTimeoutID);
2376
- stopRecorder(b);
2395
+ if (b.recordingState.recorder) {
2396
+ stopRecorder(b);
2397
+ }
2377
2398
  }
2378
2399
  else if (b.recordingState.recording && b.recordingState.audioPlaying) {
2379
2400
  b.recordingState.handleAudioStopped();
2380
- b.recordingState.recording.pause();
2381
- b.recordingState.recording.currentTime = 0;
2401
+ stopPlayback();
2382
2402
  }
2383
2403
  }
2384
- function registerSimStop(b) {
2404
+ function registerSimStop() {
2385
2405
  pxsim.AudioContextManager.onStopAll(() => {
2386
- if (b.recordingState.recording) {
2406
+ const b = pxsim.board();
2407
+ if (b && b.recordingState && b.recordingState.recording) {
2387
2408
  stopAudio();
2388
2409
  b.recordingState.recording.removeEventListener("play", b.recordingState.handleAudioPlaying);
2389
2410
  b.recordingState.recording.removeEventListener("ended", b.recordingState.handleAudioStopped);
@@ -2394,11 +2415,24 @@ var pxsim;
2394
2415
  const b = pxsim.board();
2395
2416
  if (!b)
2396
2417
  return;
2418
+ init();
2397
2419
  stopAudio();
2398
2420
  b.recordingState.audioPlaying = true;
2399
- setTimeout(() => {
2400
- if (b.recordingState.recording) {
2401
- b.recordingState.recording.play();
2421
+ setTimeout(async () => {
2422
+ if (!b.recordingState.currentlyErasing && b.recordingState.recording) {
2423
+ try {
2424
+ const volume = pxsim.AudioContextManager.isMuted() ? 0 : 1;
2425
+ b.recordingState.recording.volume = volume;
2426
+ await b.recordingState.recording.play();
2427
+ }
2428
+ catch (e) {
2429
+ if (!(e instanceof DOMException)) {
2430
+ throw e;
2431
+ }
2432
+ }
2433
+ }
2434
+ else {
2435
+ b.recordingState.audioPlaying = false;
2402
2436
  }
2403
2437
  }, 10);
2404
2438
  }
@@ -2407,18 +2441,35 @@ var pxsim;
2407
2441
  stopAudio();
2408
2442
  }
2409
2443
  record_1.stop = stop;
2444
+ function stopPlayback() {
2445
+ const b = pxsim.board();
2446
+ if (!b)
2447
+ return;
2448
+ b.recordingState.recording.pause();
2449
+ b.recordingState.recording.currentTime = 0;
2450
+ b.recordingState.recording.removeEventListener("play", b.recordingState.handleAudioPlaying);
2451
+ b.recordingState.recording.removeEventListener("ended", b.recordingState.handleAudioStopped);
2452
+ }
2453
+ function erasingAsync(b) {
2454
+ return new Promise((resolve, reject) => {
2455
+ if (b.recordingState.recording && b.recordingState.audioPlaying) {
2456
+ stopPlayback();
2457
+ }
2458
+ if (b.recordingState.audioURL) {
2459
+ window.URL.revokeObjectURL(b.recordingState.audioURL);
2460
+ b.recordingState.recording = null;
2461
+ }
2462
+ b.recordingState.audioPlaying = false;
2463
+ resolve(null);
2464
+ b.recordingState.currentlyErasing = false;
2465
+ });
2466
+ }
2410
2467
  function erase() {
2411
2468
  const b = pxsim.board();
2412
2469
  if (!b)
2413
2470
  return;
2414
2471
  b.recordingState.chunks = [];
2415
- if (b.recordingState.audioPlaying) {
2416
- b.recordingState.recording.pause();
2417
- b.recordingState.audioPlaying = false;
2418
- b.recordingState.recording.currentTime = 0;
2419
- }
2420
- window.URL.revokeObjectURL(b.recordingState.audioURL);
2421
- b.recordingState.recording = null;
2472
+ b.recordingState.currentlyErasing = true;
2422
2473
  }
2423
2474
  record_1.erase = erase;
2424
2475
  function setMicrophoneGain(gain) {
@@ -4084,6 +4135,65 @@ path.sim-board {
4084
4135
  })(visuals = pxsim.visuals || (pxsim.visuals = {}));
4085
4136
  })(pxsim || (pxsim = {}));
4086
4137
  var pxsim;
4138
+ (function (pxsim) {
4139
+ const icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!-- Font Awesome Pro 5.15.4 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M215.03 71.05L126.06 160H24c-13.26 0-24 10.74-24 24v144c0 13.25 10.74 24 24 24h102.06l88.97 88.95c15.03 15.03 40.97 4.47 40.97-16.97V88.02c0-21.46-25.96-31.98-40.97-16.97zM461.64 256l45.64-45.64c6.3-6.3 6.3-16.52 0-22.82l-22.82-22.82c-6.3-6.3-16.52-6.3-22.82 0L416 210.36l-45.64-45.64c-6.3-6.3-16.52-6.3-22.82 0l-22.82 22.82c-6.3 6.3-6.3 16.52 0 22.82L370.36 256l-45.63 45.63c-6.3 6.3-6.3 16.52 0 22.82l22.82 22.82c6.3 6.3 16.52 6.3 22.82 0L416 301.64l45.64 45.64c6.3 6.3 16.52 6.3 22.82 0l22.82-22.82c6.3-6.3 6.3-16.52 0-22.82L461.64 256z"/></svg>`;
4140
+ // We only need to unmute from within the iframe once
4141
+ let hasUnmuted = false;
4142
+ function createMuteButton() {
4143
+ const el = document.createElement("div");
4144
+ el.setAttribute("id", "safari-mute-button-outer");
4145
+ el.innerHTML = `
4146
+ <button class="safari-mute-button">
4147
+ ${icon}
4148
+ </button>
4149
+ `;
4150
+ const button = el.firstElementChild;
4151
+ button.setAttribute("title", pxsim.localization.lf("Unmute simulator"));
4152
+ button.addEventListener("click", () => {
4153
+ pxsim.AudioContextManager.mute(false);
4154
+ pxsim.setParentMuteState("unmuted");
4155
+ button.remove();
4156
+ hasUnmuted = true;
4157
+ });
4158
+ return el;
4159
+ }
4160
+ pxsim.createMuteButton = createMuteButton;
4161
+ function shouldShowMute() {
4162
+ return isSafari() && !hasUnmuted;
4163
+ }
4164
+ pxsim.shouldShowMute = shouldShowMute;
4165
+ // Everything below is taken from browserutils in pxt
4166
+ function hasNavigator() {
4167
+ return typeof navigator !== "undefined";
4168
+ }
4169
+ pxsim.hasNavigator = hasNavigator;
4170
+ //Microsoft Edge lies about its user agent and claims to be Chrome, but Microsoft Edge/Version
4171
+ //is always at the end
4172
+ function isEdge() {
4173
+ return hasNavigator() && /Edge/i.test(navigator.userAgent);
4174
+ }
4175
+ pxsim.isEdge = isEdge;
4176
+ //IE11 also lies about its user agent, but has Trident appear somewhere in
4177
+ //the user agent. Detecting the different between IE11 and Microsoft Edge isn't
4178
+ //super-important because the UI is similar enough
4179
+ function isIE() {
4180
+ return hasNavigator() && /Trident/i.test(navigator.userAgent);
4181
+ }
4182
+ pxsim.isIE = isIE;
4183
+ //Microsoft Edge and IE11 lie about being Chrome. Chromium-based Edge ("Edgeium") will be detected as Chrome, that is ok. If you're looking for Edgeium, use `isChromiumEdge()`.
4184
+ function isChrome() {
4185
+ return !isEdge() && !isIE() && !!navigator && (/Chrome/i.test(navigator.userAgent) || /Chromium/i.test(navigator.userAgent));
4186
+ }
4187
+ pxsim.isChrome = isChrome;
4188
+ //Chrome and Microsoft Edge lie about being Safari
4189
+ function isSafari() {
4190
+ //Could also check isMac but I don't want to risk excluding iOS
4191
+ //Checking for iPhone, iPod or iPad as well as Safari in order to detect home screen browsers on iOS
4192
+ return !isChrome() && !isEdge() && !!navigator && /(Macintosh|Safari|iPod|iPhone|iPad)/i.test(navigator.userAgent);
4193
+ }
4194
+ pxsim.isSafari = isSafari;
4195
+ })(pxsim || (pxsim = {}));
4196
+ var pxsim;
4087
4197
  (function (pxsim) {
4088
4198
  var pxtcore;
4089
4199
  (function (pxtcore) {