@@ -582,9 +582,6 @@ exports.default = new (0, _phaserDefault.default).Game({
582582 autoCenter: (0, _phaserDefault.default).Scale.CENTER_BOTH
583583 }
584584});
585- // Trigger Keyboard on mobile devices. The function is defined in the "index.html" file.
586- // @ts-ignore
587- triggerKeyboard();
588585
589586},{"phaser":"9U0wC","./scenes/Preloader":"gPcEg","phaser3-rex-plugins/templates/ui/ui-plugin.js":"kCKu7","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3","~/scenes/MainScene":"7hl19","~/scenes/End":"gpPKb","../../../library/designsystem/consts/ColorKeys":"9lnJX"}],"9U0wC":[function(require,module,exports) {
590587var process = require("b4fd6328bb67843a");
@@ -239831,7 +239828,7 @@ class InputField {
239831239828 * Every time a character is pressed, add it to the text.
239832239829 * @private
239833239830 */ _initKeyboardListener() {
239834- this.mainScene.input.keyboard.on("keydown", (event)=>{
239831+ const listenerFunction = (event)=>{
239835239832 // Check if the key is a letter or a german umlaut
239836239833 if (event.key.length === 1 && event.key.match(/^[a-zA-ZäöüÄÖÜß]$/)) {
239837239834 // Check if the last letter is a "_". If yes, remove it.
@@ -239844,7 +239841,18 @@ class InputField {
239844239841 this.text.setText(this.text.text.slice(0, -1));
239845239842 this._reactToInputChange();
239846239843 } else if (event.key === "Enter" && this.text.text.length > 0 && this.mainScene.getHand().hasLetter(this.text.text.charAt(0).toUpperCase())) this._handleEnter();
239844+ };
239845+ // For mobile devices, we need to listen to the input from a hidden input field
239846+ this.hiddenInputElement = document.getElementById("hiddenInput");
239847+ if (!this.hiddenInputElement) throw new Error("Hidden input element with id 'hiddenInput' not found in the DOM");
239848+ this.hiddenInputElement.addEventListener("keydown", listenerFunction);
239849+ // Workaround: In case we click away from canvas, we need to focus the hidden input element again
239850+ // If user clicks on the canvas, focus the hidden input element
239851+ this.mainScene.input.on("pointerdown", ()=>{
239852+ this.hiddenInputElement.focus();
239847239853 });
239854+ // Autofocus the hidden input element when the scene is created
239855+ this.hiddenInputElement.focus();
239848239856 }
239849239857 _reactToInputChange() {
239850239858 const hand = this.mainScene.getHand();
@@ -239864,6 +239872,7 @@ class InputField {
239864239872 return (0, _tslib.__awaiter)(this, void 0, void 0, function*() {
239865239873 const answer = this.text.text.replace(/_/g, ""); // Remove the blinking cursor
239866239874 this.text.setText(""); // Clear the text
239875+ this.hiddenInputElement.value = "";
239867239876 yield this.mainScene.getGameMaster().validateAnswer(answer);
239868239877 });
239869239878 }
0 commit comments