pxt-common-packages 9.5.5 → 9.5.8

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 (55) hide show
  1. package/built/common-sim.d.ts +40 -0
  2. package/built/common-sim.js +93 -1
  3. package/libs/azureiot/built/debug/binary.js +461 -461
  4. package/libs/base/sim/core.ts +1 -1
  5. package/libs/color/built/debug/binary.js +8 -8
  6. package/libs/color-sensor/built/debug/binary.js +8 -8
  7. package/libs/controller/built/debug/binary.js +7659 -7665
  8. package/libs/controller---none/built/debug/binary.js +7638 -7644
  9. package/libs/datalogger/built/debug/binary.js +63 -63
  10. package/libs/edge-connector/built/debug/binary.js +8 -8
  11. package/libs/esp32/built/debug/binary.js +462 -462
  12. package/libs/game/_locales/game-strings.json +1 -0
  13. package/libs/game/built/debug/binary.js +7551 -7557
  14. package/libs/game/docs/reference/sprites/sprite-kind.md +70 -0
  15. package/libs/game/docs/reference/tiles/get-neighboring-location.md +123 -0
  16. package/libs/game/docs/reference/tiles/get-tile-location.md +71 -30
  17. package/libs/game/docs/reference/tiles/get-tiles-by-type.md +66 -32
  18. package/libs/game/docs/reference/tiles/location.md +246 -0
  19. package/libs/game/docs/reference/tiles/place-on-random-tile.md +54 -21
  20. package/libs/game/docs/reference/tiles/place-on-tile.md +88 -0
  21. package/libs/game/docs/reference/tiles/set-current-tilemap.md +90 -0
  22. package/libs/game/docs/reference/tiles/set-tile-at.md +47 -30
  23. package/libs/game/docs/reference/tiles/set-tilemap.md +90 -0
  24. package/libs/game/docs/reference/tiles/set-wall-at.md +67 -68
  25. package/libs/game/docs/reference/tiles/tile-at-location-equals.md +97 -0
  26. package/libs/game/docs/reference/tiles/tile-at-location-is-wall.md +98 -0
  27. package/libs/game/docs/reference/tiles/tilemap.md +145 -0
  28. package/libs/game/hitbox.ts +2 -2
  29. package/libs/game/multiplayer.cpp +25 -0
  30. package/libs/game/multiplayer.ts +24 -0
  31. package/libs/game/pxt.json +3 -1
  32. package/libs/game/scene.ts +1 -0
  33. package/libs/game/sim/multiplayer.ts +132 -0
  34. package/libs/game/sprite.ts +1 -1
  35. package/libs/game/spritekind.ts +1 -0
  36. package/libs/game/tilemap.ts +12 -11
  37. package/libs/lcd/built/debug/binary.js +8 -8
  38. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  39. package/libs/lora/built/debug/binary.js +8 -8
  40. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  41. package/libs/mqtt/built/debug/binary.js +176 -176
  42. package/libs/net/built/debug/binary.js +176 -176
  43. package/libs/net-game/built/debug/binary.js +9339 -9345
  44. package/libs/palette/built/debug/binary.js +7550 -7556
  45. package/libs/pixel/built/debug/binary.js +8 -8
  46. package/libs/power/built/debug/binary.js +8 -8
  47. package/libs/proximity/built/debug/binary.js +8 -8
  48. package/libs/radio/built/debug/binary.js +8 -8
  49. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  50. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  51. package/libs/screen/built/debug/binary.js +50 -50
  52. package/libs/servo/built/debug/binary.js +8 -8
  53. package/libs/sprite-scaling/built/debug/binary.js +7550 -7556
  54. package/libs/storyboard/built/debug/binary.js +7550 -7556
  55. package/package.json +2 -2
