pxt-arcade 1.12.14 → 1.12.17

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.
@@ -818,6 +818,11 @@ declare namespace pxsim {
818
818
  instruction: "playinstructions" | "muteallchannels";
819
819
  soundbuf?: Uint8Array;
820
820
  }
821
+ interface MultiplayerConnectionEvent extends SimulatorMultiplayerMessage {
822
+ content: "Connection";
823
+ slot: number;
824
+ connected: boolean;
825
+ }
821
826
  class MultiplayerState {
822
827
  lastMessageId: number;
823
828
  origin: string;
@@ -826,6 +831,7 @@ declare namespace pxsim {
826
831
  send(msg: SimulatorMultiplayerMessage): void;
827
832
  init(origin: string): void;
828
833
  setButton(key: number, isPressed: boolean): void;
834
+ registerConnectionState(player: number, connected: boolean): void;
829
835
  protected messageHandler(msg: SimulatorMessage): void;
830
836
  }
831
837
  }
@@ -2554,11 +2554,13 @@ var pxsim;
2554
2554
  }
2555
2555
  multiplayer.postImage = postImage;
2556
2556
  function postIcon(iconType, slot, im) {
2557
- if (im._width * im._height > 64 * 64) {
2557
+ if (im && (im._width * im._height > 64 * 64)) {
2558
2558
  // setting 64x64 as max size for icon for now
2559
2559
  return;
2560
2560
  }
2561
- const asBuf = pxsim.image.toBuffer(im);
2561
+ // treat empty icon as undefined
2562
+ const asBuf = (im && im.data.some(pixel => pixel != 0))
2563
+ ? pxsim.image.toBuffer(im) : undefined;
2562
2564
  const sb = pxsim.board();
2563
2565
  const screenState = sb && sb.screenState;
2564
2566
  pxsim.getMultiplayerState().send({
@@ -2594,6 +2596,8 @@ var pxsim;
2594
2596
  IconType[IconType["Player"] = 0] = "Player";
2595
2597
  IconType[IconType["Reaction"] = 1] = "Reaction";
2596
2598
  })(IconType = pxsim.IconType || (pxsim.IconType = {}));
2599
+ const MULTIPLAYER_PLAYER_JOINED_ID = 3241;
2600
+ const MULTIPLAYER_PLAYER_LEFT_ID = 3242;
2597
2601
  class MultiplayerState {
2598
2602
  constructor() {
2599
2603
  this.lastMessageId = 0;
@@ -2626,6 +2630,11 @@ var pxsim;
2626
2630
  });
2627
2631
  }
2628
2632
  }
2633
+ registerConnectionState(player, connected) {
2634
+ const evId = connected ? MULTIPLAYER_PLAYER_JOINED_ID : MULTIPLAYER_PLAYER_LEFT_ID;
2635
+ const b = pxsim.board();
2636
+ b.bus.queue(evId, player);
2637
+ }
2629
2638
  messageHandler(msg) {
2630
2639
  if (!isMultiplayerMessage(msg)) {
2631
2640
  return;
@@ -2659,6 +2668,11 @@ var pxsim;
2659
2668
  }
2660
2669
  }
2661
2670
  }
2671
+ else if (isConnectionMessage(msg)) {
2672
+ if (this.origin === "server") {
2673
+ this.registerConnectionState(msg.slot, msg.connected);
2674
+ }
2675
+ }
2662
2676
  }
2663
2677
  }
2664
2678
  pxsim.MultiplayerState = MultiplayerState;
@@ -2674,6 +2688,9 @@ var pxsim;
2674
2688
  function isAudioMessage(msg) {
2675
2689
  return msg && msg.content === "Audio";
2676
2690
  }
2691
+ function isConnectionMessage(msg) {
2692
+ return msg && msg.content === "Connection";
2693
+ }
2677
2694
  })(pxsim || (pxsim = {}));
2678
2695
  var pxsim;
2679
2696
  (function (pxsim) {
package/built/sim.js CHANGED
@@ -2868,11 +2868,13 @@ var pxsim;
2868
2868
  }
2869
2869
  multiplayer.postImage = postImage;
2870
2870
  function postIcon(iconType, slot, im) {
2871
- if (im._width * im._height > 64 * 64) {
2871
+ if (im && (im._width * im._height > 64 * 64)) {
2872
2872
  // setting 64x64 as max size for icon for now
2873
2873
  return;
2874
2874
  }
2875
- const asBuf = pxsim.image.toBuffer(im);
2875
+ // treat empty icon as undefined
2876
+ const asBuf = (im && im.data.some(pixel => pixel != 0))
2877
+ ? pxsim.image.toBuffer(im) : undefined;
2876
2878
  const sb = pxsim.board();
2877
2879
  const screenState = sb && sb.screenState;
2878
2880
  pxsim.getMultiplayerState().send({
@@ -2908,6 +2910,8 @@ var pxsim;
2908
2910
  IconType[IconType["Player"] = 0] = "Player";
2909
2911
  IconType[IconType["Reaction"] = 1] = "Reaction";
2910
2912
  })(IconType = pxsim.IconType || (pxsim.IconType = {}));
2913
+ const MULTIPLAYER_PLAYER_JOINED_ID = 3241;
2914
+ const MULTIPLAYER_PLAYER_LEFT_ID = 3242;
2911
2915
  class MultiplayerState {
2912
2916
  constructor() {
2913
2917
  this.lastMessageId = 0;
@@ -2940,6 +2944,11 @@ var pxsim;
2940
2944
  });
2941
2945
  }
2942
2946
  }
2947
+ registerConnectionState(player, connected) {
2948
+ const evId = connected ? MULTIPLAYER_PLAYER_JOINED_ID : MULTIPLAYER_PLAYER_LEFT_ID;
2949
+ const b = pxsim.board();
2950
+ b.bus.queue(evId, player);
2951
+ }
2943
2952
  messageHandler(msg) {
2944
2953
  if (!isMultiplayerMessage(msg)) {
2945
2954
  return;
@@ -2973,6 +2982,11 @@ var pxsim;
2973
2982
  }
2974
2983
  }
2975
2984
  }
2985
+ else if (isConnectionMessage(msg)) {
2986
+ if (this.origin === "server") {
2987
+ this.registerConnectionState(msg.slot, msg.connected);
2988
+ }
2989
+ }
2976
2990
  }
2977
2991
  }
2978
2992
  pxsim.MultiplayerState = MultiplayerState;
@@ -2988,6 +3002,9 @@ var pxsim;
2988
3002
  function isAudioMessage(msg) {
2989
3003
  return msg && msg.content === "Audio";
2990
3004
  }
3005
+ function isConnectionMessage(msg) {
3006
+ return msg && msg.content === "Connection";
3007
+ }
2991
3008
  })(pxsim || (pxsim = {}));
2992
3009
  var pxsim;
2993
3010
  (function (pxsim) {