From 633bdfcaffb6a6dc746a3105cc35c61015a8ac8c Mon Sep 17 00:00:00 2001 From: PizZaKatZe Date: Wed, 7 Apr 2021 12:42:56 +0200 Subject: [PATCH] Always enable virtual joystick Keeps 'toggle fullscreen' as a separate game setting. --- front/dist/resources/html/gameMenu.html | 2 +- front/src/Connexion/LocalUserStore.ts | 10 +++++----- front/src/Phaser/Game/GameScene.ts | 17 ++++++----------- front/src/Phaser/Menu/MenuScene.ts | 12 +++--------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/front/dist/resources/html/gameMenu.html b/front/dist/resources/html/gameMenu.html index fa46090a..ce740ec5 100644 --- a/front/dist/resources/html/gameMenu.html +++ b/front/dist/resources/html/gameMenu.html @@ -37,7 +37,7 @@
- +
diff --git a/front/src/Connexion/LocalUserStore.ts b/front/src/Connexion/LocalUserStore.ts index 11977f7a..ace7b17e 100644 --- a/front/src/Connexion/LocalUserStore.ts +++ b/front/src/Connexion/LocalUserStore.ts @@ -10,7 +10,7 @@ const videoQualityKey = 'videoQuality'; const audioPlayerVolumeKey = 'audioVolume'; const audioPlayerMuteKey = 'audioMute'; const helpCameraSettingsShown = 'helpCameraSettingsShown'; -const joystickKey = 'showJoystick'; +const fullscreenKey = 'fullscreen'; class LocalUserStore { saveUser(localUser: LocalUser) { @@ -102,11 +102,11 @@ class LocalUserStore { return localStorage.getItem(helpCameraSettingsShown) === '1'; } - setJoystick(value: boolean): void { - localStorage.setItem(joystickKey, value.toString()); + setFullscreen(value: boolean): void { + localStorage.setItem(fullscreenKey, value.toString()); } - getJoystick(): boolean { - return localStorage.getItem(joystickKey) === 'true'; + getFullscreen(): boolean { + return localStorage.getItem(fullscreenKey) === 'true'; } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 428d9c0d..294174a2 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -188,16 +188,6 @@ export class GameScene extends ResizableScene implements CenterListener { this.connectionAnswerPromise = new Promise((resolve, reject): void => { this.connectionAnswerPromiseResolve = resolve; }) - const joystickVisible = localUserStore.getJoystick(); - if (joystickVisible) { - const canvas = document.querySelector('canvas') - canvas?.addEventListener('click', () => { - const body = document.querySelector('body') - body?.requestFullscreen() - }, { - once: true - }) - } } //hook preload scene @@ -423,7 +413,7 @@ export class GameScene extends ResizableScene implements CenterListener { enable: true, dir: "8dir", }); - this.virtualJoystick.visible = localUserStore.getJoystick() + this.virtualJoystick.visible = true; //create input to move mediaManager.setUserInputManager(this.userInputManager); this.userInputManager = new UserInputManager(this, this.virtualJoystick); @@ -434,6 +424,11 @@ export class GameScene extends ResizableScene implements CenterListener { this.virtualJoystick.x = pointer.x; this.virtualJoystick.y = pointer.y; }); + + if (localUserStore.getFullscreen()) { + document.querySelector('body')?.requestFullscreen(); + } + //notify game manager can to create currentUser in map this.createCurrentPlayer(); this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted diff --git a/front/src/Phaser/Menu/MenuScene.ts b/front/src/Phaser/Menu/MenuScene.ts index cdbe13f5..b42b575f 100644 --- a/front/src/Phaser/Menu/MenuScene.ts +++ b/front/src/Phaser/Menu/MenuScene.ts @@ -291,8 +291,8 @@ export class MenuScene extends Phaser.Scene { case 'editGameSettingsButton': this.openGameSettingsMenu(); break; - case 'showJoystick': - this.showJoystick(); + case 'toggleFullscreen': + this.toggleFullscreen(); break; case 'adminConsoleButton': gameManager.getCurrentGameScene(this).ConsoleGlobalMessageManager.activeMessageConsole(); @@ -332,13 +332,7 @@ export class MenuScene extends Phaser.Scene { this.gameReportElement.close(); } - private showJoystick() { - const gameScene = gameManager.getCurrentGameScene(this) - if (gameScene?.virtualJoystick) { - const joystickVisible = !gameScene.virtualJoystick.visible - gameScene.virtualJoystick.visible = joystickVisible - localUserStore.setJoystick(joystickVisible) - } + private toggleFullscreen() { const body = document.querySelector('body') if (body) { if (document.fullscreenElement ?? document.fullscreen) {