pxt-arcade 2.0.17 → 2.0.20

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.
package/built/editor.js CHANGED
@@ -306,6 +306,27 @@ var pxt;
306
306
  });
307
307
  }
308
308
  }
309
+ // Added the "use system keyboard" options to the ask for number and ask for string blocks
310
+ if (pxt.semver.strcmp(pkgTargetVersion || "0.0.0", "2.0.18") < 0) {
311
+ const allPromptBlocks = pxt.U.toArray(dom.querySelectorAll("block[type=gameaskforstring]"))
312
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=gameaskforstring]")))
313
+ .concat(pxt.U.toArray(dom.querySelectorAll("block[type=gameaskfornumber]")))
314
+ .concat(pxt.U.toArray(dom.querySelectorAll("shadow[type=gameaskfornumber]")));
315
+ for (const block of allPromptBlocks) {
316
+ if (!getChildNode(block, "value", "name", "useSystemKeyboard")) {
317
+ const value = document.createElement("value");
318
+ value.setAttribute("name", "useSystemKeyboard");
319
+ const shadow = document.createElement("shadow");
320
+ shadow.setAttribute("type", "logic_boolean");
321
+ const field = document.createElement("field");
322
+ field.setAttribute("name", "BOOL");
323
+ field.textContent = "FALSE";
324
+ shadow.appendChild(field);
325
+ value.appendChild(shadow);
326
+ block.appendChild(value);
327
+ }
328
+ }
329
+ }
309
330
  }
310
331
  function swapFieldIfNotMatching(eventRoot, fieldAName, fieldBName, fieldAShouldStartWith) {
311
332
  const fieldA = eventRoot.querySelector(`field[name=${fieldAName}]`);
package/built/sim.js CHANGED
@@ -145,6 +145,7 @@ var pxsim;
145
145
  }
146
146
  const old = ctrl.state[key] || false;
147
147
  if (old != pressed) {
148
+ pxsim.Keyboard.cancelSystemKeyboard();
148
149
  ctrl.state[key] = pressed;
149
150
  pxsim.board().setButton(key + (7 * (ctrl.player - 1)), pressed);
150
151
  }
@@ -155,6 +156,7 @@ var pxsim;
155
156
  let forcedUpdateLoop;
156
157
  let isFirstRunSafari = true;
157
158
  let themeFromQueryParameter = false;
159
+ pxsim.simButtonsHidden = false;
158
160
  window.addEventListener("DOMContentLoaded", () => {
159
161
  const searchParams = new URL(window.location.toString()).searchParams;
160
162
  const setThemeIfDefined = (themeType) => {
@@ -175,7 +177,8 @@ var pxsim;
175
177
  pxsim.theme.applySkin(skin);
176
178
  }
177
179
  registerPointerEvents(!!searchParams.get("pointer-events"));
178
- if (!!searchParams.get("hideSimButtons"))
180
+ pxsim.simButtonsHidden = !!searchParams.get("hideSimButtons");
181
+ if (pxsim.simButtonsHidden)
179
182
  hideSimButtons();
180
183
  if (!!searchParams.get("noExtraPadding"))
181
184
  noExtraPadding();
@@ -417,6 +420,7 @@ var pxsim;
417
420
  super();
418
421
  this.startTime = Date.now();
419
422
  this.isPaused = false;
423
+ this.disableKeyEvents = false;
420
424
  this.lightState = {};
421
425
  this.screenState = new pxsim.ScreenState(null);
422
426
  this.audioState = new pxsim.AudioState();
@@ -506,6 +510,9 @@ var pxsim;
506
510
  return undefined;
507
511
  }
508
512
  setKey(which, isPressed, e) {
513
+ if (this.disableKeyEvents) {
514
+ return;
515
+ }
509
516
  if (!isMultiplayerSession() && e instanceof KeyboardEvent) {
510
517
  pxsim.browserEvents.onKeyboardEvent(e, isPressed);
511
518
  }
@@ -644,6 +651,10 @@ var pxsim;
644
651
  state = this.lightState[pinId] = new pxsim.CommonNeoPixelState();
645
652
  return state;
646
653
  }
654
+ kill() {
655
+ super.kill();
656
+ pxsim.Keyboard.cancelTextPrompt();
657
+ }
647
658
  }
648
659
  pxsim.Board = Board;
649
660
  function indicateFocus(hasFocus) {
@@ -653,6 +664,9 @@ var pxsim;
653
664
  const b = board();
654
665
  if (b) {
655
666
  b.gameplayer.indicateFocus(hasFocus);
667
+ if (hasFocus && b.disableKeyEvents) {
668
+ pxsim.Keyboard.focusTextInput();
669
+ }
656
670
  }
657
671
  }
658
672
  pxsim.indicateFocus = indicateFocus;
@@ -718,6 +732,126 @@ function isSafari() {
718
732
  })(ButtonMethods = pxsim.ButtonMethods || (pxsim.ButtonMethods = {}));
719
733
  })(pxsim || (pxsim = {}));
720
734
  var pxsim;
