Always enable virtual joystick

Keeps 'toggle fullscreen' as a separate game setting.
This commit is contained in:
PizZaKatZe 2021-04-07 12:42:56 +02:00
parent 340caaff32
commit 633bdfcaff
4 changed files with 15 additions and 26 deletions

View file

@ -37,7 +37,7 @@
<button id="editGameSettingsButton">Settings</button>
</section>
<section>
<button id="showJoystick">Show joystick</button>
<button id="toggleFullscreen">Toggle fullscreen</button>
</section>
<section>
<button id="sparkButton">Create map</button>

View file

@ -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';
}
}

View file

@ -188,16 +188,6 @@ export class GameScene extends ResizableScene implements CenterListener {
this.connectionAnswerPromise = new Promise<RoomJoinedMessageInterface>((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

View file

@ -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) {