pxt-common-packages 9.5.9 → 9.5.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 (37) hide show
  1. package/built/common-sim.js +66 -66
  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 +7875 -7657
  6. package/libs/controller---none/built/debug/binary.js +7856 -7638
  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 +5 -0
  11. package/libs/game/built/debug/binary.js +7769 -7551
  12. package/libs/game/extendableSprite.ts +80 -0
  13. package/libs/game/game.ts +3 -0
  14. package/libs/game/info.ts +13 -0
  15. package/libs/game/pxt.json +1 -0
  16. package/libs/game/sim/keymap.ts +3 -3
  17. package/libs/game/sprite.ts +68 -57
  18. package/libs/lcd/built/debug/binary.js +8 -8
  19. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  20. package/libs/lora/built/debug/binary.js +8 -8
  21. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  22. package/libs/mqtt/built/debug/binary.js +176 -176
  23. package/libs/net/built/debug/binary.js +176 -176
  24. package/libs/net-game/built/debug/binary.js +9557 -9339
  25. package/libs/palette/built/debug/binary.js +7768 -7550
  26. package/libs/pixel/built/debug/binary.js +8 -8
  27. package/libs/power/built/debug/binary.js +8 -8
  28. package/libs/proximity/built/debug/binary.js +8 -8
  29. package/libs/radio/built/debug/binary.js +8 -8
  30. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  31. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  32. package/libs/screen/built/debug/binary.js +50 -50
  33. package/libs/servo/built/debug/binary.js +8 -8
  34. package/libs/settings---files/settings.cpp +2 -1
  35. package/libs/sprite-scaling/built/debug/binary.js +7768 -7550
  36. package/libs/storyboard/built/debug/binary.js +7768 -7550
  37. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ namespace sprites {
2
+ /**
3
+ * A version of the Sprite class that is easier to extend.
4
+ *
5
+ * Unlike the normal Sprite class, this class will automatically add
6
+ * itself to the physics engine and run all sprite created handlers
7
+ * in the constructor
8
+ */
9
+ export class ExtendableSprite extends Sprite {
10
+ protected hasCustomDimensions: boolean;
11
+
12
+ constructor(spriteImage: Image, kind?: number) {
13
+ super(spriteImage);
14
+
15
+ const scene = game.currentScene();
16
+ this.setKind(kind);
17
+ scene.physicsEngine.addSprite(this);
18
+
19
+ // run on created handlers
20
+ scene.createdHandlers
21
+ .filter(h => h.kind == kind)
22
+ .forEach(h => h.handler(this));
23
+
24
+ this.hasCustomDimensions = false;
25
+ }
26
+
27
+ /**
28
+ * Override to change how the sprite is drawn to the screen
29
+ *
30
+ * @param drawLeft The left position to draw the sprite at (already adjusted for camera)
31
+ * @param drawTop The top position to draw the sprite at (already adjusted for camera)
32
+ */
33
+ draw(drawLeft: number, drawTop: number) {
34
+ super.drawSprite(drawLeft, drawTop);
35
+ }
36
+
37
+ /**
38
+ * Override to add update logic for a sprite. This method runs once per frame
39
+ *
40
+ * @param deltaTimeMillis The time that has elapsed since the last frame in milliseconds
41
+ */
42
+ update(deltaTimeMillis: number) {
43
+ }
44
+
45
+ /**
46
+ * Sets the width and height of this sprite. Once set, this will also prevent
47
+ * this width and height from automatically changing whenever scale or the image
48
+ * changes
49
+ */
50
+ setDimensions(width: number, height: number) {
51
+ this._width = Fx8(width);
52
+ this._height = Fx8(height);
53
+ this.hasCustomDimensions = true;
54
+ this.resetHitbox();
55
+ }
56
+
57
+ __update(camera: scene.Camera, dt: number) {
58
+ super.__update(camera, dt);
59
+ this.update(game.currentScene().eventContext.deltaTimeMillis)
60
+ }
61
+
62
+ setHitbox() {
63
+ if (this.hasCustomDimensions) {
64
+ this._hitbox = new game.Hitbox(this, this._width, this._height, Fx.zeroFx8, Fx.zeroFx8)
65
+ }
66
+ else {
67
+ super.setHitbox();
68
+ }
69
+ }
70
+
71
+ protected drawSprite(drawLeft: number, drawTop: number): void {
72
+ this.draw(drawLeft, drawTop);
73
+ }
74
+
75
+ protected recalcSize() {
76
+ if (this.hasCustomDimensions) return;
77
+ super.recalcSize();
78
+ }
79
+ }
80
+ }
package/libs/game/game.ts CHANGED
@@ -191,6 +191,9 @@ namespace game {
191
191
  effect = win ? winEffect : loseEffect;
192
192
  }
193
193
 
194
+ // Save all scores as relevant to the game.
195
+ info.saveAllScores();
196
+
194
197
  // collect the scores before poping the scenes
195
198
  const scoreInfo = info.player1.getState();
