diff --git a/front/src/Components/Menu/ProfileSubMenu.svelte b/front/src/Components/Menu/ProfileSubMenu.svelte index 516baf6b..2a2b7af0 100644 --- a/front/src/Components/Menu/ProfileSubMenu.svelte +++ b/front/src/Components/Menu/ProfileSubMenu.svelte @@ -7,6 +7,8 @@ import {loginSceneVisibleStore} from "../../Stores/LoginSceneStore"; import {selectCharacterSceneVisibleStore} from "../../Stores/SelectCharacterStore"; import {SelectCharacterScene, SelectCharacterSceneName} from "../../Phaser/Login/SelectCharacterScene"; + import {EnableCameraScene, EnableCameraSceneName} from "../../Phaser/Login/EnableCameraScene"; + import {enableCameraSceneVisibilityStore} from "../../Stores/MediaStore"; //import {connectionManager} from "../../Connexion/ConnectionManager"; @@ -33,6 +35,12 @@ gameManager.leaveGame(SelectCharacterSceneName,new SelectCharacterScene()); } + function openEnableCameraScene(){ + disableMenuStores(); + enableCameraSceneVisibilityStore.showEnableCameraScene(); + gameManager.leaveGame(EnableCameraSceneName,new EnableCameraScene()); + } + //TODO: Uncomment when login will be completely developed /*function clickLogin() { connectionManager.loadOpenIDScreen(); @@ -50,6 +58,9 @@
+
+ +
diff --git a/front/src/Connexion/LocalUserStore.ts b/front/src/Connexion/LocalUserStore.ts index db4c3083..05c9613d 100644 --- a/front/src/Connexion/LocalUserStore.ts +++ b/front/src/Connexion/LocalUserStore.ts @@ -17,6 +17,7 @@ const authToken = "authToken"; const state = "state"; const nonce = "nonce"; const notification = "notificationPermission"; +const cameraSetup = "cameraSetup"; const cacheAPIIndex = "workavdenture-cache"; @@ -174,6 +175,14 @@ class LocalUserStore { localStorage.removeItem(nonce); return oldValue; } + + setCameraSetup(cameraId: string) { + localStorage.setItem(cameraSetup, cameraId); + } + getCameraSetup(): { video: unknown; audio: unknown } | undefined { + const cameraSetupValues = localStorage.getItem(cameraSetup); + return cameraSetupValues != undefined ? JSON.parse(cameraSetupValues) : undefined; + } } export const localUserStore = new LocalUserStore(); diff --git a/front/src/Phaser/Components/Loader.ts b/front/src/Phaser/Components/Loader.ts index c80e31b8..f77590eb 100644 --- a/front/src/Phaser/Components/Loader.ts +++ b/front/src/Phaser/Components/Loader.ts @@ -70,3 +70,9 @@ export const addLoader = (scene: Phaser.Scene): void => { } }); }; + +export const removeLoader = (scene: Phaser.Scene): void => { + if (scene.load.textureManager.exists(LogoNameIndex)) { + scene.load.textureManager.remove(LogoNameIndex); + } +}; diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 45d0bc86..068e1734 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -18,6 +18,7 @@ export class GameManager { private characterLayers: string[] | null; private companion: string | null; private startRoom!: Room; + private cameraSetup?: { video: unknown; audio: unknown }; currentGameSceneName: string | null = null; // Note: this scenePlugin is the scenePlugin of the EntryScene. We should always provide a key in methods called on this scenePlugin. private scenePlugin!: Phaser.Scenes.ScenePlugin; @@ -26,6 +27,7 @@ export class GameManager { this.playerName = localUserStore.getName(); this.characterLayers = localUserStore.getCharacterLayers(); this.companion = localUserStore.getCompanion(); + this.cameraSetup = localUserStore.getCameraSetup(); } public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise { @@ -37,8 +39,11 @@ export class GameManager { return LoginSceneName; } else if (!this.characterLayers || !this.characterLayers.length) { return SelectCharacterSceneName; - } else { + } else if (this.cameraSetup == undefined) { return EnableCameraSceneName; + } else { + this.activeMenuSceneAndHelpCameraSettings(); + return this.startRoom.key; } } @@ -84,7 +89,14 @@ export class GameManager { public goToStartingMap(): void { console.log("starting " + (this.currentGameSceneName || this.startRoom.key)); this.scenePlugin.start(this.currentGameSceneName || this.startRoom.key); + this.activeMenuSceneAndHelpCameraSettings(); + } + /** + * @private + * @return void + */ + private activeMenuSceneAndHelpCameraSettings(): void { if ( !localUserStore.getHelpCameraSettingsShown() && (!get(requestedMicrophoneState) || !get(requestedCameraState)) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index e1eb0476..9fbb7ea3 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -37,7 +37,7 @@ import { localUserStore } from "../../Connexion/LocalUserStore"; import { HtmlUtils } from "../../WebRtc/HtmlUtils"; import { mediaManager } from "../../WebRtc/MediaManager"; import { SimplePeer } from "../../WebRtc/SimplePeer"; -import { addLoader } from "../Components/Loader"; +import { addLoader, removeLoader } from "../Components/Loader"; import { OpenChatIcon, openChatIconName } from "../Components/OpenChatIcon"; import { lazyLoadPlayerCharacterTextures, loadCustomTexture } from "../Entity/PlayerTexturesLoadingManager"; import { RemotePlayer } from "../Entity/RemotePlayer"; @@ -291,8 +291,11 @@ export class GameScene extends DirtyScene { } //once preloading is over, we don't want loading errors to crash the game, so we need to disable this behavior after preloading. - console.error("Error when loading: ", file); if (this.preloading) { + //remove loader in progress + removeLoader(this); + + //display an error scene this.scene.start(ErrorSceneName, { title: "Network error", subTitle: "An error occurred while loading resource:", @@ -1258,7 +1261,9 @@ ${escapedMessage} if (!targetRoom.isEqual(this.room)) { if (this.scene.get(targetRoom.key) === null) { console.error("next room not loaded", targetRoom.key); - return; + // Try to load next dame room from exit URL + // The policy of room can to be updated during a session and not load before + await this.loadNextGameFromExitUrl(targetRoom.key); } this.cleanupClosingScene(); this.scene.stop(); diff --git a/front/src/Phaser/Game/SharedVariablesManager.ts b/front/src/Phaser/Game/SharedVariablesManager.ts index 76b78d04..b4f2a3f7 100644 --- a/front/src/Phaser/Game/SharedVariablesManager.ts +++ b/front/src/Phaser/Game/SharedVariablesManager.ts @@ -1,7 +1,7 @@ import type { RoomConnection } from "../../Connexion/RoomConnection"; import { iframeListener } from "../../Api/IframeListener"; import type { GameMap } from "./GameMap"; -import type {ITiledMapLayer, ITiledMapObject, ITiledMapObjectLayer} from "../Map/ITiledMap"; +import type { ITiledMapLayer, ITiledMapObject, ITiledMapObjectLayer } from "../Map/ITiledMap"; interface Variable { defaultValue: unknown; diff --git a/front/src/Phaser/Login/EnableCameraScene.ts b/front/src/Phaser/Login/EnableCameraScene.ts index 1b317d12..91a351ff 100644 --- a/front/src/Phaser/Login/EnableCameraScene.ts +++ b/front/src/Phaser/Login/EnableCameraScene.ts @@ -1,6 +1,7 @@ import { gameManager } from "../Game/GameManager"; import { ResizableScene } from "./ResizableScene"; import { enableCameraSceneVisibilityStore } from "../../Stores/MediaStore"; +import { localUserStore } from "../../Connexion/LocalUserStore"; export const EnableCameraSceneName = "EnableCameraScene"; diff --git a/front/src/Phaser/Login/SelectCompanionScene.ts b/front/src/Phaser/Login/SelectCompanionScene.ts index cbff75d3..46ad6361 100644 --- a/front/src/Phaser/Login/SelectCompanionScene.ts +++ b/front/src/Phaser/Login/SelectCompanionScene.ts @@ -1,5 +1,3 @@ -import Image = Phaser.GameObjects.Image; -import Rectangle = Phaser.GameObjects.Rectangle; import { addLoader } from "../Components/Loader"; import { gameManager } from "../Game/GameManager"; import { ResizableScene } from "./ResizableScene"; diff --git a/front/src/Stores/MediaStore.ts b/front/src/Stores/MediaStore.ts index d23a4a23..48832773 100644 --- a/front/src/Stores/MediaStore.ts +++ b/front/src/Stores/MediaStore.ts @@ -251,10 +251,18 @@ export const mediaStreamConstraintsStore = derived( let currentAudioConstraint: boolean | MediaTrackConstraints = $audioConstraintStore; if ($enableCameraSceneVisibilityStore) { + console.log("currentVideoConstraint", currentVideoConstraint); + console.log("currentAudioConstraint", currentAudioConstraint); set({ video: currentVideoConstraint, audio: currentAudioConstraint, }); + localUserStore.setCameraSetup( + JSON.stringify({ + video: currentVideoConstraint, + audio: currentAudioConstraint, + }) + ); return; }