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,
SimplePeer: SimplePeerInterface;
createCurrentPlayer() : void;
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
+ connect(email : string) : Promise<any>;
}
export class GameManager implements GameManagerInterface {
GameScenes: Array<GameSceneInterface> = [];
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));
}
/**
- * 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;
}
-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";
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);
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 {
}
}
\ No newline at end of file