196
199
  const highScore = info.highScore();
package/libs/game/info.ts CHANGED
@@ -204,6 +204,19 @@ namespace info {
204
204
  `;
205
205
  }
206
206
 
207
+ export function saveAllScores() {
208
+ const allScoresKey = "all-scores";
209
+ let allScores: number[];
210
+ if (players) {
211
+ allScores = players.filter(item => item.hasScore()).map(item => item.score());
212
+ }
213
+ else {
214
+ allScores = [];
215
+ }
216
+
217
+ settings.writeJSON(allScoresKey, allScores);
218
+ }
219
+
207
220
  export function saveHighScore() {
208
221
  if (players) {
209
222
  let hs = 0;
@@ -13,6 +13,7 @@
13
13
  "spritesay.ts",
14
14
  "sprites.ts",
15
15
  "sprite.ts",
16
+ "extendableSprite.ts",
16
17
  "sprite.d.ts",
17
18
  "spritemap.ts",
18
19
  "spriteevents.ts",
@@ -67,9 +67,9 @@ namespace pxsim {
67
67
  this.setPlayerKeys(
68
68
  1, // Player 1
69
69
  87, // W - Up
70
- 83, // D - Down
70
+ 83, // S - Down
71
71
  65, // A - Left
72
- 83, // S - Right
72
+ 68, // D - Right
73
73
  32, // Space - A
74
74
  13 // Enter - B
75
75
  );
@@ -79,7 +79,7 @@ namespace pxsim {
79
79
  73, // I - Up
80
80
  75, // K - Down
81
81
  74, // J - Left
82
- 75, // K - Right
82
+ 76, // L - Right
83
83
  85, // U - A
84
84
  79 // O - B
85
85
  );
@@ -394,7 +394,7 @@ class Sprite extends sprites.BaseSprite {
394
394
  return !(this.flags & SpriteFlag.Invisible);
395
395
  }
396
396
 
397
- private recalcSize(): void {
397
+ protected recalcSize(): void {
398
398
  this._width = Fx8(this._image.width * this.sx);
399
399
  this._height = Fx8(this._image.height * this.sy);
400
400
  this.resetHitbox();
@@ -645,21 +645,7 @@ class Sprite extends sprites.BaseSprite {
645
645
  }
646
646
 
647
647
  __drawCore(camera: scene.Camera) {
648
- if (this.sayRenderer) {
649
- if (this.sayEndTime !== undefined) {
650
- if (control.millis() < this.sayEndTime) {
651
- this.sayRenderer.draw(screen, camera, this);
652
- }
653
- else {
654
- this.sayRenderer.destroy();
655
- this.sayRenderer = undefined;
656
- this.sayEndTime = undefined;
657
- }
658
- }
659
- else {
660
- this.sayRenderer.draw(screen, camera, this)
661
- }
662
- }
648
+ this.drawSay(camera);
663
649
 
664
650
  if (this.isOutOfScreen(camera)) return;
665
651
 
@@ -669,47 +655,8 @@ class Sprite extends sprites.BaseSprite {
669
655
  const l = Math.floor(this.left - ox);
670
656
  const t = Math.floor(this.top - oy);
671
657
 
672
- if (!this.isScaled())
673
- screen.drawTransparentImage(this._image, l, t);
674
- else
675
- screen.blit(
676
- // dst rect in screen
677
- l, t,
678
- this.width,
679
- this.height,
680
- // src rect in sprite image
681
- this._image,
682
- 0, 0,
683
- this._image.width, this._image.height,
684
- true, false);
685
-
686
- if (this.flags & SpriteFlag.ShowPhysics) {
687
- const font = image.font5;
688
- const margin = 2;
689
- let tx = l;
690
- let ty = t + this.height + margin;
691
- screen.print(`${this.x >> 0},${this.y >> 0}`, tx, ty, 1, font);
692
- tx -= font.charWidth;
693
- if (this.vx || this.vy) {
694
- ty += font.charHeight + margin;
695
- screen.print(`v${this.vx >> 0},${this.vy >> 0}`, tx, ty, 1, font);
696
- }
697
- if (this.ax || this.ay) {
698
- ty += font.charHeight + margin;
699
- screen.print(`a${this.ax >> 0},${this.ay >> 0}`, tx, ty, 1, font);
700
- }
701
- }
702
-
703
- // debug info
704
- if (game.debug) {
705
- screen.drawRect(
706
- Fx.toInt(this._hitbox.left) - ox,
707
- Fx.toInt(this._hitbox.top) - oy,
708
- Fx.toInt(this._hitbox.width),
709
- Fx.toInt(this._hitbox.height),
710
- 1
711
- );
712
- }
658
+ this.drawSprite(l, t);
659
+ this.drawDebug(l, t, ox, oy);
713
660
  }
714
661
 
715
662
  __update(camera: scene.Camera, dt: number) {
@@ -1171,4 +1118,68 @@ class Sprite extends sprites.BaseSprite {
1171
1118
  toString() {
1172
1119
  return `${this.id}(${this.x},${this.y})->(${this.vx},${this.vy})`;
1173
1120
  }
1121
+
1122
+ protected drawSay(camera: scene.Camera) {
1123
+ if (this.sayRenderer) {
1124
+ if (this.sayEndTime !== undefined) {
1125
+ if (control.millis() < this.sayEndTime) {
1126
+ this.sayRenderer.draw(screen, camera, this);
1127
+ }
1128
+ else {
1129
+ this.sayRenderer.destroy();
1130
+ this.sayRenderer = undefined;
1131
+ this.sayEndTime = undefined;
1132
+ }
1133
+ }
1134
+ else {
1135
+ this.sayRenderer.draw(screen, camera, this)
1136
+ }
1137
+ }
1138
+ }
1139
+
1140
+ protected drawDebug(left: number, top: number, offsetX: number, offsetY: number) {
1141
+ if (this.flags & SpriteFlag.ShowPhysics) {
1142
+ const font = image.font5;
1143
+ const margin = 2;
1144
+ let tx = left;
1145
+ let ty = top + this.height + margin;
1146
+ screen.print(`${this.x >> 0},${this.y >> 0}`, tx, ty, 1, font);
1147
+ tx -= font.charWidth;
1148
+ if (this.vx || this.vy) {
1149
+ ty += font.charHeight + margin;
1150
+ screen.print(`v${this.vx >> 0},${this.vy >> 0}`, tx, ty, 1, font);
1151
+ }
1152
+ if (this.ax || this.ay) {
1153
+ ty += font.charHeight + margin;
1154
+ screen.print(`a${this.ax >> 0},${this.ay >> 0}`, tx, ty, 1, font);
1155
+ }
1156
+ }
1157
+
1158
+ // debug info
1159
+ if (game.debug) {
1160
+ screen.drawRect(
1161
+ Fx.toInt(this._hitbox.left) - offsetX,
1162
+ Fx.toInt(this._hitbox.top) - offsetY,
1163
+ Fx.toInt(this._hitbox.width),
1164
+ Fx.toInt(this._hitbox.height),
1165
+ 1
1166
+ );
1167
+ }
1168
+ }
1169
+
1170
+ protected drawSprite(drawLeft: number, drawTop: number) {
1171
+ if (!this.isScaled())
1172
+ screen.drawTransparentImage(this._image, drawLeft, drawTop);
1173
+ else
1174
+ screen.blit(
1175
+ // dst rect in screen
1176
+ drawLeft, drawTop,
1177
+ this.width,
1178
+ this.height,
1179
+ // src rect in sprite image
1180
+ this._image,
1181
+ 0, 0,
1182
+ this._image.width, this._image.height,
1183
+ true, false);
1184
+ }
1174
1185
  }
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48182(s) {
59
+ function _main___P48217(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___48425 = (undefined);
70
- globals._pollEventQueue___48438 = (undefined);
69
+ globals._intervals___48460 = (undefined);
70
+ globals._pollEventQueue___48473 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48182.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48182.continuations = [ ]
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 = [ ]
77
77
 
78
- function _main___P48182_mk(s) {
78
+ function _main___P48217_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48182, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48217, 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___P48182_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48182
91
+ return _main___P48217
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___P96878(s) {
59
+ function _main___P96983(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___97121 = (undefined);
70
- globals._pollEventQueue___97134 = (undefined);
69
+ globals._intervals___97226 = (undefined);
70
+ globals._pollEventQueue___97239 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P96878.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P96878.continuations = [ ]
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 = [ ]
77
77
 
78
- function _main___P96878_mk(s) {
78
+ function _main___P96983_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P96878, depth: s.depth + 1,
81
+ parent: s, fn: _main___P96983, 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___P96878_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P96878
91
+ return _main___P96983
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___P59484(s) {
59
+ function _main___P59519(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___59727 = (undefined);
70
- globals._pollEventQueue___59740 = (undefined);
69
+ globals._intervals___59762 = (undefined);
70
+ globals._pollEventQueue___59775 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P59484.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P59484.continuations = [ ]
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 = [ ]
77
77
 
78
- function _main___P59484_mk(s) {
78
+ function _main___P59519_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P59484, depth: s.depth + 1,
81
+ parent: s, fn: _main___P59519, 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___P59484_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P59484
91
+ return _main___P59519
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___P187794(s) {
59
+ function _main___P188039(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___188037 = (undefined);
70
- globals._pollEventQueue___188050 = (undefined);
69
+ globals._intervals___188282 = (undefined);
70
+ globals._pollEventQueue___188295 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P187794.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P187794.continuations = [ ]
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 = [ ]
77
77
 
78
- function _main___P187794_mk(s) {
78
+ function _main___P188039_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P187794, depth: s.depth + 1,
81
+ parent: s, fn: _main___P188039, 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___P187794_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P187794
91
+ return _main___P188039
92
92
  })