pxt-common-packages 10.3.21 → 10.3.23

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 (40) hide show
  1. package/built/common-sim.d.ts +14 -2
  2. package/built/common-sim.js +83 -29
  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 +7986 -7953
  7. package/libs/controller---none/built/debug/binary.js +7965 -7932
  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 +7878 -7845
  12. package/libs/game/info.ts +18 -8
  13. package/libs/game/sprite.ts +2 -0
  14. package/libs/game/sprites.ts +1 -0
  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/microphone/sim/state.ts +24 -1
  20. package/libs/mqtt/built/debug/binary.js +176 -176
  21. package/libs/multiplayer/player.ts +1 -0
  22. package/libs/net/built/debug/binary.js +176 -176
  23. package/libs/net-game/built/debug/binary.js +9666 -9633
  24. package/libs/palette/built/debug/binary.js +7877 -7844
  25. package/libs/pixel/built/debug/binary.js +8 -8
  26. package/libs/power/built/debug/binary.js +8 -8
  27. package/libs/proximity/built/debug/binary.js +8 -8
  28. package/libs/radio/built/debug/binary.js +8 -8
  29. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  30. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  31. package/libs/screen/built/debug/binary.js +50 -50
  32. package/libs/screen/sim/image.ts +32 -31
  33. package/libs/servo/built/debug/binary.js +8 -8
  34. package/libs/shader/pxt.json +14 -0
  35. package/libs/shader/shader.cpp +140 -0
  36. package/libs/shader/shader.ts +19 -0
  37. package/libs/shader/sim/shader.ts +37 -0
  38. package/libs/sprite-scaling/built/debug/binary.js +7877 -7844
  39. package/libs/storyboard/built/debug/binary.js +7877 -7844
  40. package/package.json +1 -1
@@ -938,9 +938,15 @@ declare namespace pxsim.input {
938
938
  }
939
939
  declare namespace pxsim {
940
940
  interface MicrophoneBoard {
941
- microphoneState: AnalogSensorState;
941
+ microphoneState: MicrophoneState;
942
942
  }
943
- function microphoneState(): AnalogSensorState;
943
+ class MicrophoneState extends AnalogSensorState {
944
+ onSoundRegistered: boolean;
945
+ soundLevelRequested: boolean;
946
+ private pingUsed;
947
+ pingSoundLevel: () => void;
948
+ }
949
+ function microphoneState(): MicrophoneState;
944
950
  }
945
951
  declare namespace pxsim.music {
946
952
  function playInstructions(b: RefBuffer): Promise<void>;
@@ -1097,6 +1103,8 @@ declare namespace pxsim {
1097
1103
  }
1098
1104
  }
1099
1105
  declare namespace pxsim.ImageMethods {
1106
+ function XX(x: number): number;
1107
+ function YY(x: number): number;
1100
1108
  function width(img: RefImage): number;
1101
1109
  function height(img: RefImage): number;
1102
1110
  function isMono(img: RefImage): boolean;
@@ -1216,6 +1224,10 @@ declare namespace pxsim.settings {
1216
1224
  function _userClean(): void;
1217
1225
  function _list(prefix: string): RefCollection;
1218
1226
  }
1227
+ declare namespace pxsim.ShaderMethods {
1228
+ function _mergeImage(dst: RefImage, src: RefImage, xy: number): void;
1229
+ function _mapImage(dst: RefImage, src: RefImage, xy: number, buf: RefBuffer): void;
1230
+ }
1219
1231
  declare namespace pxsim {
1220
1232
  class StorageState {
1221
1233
  files: pxsim.Map<number[]>;
@@ -3179,8 +3179,30 @@ var pxsim;
3179
3179
  input.setLoudSoundThreshold = setLoudSoundThreshold;
3180
3180
  })(input = pxsim.input || (pxsim.input = {}));
3181
3181
  })(pxsim || (pxsim = {}));
3182
+ /// <reference path="../../core/sim/analogSensor.ts" />
3182
3183
  var pxsim;
