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> <button id="editGameSettingsButton">Settings</button>
</section> </section>
<section> <section>
<button id="showJoystick">Show joystick</button> <button id="toggleFullscreen">Toggle fullscreen</button>
</section> </section>
<section> <section>
<button id="sparkButton">Create map</button> <button id="sparkButton">Create map</button>

View File

@ -10,7 +10,7 @@ const videoQualityKey = 'videoQuality';
const audioPlayerVolumeKey = 'audioVolume'; const audioPlayerVolumeKey = 'audioVolume';
const audioPlayerMuteKey = 'audioMute'; const audioPlayerMuteKey = 'audioMute';
const helpCameraSettingsShown = 'helpCameraSettingsShown'; const helpCameraSettingsShown = 'helpCameraSettingsShown';
const joystickKey = 'showJoystick'; const fullscreenKey = 'fullscreen';
class LocalUserStore { class LocalUserStore {
saveUser(localUser: LocalUser) { saveUser(localUser: LocalUser) {
@ -102,11 +102,11 @@ class LocalUserStore {
return localStorage.getItem(helpCameraSettingsShown) === '1'; return localStorage.getItem(helpCameraSettingsShown) === '1';
} }
setJoystick(value: boolean): void { setFullscreen(value: boolean): void {
localStorage.setItem(joystickKey, value.toString()); localStorage.setItem(fullscreenKey, value.toString());
} }
getJoystick(): boolean { getFullscreen(): boolean {
return localStorage.getItem(joystickKey) === 'true'; 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.connectionAnswerPromise = new Promise<RoomJoinedMessageInterface>((resolve, reject): void => {
this.connectionAnswerPromiseResolve = resolve; 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 //hook preload scene
@ -423,7 +413,7 @@ export class GameScene extends ResizableScene implements CenterListener {
enable: true, enable: true,
dir: "8dir", dir: "8dir",
}); });
this.virtualJoystick.visible = localUserStore.getJoystick() this.virtualJoystick.visible = true;
//create input to move //create input to move
mediaManager.setUserInputManager(this.userInputManager); mediaManager.setUserInputManager(this.userInputManager);
this.userInputManager = new UserInputManager(this, this.virtualJoystick); 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.x = pointer.x;
this.virtualJoystick.y = pointer.y; this.virtualJoystick.y = pointer.y;
}); });
if (localUserStore.getFullscreen()) {
document.querySelector('body')?.requestFullscreen();
}
//notify game manager can to create currentUser in map //notify game manager can to create currentUser in map
this.createCurrentPlayer(); this.createCurrentPlayer();
this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted 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': case 'editGameSettingsButton':
this.openGameSettingsMenu(); this.openGameSettingsMenu();
break; break;
case 'showJoystick': case 'toggleFullscreen':
this.showJoystick(); this.toggleFullscreen();
break; break;
case 'adminConsoleButton': case 'adminConsoleButton':
gameManager.getCurrentGameScene(this).ConsoleGlobalMessageManager.activeMessageConsole(); gameManager.getCurrentGameScene(this).ConsoleGlobalMessageManager.activeMessageConsole();
@ -332,13 +332,7 @@ export class MenuScene extends Phaser.Scene {
this.gameReportElement.close(); this.gameReportElement.close();
} }
private showJoystick() { private toggleFullscreen() {
const gameScene = gameManager.getCurrentGameScene(this)
if (gameScene?.virtualJoystick) {
const joystickVisible = !gameScene.virtualJoystick.visible
gameScene.virtualJoystick.visible = joystickVisible
localUserStore.setJoystick(joystickVisible)
}
const body = document.querySelector('body') const body = document.querySelector('body')
if (body) { if (body) {
if (document.fullscreenElement ?? document.fullscreen) { if (document.fullscreenElement ?? document.fullscreen) {