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 {ROOM} from "../../Enum/EnvironmentVariable"
|
||||||
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
||||||
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
|
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
|
||||||
|
import {LogincScene} from "../Login/LogincScene";
|
||||||
|
|
||||||
export enum StatusGameManagerEnum {
|
export enum StatusGameManagerEnum {
|
||||||
IN_PROGRESS = 1,
|
IN_PROGRESS = 1,
|
||||||
@ -16,6 +17,7 @@ export interface GameManagerInterface {
|
|||||||
SimplePeer: SimplePeerInterface;
|
SimplePeer: SimplePeerInterface;
|
||||||
createCurrentPlayer() : void;
|
createCurrentPlayer() : void;
|
||||||
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
||||||
|
connect(email : string) : Promise<any>;
|
||||||
}
|
}
|
||||||
export class GameManager implements GameManagerInterface {
|
export class GameManager implements GameManagerInterface {
|
||||||
GameScenes: Array<GameSceneInterface> = [];
|
GameScenes: Array<GameSceneInterface> = [];
|
||||||
@ -27,15 +29,26 @@ export class GameManager implements GameManagerInterface {
|
|||||||
this.configureGame();
|
this.configureGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(email:string) {
|
/**
|
||||||
|
*
|
||||||
|
* @param email
|
||||||
|
*/
|
||||||
|
connect(email : string) : Promise<any> {
|
||||||
ConnexionInstance = new Connexion(email, this);
|
ConnexionInstance = new Connexion(email, this);
|
||||||
|
return ConnexionInstance.createConnexion().then(() => {
|
||||||
this.SimplePeer = new SimplePeer(ConnexionInstance);
|
this.SimplePeer = new SimplePeer(ConnexionInstance);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* permit to config rooms
|
* permit to config rooms
|
||||||
*/
|
*/
|
||||||
configureGame() {
|
configureGame() {
|
||||||
|
//create login scene
|
||||||
|
let LoginScene = new LogincScene();
|
||||||
|
this.GameScenes.push(LoginScene)
|
||||||
|
|
||||||
|
//create scene
|
||||||
ROOM.forEach((roomId) => {
|
ROOM.forEach((roomId) => {
|
||||||
let newGame = new GameScene(roomId, this);
|
let newGame = new GameScene(roomId, this);
|
||||||
this.GameScenes.push((newGame as GameSceneInterface));
|
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 {
|
createCurrentPlayer(): void {
|
||||||
//Get started room send by the backend
|
//Get started room send by the backend
|
||||||
let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom);
|
let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom);
|
||||||
|
if(!game){
|
||||||
|
return;
|
||||||
|
}
|
||||||
game.createCurrentPlayer(ConnexionInstance.userId);
|
game.createCurrentPlayer(ConnexionInstance.userId);
|
||||||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import KeyboardKeydownCallback = Phaser.Types.Input.Keyboard.KeyboardKeydownCallback;
|
|
||||||
import {gameManager} from "../Game/GameManager";
|
import {gameManager} from "../Game/GameManager";
|
||||||
import {ROOM} from "../../Enum/EnvironmentVariable";
|
|
||||||
import {TextField} from "../Components/TextField";
|
import {TextField} from "../Components/TextField";
|
||||||
import {TextInput} from "../Components/TextInput";
|
import {TextInput} from "../Components/TextInput";
|
||||||
import {ClickButton} from "../Components/ClickButton";
|
import {ClickButton} from "../Components/ClickButton";
|
||||||
|
import {GameSceneInterface} from "../Game/GameScene";
|
||||||
|
import {MessageUserPositionInterface} from "../../Connexion";
|
||||||
|
|
||||||
//todo: put this constants in a dedicated file
|
//todo: put this constants in a dedicated file
|
||||||
export const LoginSceneName = "LoginScene";
|
export const LoginSceneName = "LoginScene";
|
||||||
@ -11,11 +11,12 @@ enum LoginTextures {
|
|||||||
playButton = "play_button",
|
playButton = "play_button",
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LogincScene extends Phaser.Scene {
|
export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
||||||
private emailInput: TextInput;
|
private emailInput: TextInput;
|
||||||
private textField: TextField;
|
private textField: TextField;
|
||||||
private playButton: ClickButton;
|
private playButton: ClickButton;
|
||||||
private infoTextField: TextField;
|
private infoTextField: TextField;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
key: LoginSceneName
|
key: LoginSceneName
|
||||||
@ -45,7 +46,17 @@ export class LogincScene extends Phaser.Scene {
|
|||||||
async login() {
|
async login() {
|
||||||
let email = this.emailInput.text;
|
let email = this.emailInput.text;
|
||||||
if (!email) return;
|
if (!email) return;
|
||||||
await gameManager.connect(email);
|
gameManager.connect(email).then(() => {
|
||||||
this.scene.start("GameScene");
|
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,
|
width: window.innerWidth / RESOLUTION,
|
||||||
height: window.innerHeight / RESOLUTION,
|
height: window.innerHeight / RESOLUTION,
|
||||||
parent: "game",
|
parent: "game",
|
||||||
scene: [LogincScene, ...gameManager.GameScenes as any],
|
scene: gameManager.GameScenes,
|
||||||
zoom: RESOLUTION,
|
zoom: RESOLUTION,
|
||||||
physics: {
|
physics: {
|
||||||
default: "arcade",
|
default: "arcade",
|
||||||
|
Loading…
Reference in New Issue
Block a user