3183
3184
  (function (pxsim) {
3185
+ class MicrophoneState extends pxsim.AnalogSensorState {
3186
+ constructor() {
3187
+ super(...arguments);
3188
+ this.onSoundRegistered = false;
3189
+ this.soundLevelRequested = false;
3190
+ this.pingSoundLevel = () => {
3191
+ if (this.onSoundRegistered) {
3192
+ return;
3193
+ }
3194
+ this.soundLevelRequested = true;
3195
+ pxsim.runtime.queueDisplayUpdate();
3196
+ clearTimeout(this.pingUsed);
3197
+ this.pingUsed = setTimeout(() => {
3198
+ this.soundLevelRequested = false;
3199
+ pxsim.runtime.queueDisplayUpdate();
3200
+ this.pingUsed = undefined;
3201
+ }, 100);
3202
+ };
3203
+ }
3204
+ }
3205
+ pxsim.MicrophoneState = MicrophoneState;
3184
3206
  function microphoneState() {
3185
3207
  return pxsim.board().microphoneState;
3186
3208
  }
@@ -3771,7 +3793,9 @@ var pxsim;
3771
3793
  var ImageMethods;
3772
3794
  (function (ImageMethods) {
3773
3795
  function XX(x) { return (x << 16) >> 16; }
3796
+ ImageMethods.XX = XX;
3774
3797
  function YY(x) { return x >> 16; }
3798
+ ImageMethods.YY = YY;
3775
3799
  function width(img) { return img._width; }
3776
3800
  ImageMethods.width = width;
3777
3801
  function height(img) { return img._height; }
@@ -4215,57 +4239,58 @@ var pxsim;
4215
4239
  }
4216
4240
  ImageMethods.drawLine = drawLine;
4217
4241
  function drawIcon(img, icon, x, y, color) {
4218
- const img2 = icon.data;
4242
+ const src = icon.data;
4219
4243
  if (!pxsim.image.isValidImage(icon))
4220
4244
  return;
4221
- if (img2[1] != 1)
4245
+ if (src[1] != 1)
4222
4246
  return; // only mono
4223
- let w = pxsim.image.bufW(img2);
4224
- let h = pxsim.image.bufH(img2);
4225
- let byteH = pxsim.image.byteHeight(h, 1);
4247
+ let width = pxsim.image.bufW(src);
4248
+ let height = pxsim.image.bufH(src);
4249
+ let byteH = pxsim.image.byteHeight(height, 1);
4226
4250
  x |= 0;
4227
4251
  y |= 0;
4228
- const sh = img._height;
4229
- const sw = img._width;
4230
- if (x + w <= 0)
4252
+ const destHeight = img._height;
4253
+ const destWidth = img._width;
4254
+ if (x + width <= 0)
4231
4255
  return;
4232
- if (x >= sw)
4256
+ if (x >= destWidth)
4233
4257
  return;
4234
- if (y + h <= 0)
4258
+ if (y + height <= 0)
4235
4259
  return;
4236
- if (y >= sh)
4260
+ if (y >= destHeight)
4237
4261
  return;
4238
4262
  img.makeWritable();
4239
- let p = 8;
4263
+ let srcPointer = 8;
4240
4264
  color = img.color(color);
4241
4265
  const screen = img.data;
4242
- for (let i = 0; i < w; ++i) {
4243
- let xxx = x + i;
4244
- if (0 <= xxx && xxx < sw) {
4245
- let dst = xxx + y * sw;
4246
- let src = p;
4247
- let yy = y;
4248
- let end = Math.min(sh, h + y);
4266
+ for (let i = 0; i < width; ++i) {
4267
+ let destX = x + i;
4268
+ if (0 <= destX && destX < destWidth) {
4269
+ let destIndex = destX + y * destWidth;
4270
+ let srcIndex = srcPointer;
4271
+ let destY = y;
4272
+ let destEnd = Math.min(destHeight, height + y);
4249
4273
  if (y < 0) {
4250
- src += ((-y) >> 3);
4251
- yy += ((-y) >> 3) * 8;
4274
+ srcIndex += ((-y) >> 3);
4275
+ destY += ((-y) >> 3) * 8;
4276
+ destIndex += (destY - y) * destWidth;
4252
4277
  }
4253
4278
  let mask = 0x01;
4254
- let v = img2[src++];
4255
- while (yy < end) {
4256
- if (yy >= 0 && (v & mask)) {
4257
- screen[dst] = color;
4279
+ let srcByte = src[srcIndex++];
4280
+ while (destY < destEnd) {
4281
+ if (destY >= 0 && (srcByte & mask)) {
4282
+ screen[destIndex] = color;
4258
4283
  }
4259
4284
  mask <<= 1;
4260
4285
  if (mask == 0x100) {
4261
4286
  mask = 0x01;
4262
- v = img2[src++];
4287
+ srcByte = src[srcIndex++];
4263
4288
  }
4264
- dst += sw;
4265
- yy++;
4289
+ destIndex += destWidth;
4290
+ destY++;
4266
4291
  }
4267
4292
  }
4268
- p += byteH;
4293
+ srcPointer += byteH;
4269
4294
  }
4270
4295
  }
4271
4296
  ImageMethods.drawIcon = drawIcon;
@@ -5108,6 +5133,35 @@ var pxsim;
5108
5133
  settings._list = _list;
5109
5134
  })(settings = pxsim.settings || (pxsim.settings = {}));
5110
5135
  })(pxsim || (pxsim = {}));
5136
+ /// <reference path="../../screen/sim/image.ts" />
5137
+ var pxsim;
5138
+ (function (pxsim) {
5139
+ var ShaderMethods;
5140
+ (function (ShaderMethods) {
5141
+ function _mergeImage(dst, src, xy) {
5142
+ mergeImage(dst, src, pxsim.ImageMethods.XX(xy), pxsim.ImageMethods.YY(xy));
5143
+ }
5144
+ ShaderMethods._mergeImage = _mergeImage;
5145
+ function mergeImage(dst, src, x0, y0) {
5146
+ for (let x = 0; x < src._width; x++) {
5147
+ for (let y = 0; y < src._height; y++) {
5148
+ pxsim.ImageMethods.setPixel(dst, x0 + x, y0 + y, Math.min(pxsim.ImageMethods.getPixel(dst, x0 + x, y0 + y), pxsim.ImageMethods.getPixel(src, x, y)));
5149
+ }
5150
+ }
5151
+ }
5152
+ function _mapImage(dst, src, xy, buf) {
5153
+ mapImage(dst, src, pxsim.ImageMethods.XX(xy), pxsim.ImageMethods.YY(xy), buf);
5154
+ }
5155
+ ShaderMethods._mapImage = _mapImage;
5156
+ function mapImage(dst, src, x0, y0, buf) {
5157
+ for (let x = 0; x < src._width; x++) {
5158
+ for (let y = 0; y < src._height; y++) {
5159
+ pxsim.ImageMethods.setPixel(dst, x0 + x, y0 + y, buf.data[pxsim.ImageMethods.getPixel(dst, x0 + x, y0 + y) + (pxsim.ImageMethods.getPixel(src, x, y) << 4)]);
5160
+ }
5161
+ }
5162
+ }
5163
+ })(ShaderMethods = pxsim.ShaderMethods || (pxsim.ShaderMethods = {}));
5164
+ })(pxsim || (pxsim = {}));
5111
5165
  var pxsim;
5112
5166
  (function (pxsim) {
5113
5167
  class StorageState {