735
+ (function (pxsim) {
736
+ var Keyboard;
737
+ (function (Keyboard) {
738
+ let KeyboardEvent;
739
+ (function (KeyboardEvent) {
740
+ KeyboardEvent[KeyboardEvent["Change"] = 7339] = "Change";
741
+ KeyboardEvent[KeyboardEvent["Enter"] = 7340] = "Enter";
742
+ KeyboardEvent[KeyboardEvent["Cancel"] = 7341] = "Cancel";
743
+ })(KeyboardEvent = Keyboard.KeyboardEvent || (Keyboard.KeyboardEvent = {}));
744
+ let input;
745
+ let onClick = (e) => {
746
+ if (input)
747
+ input.focus();
748
+ e.stopPropagation();
749
+ e.preventDefault();
750
+ };
751
+ function validateNumberInput() {
752
+ if (!input)
753
+ return;
754
+ let cleaned = "";
755
+ for (let i = 0; i < input.value.length; i++) {
756
+ const current = input.value.charAt(i);
757
+ if (current === "-") {
758
+ if (cleaned.length !== 0) {
759
+ continue;
760
+ }
761
+ }
762
+ else if (current === ".") {
763
+ if (cleaned.indexOf(".") !== -1) {
764
+ continue;
765
+ }
766
+ }
767
+ else if (!/[0-9]/.test(current)) {
768
+ continue;
769
+ }
770
+ cleaned += current;
771
+ }
772
+ input.value = cleaned;
773
+ }
774
+ function promptForText(maxLength, numberOnly) {
775
+ if (input)
776
+ input.remove();
777
+ pxsim.board().disableKeyEvents = true;
778
+ input = document.createElement("input");
779
+ input.type = "text";
780
+ input.maxLength = maxLength;
781
+ document.body.appendChild(input);
782
+ input.addEventListener("change", e => {
783
+ if (numberOnly) {
784
+ validateNumberInput();
785
+ }
786
+ pxsim.board().bus.queue(KeyboardEvent.Change, 0);
787
+ });
788
+ input.addEventListener("keyup", e => {
789
+ if (e.key === "Enter" || e.key === "Escape") {
790
+ pxsim.board().bus.queue(KeyboardEvent.Enter, 0);
791
+ cancelTextPrompt();
792
+ }
793
+ else if (numberOnly) {
794
+ validateNumberInput();
795
+ }
796
+ pxsim.board().bus.queue(KeyboardEvent.Change, 0);
797
+ });
798
+ input.addEventListener("keydown", e => {
799
+ pxsim.board().bus.queue(KeyboardEvent.Change, 0);
800
+ if (numberOnly) {
801
+ validateNumberInput();
802
+ }
803
+ });
804
+ document.addEventListener("pointerdown", onClick);
805
+ document.addEventListener("click", onClick);
806
+ input.style.opacity = "0";
807
+ input.focus();
808
+ }
809
+ Keyboard.promptForText = promptForText;
810
+ function cancelTextPrompt() {
811
+ if (input)
812
+ input.remove();
813
+ pxsim.board().disableKeyEvents = false;
814
+ document.removeEventListener("pointerdown", onClick);
815
+ document.removeEventListener("click", onClick);
816
+ }
817
+ Keyboard.cancelTextPrompt = cancelTextPrompt;
818
+ function cancelSystemKeyboard() {
819
+ if (input) {
820
+ cancelTextPrompt();
821
+ pxsim.board().bus.queue(KeyboardEvent.Cancel, 0);
822
+ }
823
+ }
824
+ Keyboard.cancelSystemKeyboard = cancelSystemKeyboard;
825
+ function getTextPromptString() {
826
+ if (input)
827
+ return input.value;
828
+ return "";
829
+ }
830
+ Keyboard.getTextPromptString = getTextPromptString;
831
+ function focusTextInput() {
832
+ if (input)
833
+ input.focus();
834
+ }
835
+ Keyboard.focusTextInput = focusTextInput;
836
+ function getTextPromptSelectionStart() {
837
+ if (input)
838
+ return input.selectionStart;
839
+ return 0;
840
+ }
841
+ Keyboard.getTextPromptSelectionStart = getTextPromptSelectionStart;
842
+ function getTextPromptSelectionEnd() {
843
+ if (input)
844
+ return input.selectionEnd;
845
+ return 0;
846
+ }
847
+ Keyboard.getTextPromptSelectionEnd = getTextPromptSelectionEnd;
848
+ function isSystemKeyboardSupported() {
849
+ return !pxsim.board().multiplayerState.origin && !pxsim.simButtonsHidden;
850
+ }
851
+ Keyboard.isSystemKeyboardSupported = isSystemKeyboardSupported;
852
+ })(Keyboard = pxsim.Keyboard || (pxsim.Keyboard = {}));
853
+ })(pxsim || (pxsim = {}));
854
+ var pxsim;
721
855
  (function (pxsim) {
722
856
  var theme;
723
857
  (function (theme_1) {
@@ -1043,6 +1177,7 @@ var pxsim;
1043
1177
  this.bindEvent(surface, "pointerdown", (ev) => {
1044
1178
  this.updateButtonGesture(ev.clientX, ev.clientY);
1045
1179
  inGesture = true;
1180
+ pxsim.Keyboard.cancelSystemKeyboard();
1046
1181
  });
1047
1182
  this.bindEvent(surface, "pointermove", (ev) => {
1048
1183
  if (inGesture)
@@ -1146,6 +1281,7 @@ var pxsim;
1146
1281
  visuals.pressButton(pxsim.Key.Menu);
1147
1282
  visuals.releaseButton(pxsim.Key.Menu);
1148
1283
  pxsim.indicateFocus(true);
1284
+ pxsim.Keyboard.cancelSystemKeyboard();
1149
1285
  };
1150
1286
  }
1151
1287
  if (this.reset) {
@@ -1340,6 +1476,7 @@ var pxsim;
1340
1476
  this.bindEvent(surface, "pointerdown", (ev) => {
1341
1477
  this.updateJoystickDrag(ev.clientX, ev.clientY);
1342
1478
  inGesture = true;
1479
+ pxsim.Keyboard.cancelSystemKeyboard();
1343
1480
  });
1344
1481
  this.bindEvent(surface, "pointermove", (ev) => {
1345
1482
  if (inGesture)