pxt-common-packages 9.5.12 → 10.1.2

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 (42) hide show
  1. package/built/common-sim.js +2 -2
  2. package/libs/azureiot/built/debug/binary.js +461 -461
  3. package/libs/color/built/debug/binary.js +8 -8
  4. package/libs/color-sensor/built/debug/binary.js +8 -8
  5. package/libs/controller/built/debug/binary.js +6898 -6898
  6. package/libs/controller---none/built/debug/binary.js +6878 -6878
  7. package/libs/datalogger/built/debug/binary.js +63 -63
  8. package/libs/edge-connector/built/debug/binary.js +8 -8
  9. package/libs/esp32/built/debug/binary.js +462 -462
  10. package/libs/game/_locales/game-jsdoc-strings.json +4 -0
  11. package/libs/game/_locales/game-strings.json +2 -0
  12. package/libs/game/built/debug/binary.js +6817 -6817
  13. package/libs/game/docs/reference/info/change-score-by.md +2 -1
  14. package/libs/game/docs/reference/info/on-score.md +72 -0
  15. package/libs/game/docs/reference/info/score.md +2 -1
  16. package/libs/game/docs/reference/info/set-score.md +2 -1
  17. package/libs/game/docs/reference/tiles/tile-image-at-location.md +65 -0
  18. package/libs/game/info.ts +53 -0
  19. package/libs/game/sim/keymap.ts +2 -2
  20. package/libs/game/sprite.ts +1 -0
  21. package/libs/game/tilemap.ts +1 -1
  22. package/libs/lcd/built/debug/binary.js +8 -8
  23. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  24. package/libs/lora/built/debug/binary.js +8 -8
  25. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  26. package/libs/mqtt/built/debug/binary.js +176 -176
  27. package/libs/net/built/debug/binary.js +176 -176
  28. package/libs/net-game/built/debug/binary.js +8406 -8406
  29. package/libs/palette/built/debug/binary.js +6816 -6816
  30. package/libs/pixel/built/debug/binary.js +8 -8
  31. package/libs/power/built/debug/binary.js +8 -8
  32. package/libs/proximity/built/debug/binary.js +8 -8
  33. package/libs/radio/built/debug/binary.js +8 -8
  34. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  35. package/libs/radio-broadcast/docs/reference/radio-broadcast.md +21 -0
  36. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  37. package/libs/screen/built/debug/binary.js +50 -50
  38. package/libs/servo/built/debug/binary.js +8 -8
  39. package/libs/servo/docs/reference/servo.md +41 -0
  40. package/libs/sprite-scaling/built/debug/binary.js +6816 -6816
  41. package/libs/storyboard/built/debug/binary.js +6816 -6816
  42. package/package.json +1 -1