@@ -63,6 +63,7 @@ namespace scene {
63
63
  export const RENDER_BACKGROUND_PRIORITY = 60;
64
64
  export const RENDER_SPRITES_PRIORITY = 90;
65
65
  export const RENDER_DIAGNOSTICS_PRIORITY = 150;
66
+ export const MULTIPLAYER_SCREEN_PRIORITY = 190;
66
67
  export const UPDATE_SCREEN_PRIORITY = 200;
67
68
 
68
69
  // default rendering z indices
@@ -0,0 +1,132 @@
1
+ namespace pxsim.multiplayer {
2
+ export function postImage(im: pxsim.RefImage, goal: string) {
3
+ const asBuf = pxsim.image.toBuffer(im);
4
+ getMultiplayerState().send(<MultiplayerImageMessage>{
5
+ content: "Image",
6
+ image: asBuf,
7
+ goal
8
+ });
9
+ }
10
+
11
+ export function getCurrentImage(): pxsim.RefImage {
12
+ return getMultiplayerState().backgroundImage;
13
+ }
14
+
15
+ export function setOrigin(origin: "client" | "server" | undefined) {
16
+ getMultiplayerState().origin = origin;
17
+ }
18
+
19
+ export function getOrigin(): string {
20
+ return getMultiplayerState().origin;
21
+ }
22
+ }
23
+
24
+ namespace pxsim {
25
+ export interface MultiplayerBoard extends EventBusBoard {
26
+ multiplayerState: MultiplayerState;
27
+ }
28
+
29
+ export function getMultiplayerState() {
30
+ return (board() as EventBusBoard as MultiplayerBoard).multiplayerState;
31
+ }
32
+
33
+ export interface SimulatorMultiplayerMessage extends SimulatorBroadcastMessage {
34
+ broadcast: true
35
+ type: "multiplayer";
36
+ content: string;
37
+ origin?: "server" | "client";
38
+ clientNumber?: number;
39
+ id?: number;
40
+ }
41
+
42
+ export interface MultiplayerImageMessage extends SimulatorMultiplayerMessage {
43
+ content: "Image";
44
+ goal: string; // goal of message; e.g. "broadcast-screen"
45
+ image: RefImage;
46
+ }
47
+
48
+ export interface MultiplayerButtonEvent extends SimulatorMultiplayerMessage {
49
+ content: "Button";
50
+ button: number; // pxsim.Key.A, ...
51
+ state: "Pressed" | "Released" | "Held";
52
+ }
53
+
54
+ export class MultiplayerState {
55
+ lastMessageId: number;
56
+ origin: string;
57
+ backgroundImage: RefImage;
58
+
59
+ constructor() {
60
+ this.lastMessageId = 0;
61
+ }
62
+
63
+ send(msg: SimulatorMultiplayerMessage) {
64
+ Runtime.postMessage(<SimulatorMultiplayerMessage>{
65
+ ...msg,
66
+ broadcast: true,
67
+ toParentIFrameOnly: true,
68
+ type: "multiplayer",
69
+ origin: this.origin,
70
+ id: this.lastMessageId++
71
+ });
72
+ }
73
+
74
+ init(origin: string) {
75
+ this.origin = origin;
76
+ runtime.board.addMessageListener(msg => this.messageHandler(msg));
77
+ setInterval(() => {
78
+ if (this.origin === "server") {
79
+ const b = board() as ScreenBoard;
80
+ const screenState = b && b.screenState;
81
+ const lastImage = screenState && screenState.lastImage;
82
+ lastImage && pxsim.multiplayer.postImage(lastImage, "broadcast-screen");
83
+ }
84
+ }, 50);
85
+ }
86
+
87
+ setButton(key: number, isPressed: boolean) {
88
+ if (this.origin === "client") {
89
+ this.send(<pxsim.MultiplayerButtonEvent>{
90
+ content: "Button",
91
+ button: key,
92
+ state: isPressed ? "Pressed" : "Released"
93
+ })
94
+ }
95
+ }
96
+
97
+ protected messageHandler(msg: SimulatorMessage) {
98
+ if (!isMultiplayerMessage(msg)) {
99
+ return;
100
+ }
101
+
102
+ if (isImageMessage(msg)) {
103
+ if (this.origin === "client") {
104
+ // HACK: peer js can convert Uint8Array into ArrayBuffer when transmitting; fix this.
105
+ if (!ArrayBuffer.isView(msg.image.data)) {
106
+ msg.image.data = new Uint8Array(msg.image.data);
107
+ }
108
+ this.backgroundImage = pxsim.image.ofBuffer(msg.image);
109
+ }
110
+ } else if (isButtonMessage(msg)) {
111
+ if (this.origin === "server") {
112
+ (board() as any).setButton(
113
+ msg.button + (7 * (msg.clientNumber || 1)), // + 7 to make it player 2 controls,
114
+ msg.state === "Pressed" || msg.state === "Held"
115
+ );
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ function isMultiplayerMessage(msg: SimulatorMessage): msg is SimulatorMultiplayerMessage {
122
+ return msg && msg.type === "multiplayer";
123
+ }
124
+
125
+ function isImageMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerImageMessage {
126
+ return msg && msg.content === "Image";
127
+ }
128
+
129
+ function isButtonMessage(msg: SimulatorMultiplayerMessage): msg is MultiplayerButtonEvent {
130
+ return msg && msg.content === "Button";
131
+ }
132
+ }
@@ -319,7 +319,7 @@ class Sprite extends sprites.BaseSprite {
319
319
  */
320
320
  //% group="Image"
321
321
  //% blockId=spriteimage block="%sprite(mySprite) image"
322
- //% weight=8
322
+ //% weight=8 help=sprites/sprite/image
323
323
  get image(): Image {
324
324
  return this._image;
325
325
  }
@@ -5,6 +5,7 @@ namespace sprites {
5
5
  //% shim=KIND_GET
6
6
  //% blockId=spritekind block="$kind"
7
7
  //% kindNamespace=SpriteKind kindMemberName=kind kindPromptHint="e.g. Coin, Fireball, Asteroid..."
8
+ //% help=sprites/sprite-kind
8
9
  export function _spriteKind(kind: number): number {
9
10
  return kind;
10
11
  }
@@ -596,7 +596,7 @@ namespace tiles {
596
596
  //% tilemap.fieldOptions.filter="tile"
597
597
  //% tilemap.fieldOptions.taggedTemplate="tilemap"
598
598
  //% blockNamespace="scene" duplicateShadowOnDrag
599
- //% help=scene/set-tilemap
599
+ //% help=tiles/set-tilemap
600
600
  //% deprecated=1
601
601
  export function setTilemap(tilemap: TileMapData) {
602
602
  setCurrentTilemap(tilemap);
@@ -611,7 +611,7 @@ namespace tiles {
611
611
  //% weight=201 blockGap=8
612
612
  //% tilemap.shadow=tiles_tilemap_editor
613
613
  //% blockNamespace="scene" group="Tilemaps" duplicateShadowOnDrag
614
- //% help=tiles/set-tile-map
614
+ //% help=tiles/set-current-tilemap
615
615
  export function setCurrentTilemap(tilemap: TileMapData) {
616
616
  scene.setTileMapLevel(tilemap);
617
617
  }
@@ -625,7 +625,7 @@ namespace tiles {
625
625
  //% tile.shadow=tileset_tile_picker
626
626
  //% tile.decompileIndirectFixedInstances=true
627
627
  //% blockNamespace="scene" group="Tilemap Operations" blockGap=8
628
- //% help=scene/set-tile-at
628
+ //% help=tiles/set-tile-at
629
629
  //% weight=70
630
630
  export function setTileAt(loc: Location, tile: Image): void {
631
631
  const scene = game.currentScene();
@@ -643,7 +643,7 @@ namespace tiles {
643
643
  //% blockId=mapsetwallat block="set wall $on at $loc"
644
644
  //% on.shadow=toggleOnOff loc.shadow=mapgettile
645
645
  //% blockNamespace="scene" group="Tilemap Operations"
646
- //% help=scene/set-wall-at
646
+ //% help=tiles/set-wall-at
647
647
  //% weight=60
648
648
  export function setWallAt(loc: Location, on: boolean): void {
649
649
  const scene = game.currentScene();
@@ -660,7 +660,7 @@ namespace tiles {
660
660
  //% blockId=mapgettile block="tilemap col $col row $row"
661
661
  //% blockNamespace="scene" group="Locations"
662
662
  //% weight=100 blockGap=8
663
- //% help=scene/get-tile-location
663
+ //% help=tiles/get-tile-location
664
664
  export function getTileLocation(col: number, row: number): Location {
665
665
  const scene = game.currentScene();
666
666
  if (col == undefined || row == undefined || !scene.tileMap) return null;
@@ -697,7 +697,7 @@ namespace tiles {
697
697
  //% location.shadow=mapgettile
698
698
  //% tile.shadow=tileset_tile_picker tile.decompileIndirectFixedInstances=true
699
699
  //% blockNamespace="scene" group="Locations" blockGap=8
700
- //% weight=40 help=scene/tile-at-location-equals
700
+ //% weight=40 help=tiles/tile-at-location-equals
701
701
  export function tileAtLocationEquals(location: Location, tile: Image): boolean {
702
702
  const scene = game.currentScene();
703
703
  if (!location || !tile || !scene.tileMap) return false;
@@ -713,7 +713,7 @@ namespace tiles {
713
713
  //% block="tile at $location is wall"
714
714
  //% location.shadow=mapgettile
715
715
  //% blockNamespace="scene" group="Locations" blockGap=8
716
- //% weight=30 help=scene/tile-at-location-is-wall
716
+ //% weight=30 help=tiles/tile-at-location-is-wall
717
717
  export function tileAtLocationIsWall(location: Location): boolean {
718
718
  if (!location || !location.tileMap) return false;
719
719
  return location.isWall();
@@ -727,7 +727,7 @@ namespace tiles {
727
727
  //% blockId=tiles_image_at_location
728
728
  //% block="tile image at $location"
729
729
  //% location.shadow=mapgettile
730
- //% weight=0 help=scene/tile-image-at-location
730
+ //% weight=0 help=tiles/tile-image-at-location
731
731
  //% blockNamespace="scene" group="Locations"
732
732
  export function tileImageAtLocation(location: Location): Image {
733
733
  const scene = game.currentScene();
@@ -743,7 +743,7 @@ namespace tiles {
743
743
  //% blockId=mapplaceontile block="place $sprite=variables_get(mySprite) on top of $loc"
744
744
  //% loc.shadow=mapgettile
745
745
  //% blockNamespace="scene" group="Tilemap Operations" blockGap=8
746
- //% help=scene/place-on-tile
746
+ //% help=tiles/place-on-tile
747
747
  //% weight=100
748
748
  export function placeOnTile(sprite: Sprite, loc: Location): void {
749
749
  if (!sprite || !loc || !loc.tileMap) return;
@@ -759,7 +759,7 @@ namespace tiles {
759
759
  //% tile.shadow=tileset_tile_picker
760
760
  //% tile.decompileIndirectFixedInstances=true
761
761
  //% blockNamespace="scene" group="Tilemap Operations"
762
- //% help=scene/place-on-random-tile
762
+ //% help=tiles/place-on-random-tile
763
763
  //% weight=90
764
764
  export function placeOnRandomTile(sprite: Sprite, tile: Image): void {
765
765
  if (!sprite || !game.currentScene().tileMap) return;
@@ -776,7 +776,7 @@ namespace tiles {
776
776
  //% tile.shadow=tileset_tile_picker
777
777
  //% tile.decompileIndirectFixedInstances=true
778
778
  //% blockNamespace="scene" group="Locations" blockGap=8
779
- //% help=scene/get-tiles-by-type
779
+ //% help=tiles/get-tiles-by-type
780
780
  //% weight=10
781
781
  export function getTilesByType(tile: Image): Location[] {
782
782
  const scene = game.currentScene();
@@ -809,6 +809,7 @@ namespace tiles {
809
809
  //% tilemap.fieldOptions.filter="tile"
810
810
  //% tilemap.fieldOptions.taggedTemplate="tilemap"
811
811
  //% blockNamespace="scene" group="Tilemaps" duplicateShadowOnDrag
812
+ //% help=tiles/tilemap
812
813
  export function _tilemapEditor(tilemap: TileMapData): TileMapData {
813
814
  return tilemap;
814
815
  }
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P48928(s) {
59
+ function _main___P48096(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___49171 = (undefined);
70
- globals._pollEventQueue___49184 = (undefined);
69
+ globals._intervals___48339 = (undefined);
70
+ globals._pollEventQueue___48352 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P48928.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P48928.continuations = [ ]
75
+ _main___P48096.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"characterlcd.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P48096.continuations = [ ]
77
77
 
78
- function _main___P48928_mk(s) {
78
+ function _main___P48096_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P48928, depth: s.depth + 1,
81
+ parent: s, fn: _main___P48096, 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___P48928_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P48928
91
+ return _main___P48096
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___P97400(s) {
59
+ function _main___P96578(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___97643 = (undefined);
70
- globals._pollEventQueue___97656 = (undefined);
69
+ globals._intervals___96821 = (undefined);
70
+ globals._pollEventQueue___96834 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P97400.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P97400.continuations = [ ]
75
+ _main___P96578.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tsl2591.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P96578.continuations = [ ]
77
77
 
78
- function _main___P97400_mk(s) {
78
+ function _main___P96578_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P97400, depth: s.depth + 1,
81
+ parent: s, fn: _main___P96578, 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___P97400_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P97400
91
+ return _main___P96578
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___P60230(s) {
59
+ function _main___P59398(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___60473 = (undefined);
70
- globals._pollEventQueue___60486 = (undefined);
69
+ globals._intervals___59641 = (undefined);
70
+ globals._pollEventQueue___59654 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P60230.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P60230.continuations = [ ]
75
+ _main___P59398.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"lora.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P59398.continuations = [ ]
77
77
 
78
- function _main___P60230_mk(s) {
78
+ function _main___P59398_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P60230, depth: s.depth + 1,
81
+ parent: s, fn: _main___P59398, 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___P60230_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P60230
91
+ return _main___P59398
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___P188726(s) {
59
+ function _main___P187087(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___188969 = (undefined);
70
- globals._pollEventQueue___188982 = (undefined);
69
+ globals._intervals___187330 = (undefined);
70
+ globals._pollEventQueue___187343 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P188726.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P188726.continuations = [ ]
75
+ _main___P187087.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"keypad.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P187087.continuations = [ ]
77
77
 
78
- function _main___P188726_mk(s) {
78
+ function _main___P187087_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P188726, depth: s.depth + 1,
81
+ parent: s, fn: _main___P187087, 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___P188726_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P188726
91
+ return _main___P187087
92
92
  })