Fix integration login scene in game manager
This commit is contained in:
parent
8c935e8b27
commit
4e556782af
@ -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<any>;
|
||||
}
|
||||
export class GameManager implements GameManagerInterface {
|
||||
GameScenes: Array<GameSceneInterface> = [];
|
||||
@ -27,15 +29,26 @@ export class GameManager implements GameManagerInterface {
|
||||
this.configureGame();
|
||||
}
|
||||
|
||||
connect(email:string) {
|
||||
/**
|
||||
*
|
||||
* @param email
|
||||
*/
|
||||
connect(email : string) : Promise<any> {
|
||||
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;
|
||||
}
|
||||
|
@ -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<MessageUserPositionInterface>): void {
|
||||
}
|
||||
}
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user