@@ -45,4 +45,5 @@ if (info.player2.life() > 8) {
45
45
  ## See also #seealso
46
46
 
47
47
  [set score](/reference/info/set-score),
48
- [score](/reference/info/score)
48
+ [score](/reference/info/score),
49
+ [on score](/reference/info/on-score)
@@ -0,0 +1,72 @@
1
+ # on Score
2
+
3
+ Run some code once when the player's score reaches the given value. This code will also run once if the score "passes" the given value after being changed by a value greater than 1.
4
+
5
+ ```sig
6
+ info.onScore(100, function () {})
7
+ ```
8
+
9
+ ## Parameters
10
+
11
+ * **score**: the target score value for this event to run
12
+ * **handler**: the code to run when the score reaches or passes the target value.
13
+
14
+ ## Example #example
15
+
16
+ ### Clicker game #ex1
17
+
18
+ Change the player's score by 1 each time a button is pressed and show some text when the score reaches 100!
19
+
20
+ ```blocks
21
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
22
+ info.changeScoreBy(1)
23
+ })
24
+ info.onScore(100, function () {
25
+ game.splash("Score is " + info.score())
26
+ })
27
+
28
+ ```
29
+
30
+ ### Multiplayer #ex2
31
+
32
+ Randomly give either player 1 or player 2 a point on each game update. The first player to reach 100 wins!
33
+
34
+ ```blocks
35
+ info.player2.onScore(100, function () {
36
+ game.splash("Player 2 wins!")
37
+ game.reset()
38
+ })
39
+ info.player1.onScore(100, function () {
40
+ game.splash("Player 1 wins!")
41
+ game.reset()
42
+ })
43
+ game.onUpdate(function () {
44
+ if (Math.percentChance(50)) {
45
+ info.player1.changeScoreBy(1)
46
+ } else {
47
+ info.player2.changeScoreBy(1)
48
+ }
49
+ })
50
+
51
+ ```
52
+
53
+ ### Passing the target score #ex3
54
+
55
+ This example demonstrates what happens when the score is changed by a value greater than 1. When the A button is pressed, the player's score
56
+ changes by 10. The event still runs even though it's looking for a score of 5!
57
+
58
+ ```blocks
59
+ controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
60
+ info.changeScoreBy(10)
61
+ })
62
+ info.onScore(5, function () {
63
+ game.splash("Score is " + info.score())
64
+ })
65
+
66
+ ```
67
+
68
+ ## See also #seealso
69
+
70
+ [score](/reference/info/score),
71
+ [set score](/reference/info/set-score),
72
+ [change score by](/reference/info/change-score-by)
@@ -45,4 +45,5 @@ if (info.player2.score() > 9999) {
45
45
  ## See also #seealso
46
46
 
47
47
  [set score](/reference/info/set-score),
48
- [change score by](/reference/info/change-score-by)
48
+ [change score by](/reference/info/change-score-by),
49
+ [on score](/reference/info/on-score)
@@ -31,4 +31,5 @@ info.player2.setScore(110)
31
31
  ## See also #seealso
32
32
 
33
33
  [change score by](/reference/info/change-score-by),
34
- [score](/reference/info/score)
34
+ [score](/reference/info/score),
35
+ [on score](/reference/info/on-score)
@@ -0,0 +1,65 @@
1
+ # tile Image At Location
2
+
3
+ Get the image of the tile at a location in the tilemap.
4
+
5
+ ```sig
6
+ tiles.tileImageAtLocation(tiles.getTileAtLocation(0, 0))
7
+ ```
8
+
9
+ ## Parameters
10
+
11
+ * **location**: the [location](/reference/tiles/location) object for the tile to return it's image.
12
+
13
+ ## Returns
14
+
15
+ * the [image](/types/image) of the tile at the **location** in the tilemap.
16
+
17
+ ## Example #example
18
+
19
+ Make a tilemap with some smiley face tiles. Create a new sprite using the image from one of the smiley face tiles. Have the new sprite move across the screen and back.
20
+
21
+ ```blocks
22
+ scene.onHitWall(SpriteKind.Player, function (sprite, location) {
23
+ sprite.startEffect(effects.bubbles, 500)
24
+ })
25
+ tiles.setCurrentTilemap(tilemap`level1`)
26
+ let tileImage = tiles.tileImageAtLocation(tiles.getTileLocation(0, 0))
27
+ let mySprite = sprites.create(tileImage, SpriteKind.Player)
28
+ mySprite.setBounceOnWall(true)
29
+ mySprite.vx = 50
30
+ ```
31
+
32
+ ## See also #seealso
33
+
34
+ [location](/reference/tiles/location)
35
+
36
+ ```jres
37
+ {
38
+ "transparency16": {
39
+ "data": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
40
+ "mimeType": "image/x-mkcd-f4",
41
+ "tilemapTile": true
42
+ },
43
+ "tile1": {
44
+ "data": "hwQQABAAAABERERERERERERERERERERERPT/RET/RERE9PRERERPRET0/0RERPRERERERERE9ERERERERET0RERERPRPRPRERERE9E9E9ERERERERET0RERERERERPRERPT/RERE9ERE9PRERERPRET0/0RE/0RERERERERERERERERERERERA==",
45
+ "mimeType": "image/x-mkcd-f4",
46
+ "tilemapTile": true,
47
+ "displayName": "myTile"
48
+ },
49
+ "level1": {
50
+ "id": "level1",
51
+ "mimeType": "application/mkcd-tilemap",
52
+ "data": "MTAwYTAwMDgwMDAxMDAwMTAwMDEwMDAxMDAwMTAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwMTAwMDEwMDAxMDAwMTAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA==",
53
+ "tileset": [
54
+ "myTiles.transparency16",
55
+ "myTiles.tile1"
56
+ ],
57
+ "displayName": "level1"
58
+ },
59
+ "*": {
60
+ "mimeType": "image/x-mkcd-f4",
61
+ "dataEncoding": "base64",
62
+ "namespace": "myTiles"
63
+ }
64
+ }
65
+ ```
package/libs/game/info.ts CHANGED
@@ -20,12 +20,20 @@ namespace info {
20
20
  _ExplicitlySetLife = 1 << 7,
21
21
  }
22
22
 
23
+ class ScoreReachedHandler {
24
+ public isTriggered: boolean;
25
+ constructor(public score: number, public handler: () => void) {
26
+ this.isTriggered = false;
27
+ }
28
+ }
29
+
23
30
  export class PlayerState {
24
31
  public score: number;
25
32
  // undefined: not used
26
33
  // null: reached 0 and callback was invoked
27
34
  public life: number;
28
35
  public lifeZeroHandler: () => void;
36
+ public scoreReachedHandler: ScoreReachedHandler
29
37
 
30
38
  constructor() { }
31
39
  }
@@ -332,6 +340,24 @@ namespace info {
332
340
  player1.onLifeZero(handler);
333
341
  }
334
342
 
343
+ /**
344
+ * Runs code once each time the score reaches a given value. This will also
345
+ * run if the score "passes" the given value in either direction without ever
346
+ * having the exact value (e.g. if score is changed by more than 1)
347
+ *
348
+ * @param score the score to fire the event on
349
+ * @param handler code to run when the score reaches the given value
350
+ */
351
+ //% weight=10
352
+ //% blockId=gameonscore
353
+ //% block="on score $score"
354
+ //% score.defl=100
355
+ //% help=info/on-score
356
+ //% group="Score"
357
+ export function onScore(score: number, handler: () => void) {
358
+ player1.onScore(score, handler);
359
+ }
360
+
335
361
  /**
336
362
  * Start a countdown of the given duration in seconds
337
363
  * @param duration the duration of the countdown, eg: 10
@@ -618,7 +644,16 @@ namespace info {
618
644
  }
619
645
 
620
646
  this.score(); // invoked for side effects
647
+
648
+ const oldScore = state.score || 0;
621
649
  state.score = (value | 0);
650
+
651
+ if (state.scoreReachedHandler && (
652
+ (oldScore < state.scoreReachedHandler.score && state.score >= state.scoreReachedHandler.score) ||
653
+ (oldScore > state.scoreReachedHandler.score && state.score <= state.scoreReachedHandler.score)
654
+ )) {
655
+ state.scoreReachedHandler.handler();
656
+ }
622
657
  }
623
658
 
624
659
  /**
@@ -709,6 +744,24 @@ namespace info {
709
744
  state.lifeZeroHandler = handler;
710
745
  }
711
746
 
747
+ /**
748
+ * Runs code once each time the score reaches a given value. This will also
749
+ * run if the score "passes" the given value in either direction without ever
750
+ * having the exact value (e.g. if score is changed by more than 1)
751
+ *
752
+ * @param score the score to fire the event on
753
+ * @param handler code to run when the score reaches the given value
754
+ */
755
+ //% blockId=playerinfoonscore
756
+ //% block="on $this score $score"
757
+ //% score.defl=100
758
+ //% help=info/on-score
759
+ //% group="Multiplayer"
760
+ onScore(score: number, handler: () => void) {
761
+ const state = this.getState();
762
+ state.scoreReachedHandler = new ScoreReachedHandler(score, handler);
763
+ }
764
+
712
765
  raiseLifeZero(gameOver: boolean) {
713
766
  const state = this.getState();
714
767
  if (state.life !== null && state.life <= 0) {
@@ -89,8 +89,8 @@ namespace pxsim {
89
89
  this.setSystemKeys(
90
90
  80, // P - Screenshot
91
91
  82, // R - Gif
92
- 0, // Menu - not mapped
93
- 0 // Reset - not mapped
92
+ 192, // Menu - '`' (backtick) button
93
+ 50 // Reset - Backspace button
94
94
  );
95
95
 
96
96
  // Player 1 alternate mapping. This is cleared when the game sets any player keys explicitly
@@ -857,6 +857,7 @@ class Sprite extends sprites.BaseSprite {
857
857
  //% this.shadow=variables_get
858
858
  //% this.defl=mySprite
859
859
  //% blockNamespace="scene" group="Locations" weight=90
860
+ //% help=scene/tilemap-location
860
861
  tilemapLocation(): tiles.Location {
861
862
  const scene = game.currentScene();
862
863
  if (!scene.tileMap) return undefined;
@@ -110,7 +110,7 @@ namespace tiles {
110
110
  //% this.defl=location
111
111
  //% this.shadow=variables_get
112
112
  //% group="Locations" blockGap=8
113
- //% weight=10
113
+ //% weight=10 help=tiles/get-neighboring-location
114
114
  public getNeighboringLocation(direction: CollisionDirection): Location {
115
115
  switch (direction) {
116
116
  case CollisionDirection.Top:
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48217(s) {
59
+ function _main___P48222(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___48460 = (undefined);
70
- globals._pollEventQueue___48473 = (undefined);
69
+ globals._intervals___48465 = (undefined);
70
+ globals._pollEventQueue___48478 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48217.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48217.continuations = [ ]
75
+ _main___P48222.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48222.continuations = [ ]
77
77
 
78
- function _main___P48217_mk(s) {
78
+ function _main___P48222_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48217, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48222, 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___P48217_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48217
91
+ return _main___P48222
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___P96983(s) {
59
+ function _main___P96998(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___97226 = (undefined);
70
- globals._pollEventQueue___97239 = (undefined);
69
+ globals._intervals___97241 = (undefined);
70
+ globals._pollEventQueue___97254 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P96983.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P96983.continuations = [ ]
75
+ _main___P96998.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P96998.continuations = [ ]
77
77
 
78
- function _main___P96983_mk(s) {
78
+ function _main___P96998_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P96983, depth: s.depth + 1,
81
+ parent: s, fn: _main___P96998, 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___P96983_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P96983
91
+ return _main___P96998
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___P59519(s) {
59
+ function _main___P59524(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___59762 = (undefined);
70
- globals._pollEventQueue___59775 = (undefined);
69
+ globals._intervals___59767 = (undefined);
70
+ globals._pollEventQueue___59780 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P59519.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P59519.continuations = [ ]
75
+ _main___P59524.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P59524.continuations = [ ]
77
77
 
78
- function _main___P59519_mk(s) {
78
+ function _main___P59524_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P59519, depth: s.depth + 1,
81
+ parent: s, fn: _main___P59524, 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___P59519_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P59519
91
+ return _main___P59524
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___P188039(s) {
59
+ function _main___P188074(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___188282 = (undefined);
70
- globals._pollEventQueue___188295 = (undefined);
69
+ globals._intervals___188317 = (undefined);
70
+ globals._pollEventQueue___188330 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P188039.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P188039.continuations = [ ]
75
+ _main___P188074.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P188074.continuations = [ ]
77
77
 
78
- function _main___P188039_mk(s) {
78
+ function _main___P188074_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P188039, depth: s.depth + 1,
81
+ parent: s, fn: _main___P188074, 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___P188039_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P188039
91
+ return _main___P188074
92
92
  })