first step in simplification: remove the concept of room in the front end
This commit is contained in:
parent
8bd4e81f48
commit
ee4a59578a
5 changed files with 27 additions and 48 deletions
|
@ -1,4 +1,4 @@
|
|||
import {GameSceneInterface, GameScene} from "./GameScene";
|
||||
import {GameScene} from "./GameScene";
|
||||
import {ROOM} from "../../Enum/EnvironmentVariable"
|
||||
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
||||
|
||||
|
@ -9,46 +9,32 @@ export enum StatusGameManagerEnum {
|
|||
|
||||
export let ConnexionInstance : ConnexionInterface;
|
||||
|
||||
export interface GameManagerInterface {
|
||||
GameScenes: Array<GameSceneInterface>;
|
||||
status : number;
|
||||
createCurrentPlayer() : void;
|
||||
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
|
||||
}
|
||||
export class GameManager implements GameManagerInterface {
|
||||
GameScenes: Array<GameSceneInterface> = [];
|
||||
export class GameManager {
|
||||
status: number;
|
||||
private ConnexionInstance: Connexion;
|
||||
private currentGameScene: GameScene;
|
||||
|
||||
constructor() {
|
||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||
this.configureGame();
|
||||
}
|
||||
|
||||
connect(email:string) {
|
||||
this.ConnexionInstance = new Connexion(email, this);
|
||||
ConnexionInstance = this.ConnexionInstance;
|
||||
return this.ConnexionInstance.createConnexion()
|
||||
}
|
||||
|
||||
/**
|
||||
* permit to config rooms
|
||||
*/
|
||||
configureGame() {
|
||||
ROOM.forEach((roomId) => {
|
||||
let newGame = new GameScene(roomId, this);
|
||||
this.GameScenes.push((newGame as GameSceneInterface));
|
||||
});
|
||||
|
||||
setCurrentGameScene(gameScene: GameScene) {
|
||||
this.currentGameScene = gameScene;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 === this.ConnexionInstance.startedRoom);
|
||||
game.createCurrentPlayer(this.ConnexionInstance.userId);
|
||||
this.currentGameScene.createCurrentPlayer(this.ConnexionInstance.userId);
|
||||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
||||
}
|
||||
|
||||
|
@ -61,11 +47,7 @@ export class GameManager implements GameManagerInterface {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ListMessageUserPosition.roomId);
|
||||
if (!Game) {
|
||||
return;
|
||||
}
|
||||
Game.shareUserPosition(ListMessageUserPosition.listUsersPosition)
|
||||
this.currentGameScene.shareUserPosition(ListMessageUserPosition.listUsersPosition)
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {GameManagerInterface, StatusGameManagerEnum} from "./GameManager";
|
||||
import {GameManager, gameManager, StatusGameManagerEnum} from "./GameManager";
|
||||
import {MessageUserPositionInterface} from "../../Connexion";
|
||||
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
|
||||
import {DEBUG_MODE, RESOLUTION, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
|
||||
import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
|
||||
import Tile = Phaser.Tilemaps.Tile;
|
||||
import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
|
||||
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
||||
|
@ -13,14 +13,12 @@ export enum Textures {
|
|||
}
|
||||
|
||||
export interface GameSceneInterface extends Phaser.Scene {
|
||||
RoomId : string;
|
||||
Map: Phaser.Tilemaps.Tilemap;
|
||||
createCurrentPlayer(UserId : string) : void;
|
||||
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
|
||||
}
|
||||
export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
||||
GameManager : GameManagerInterface;
|
||||
RoomId : string;
|
||||
GameManager : GameManager;
|
||||
Terrains : Array<Phaser.Tilemaps.Tileset>;
|
||||
CurrentPlayer: CurrentGamerInterface;
|
||||
MapPlayers : Phaser.Physics.Arcade.Group;
|
||||
|
@ -32,17 +30,17 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
|
|||
startY = (window.innerHeight / 2) / RESOLUTION;
|
||||
|
||||
|
||||
constructor(RoomId : string, GameManager : GameManagerInterface) {
|
||||
constructor() {
|
||||
super({
|
||||
key: "GameScene"
|
||||
});
|
||||
this.RoomId = RoomId;
|
||||
this.GameManager = GameManager;
|
||||
this.GameManager = gameManager;
|
||||
this.Terrains = [];
|
||||
}
|
||||
|
||||
//hook preload scene
|
||||
preload(): void {
|
||||
this.GameManager.setCurrentGameScene(this);
|
||||
cypressAsserter.preloadStarted();
|
||||
let mapUrl = 'maps/map.json';
|
||||
this.load.on('filecomplete-tilemapJSON-'+Textures.Map, (key: string, type: string, data: any) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue