From: gparant Date: Tue, 28 Apr 2020 22:01:37 +0000 (+0200) Subject: Fix integration login scene in game manager X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e556782af8999e2bf997a54b2dced5c0a4ab4f5;p=libreadventure.git Fix integration login scene in game manager --- diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index fe04a95..52f0805 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -2,6 +2,7 @@ import {GameSceneInterface, GameScene} from "./GameScene"; import {ROOM} from "../../Enum/EnvironmentVariable" import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion"; import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer"; +import {LogincScene} from "../Login/LogincScene"; export enum StatusGameManagerEnum { IN_PROGRESS = 1, @@ -16,6 +17,7 @@ export interface GameManagerInterface { SimplePeer: SimplePeerInterface; createCurrentPlayer() : void; shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void; + connect(email : string) : Promise; } export class GameManager implements GameManagerInterface { GameScenes: Array = []; @@ -27,15 +29,26 @@ export class GameManager implements GameManagerInterface { this.configureGame(); } - connect(email:string) { + /** + * + * @param email + */ + connect(email : string) : Promise { ConnexionInstance = new Connexion(email, this); - this.SimplePeer = new SimplePeer(ConnexionInstance); + return ConnexionInstance.createConnexion().then(() => { + this.SimplePeer = new SimplePeer(ConnexionInstance); + }); } /** * permit to config rooms */ configureGame() { + //create login scene + let LoginScene = new LogincScene(); + this.GameScenes.push(LoginScene) + + //create scene ROOM.forEach((roomId) => { let newGame = new GameScene(roomId, this); this.GameScenes.push((newGame as GameSceneInterface)); @@ -43,13 +56,14 @@ export class GameManager implements GameManagerInterface { } /** - * Permit to create player in started room - * @param RoomId - * @param UserId + * */ createCurrentPlayer(): void { //Get started room send by the backend let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom); + if(!game){ + return; + } game.createCurrentPlayer(ConnexionInstance.userId); this.status = StatusGameManagerEnum.CURRENT_USER_CREATED; } diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LogincScene.ts index 0fb4d2a..1aa1e0a 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LogincScene.ts @@ -1,9 +1,9 @@ -import KeyboardKeydownCallback = Phaser.Types.Input.Keyboard.KeyboardKeydownCallback; import {gameManager} from "../Game/GameManager"; -import {ROOM} from "../../Enum/EnvironmentVariable"; import {TextField} from "../Components/TextField"; import {TextInput} from "../Components/TextInput"; import {ClickButton} from "../Components/ClickButton"; +import {GameSceneInterface} from "../Game/GameScene"; +import {MessageUserPositionInterface} from "../../Connexion"; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; @@ -11,21 +11,22 @@ enum LoginTextures { playButton = "play_button", } -export class LogincScene extends Phaser.Scene { +export class LogincScene extends Phaser.Scene implements GameSceneInterface { private emailInput: TextInput; private textField: TextField; private playButton: ClickButton; private infoTextField: TextField; + constructor() { super({ key: LoginSceneName }); } - + preload() { this.load.image(LoginTextures.playButton, "resources/objects/play_button.png"); } - + create() { this.textField = new TextField(this, 10, 10, 'Enter your email:'); this.emailInput = new TextInput(this, 10, 50); @@ -37,15 +38,25 @@ export class LogincScene extends Phaser.Scene { let infoText = "Commandes de base: \n - Z,Q,S,D (ou les flèches de direction) pour bouger\n - SHIFT pour accélerer"; this.infoTextField = new TextField(this, 10, 300, infoText); } - + update(time: number, delta: number): void { - + } - + async login() { let email = this.emailInput.text; if (!email) return; - await gameManager.connect(email); - this.scene.start("GameScene"); + gameManager.connect(email).then(() => { + this.scene.start("GameScene"); + }); + } + + Map: Phaser.Tilemaps.Tilemap; + RoomId: string; + + createCurrentPlayer(UserId: string): void { + } + + shareUserPosition(UsersPosition: Array): void { } } \ No newline at end of file diff --git a/front/src/index.ts b/front/src/index.ts index c55a5d0..09fd978 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -10,7 +10,7 @@ const config: GameConfig = { width: window.innerWidth / RESOLUTION, height: window.innerHeight / RESOLUTION, parent: "game", - scene: [LogincScene, ...gameManager.GameScenes as any], + scene: gameManager.GameScenes, zoom: RESOLUTION, physics: { default: "arcade",