ListMessageUserPositionInterface
} from "../../Connexion";
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
+import {MAP_FILE_URL} from "../../Enum/EnvironmentVariable";
+import {getMapKeyByUrl} from "../Login/LogincScene";
+import SceneManager = Phaser.Scenes.SceneManager;
+import ScenePlugin = Phaser.Scenes.ScenePlugin;
export enum StatusGameManagerEnum {
IN_PROGRESS = 1,
pushPlayerPosition(event: HasMovedEvent) {
this.ConnexionInstance.sharePosition(event.x, event.y, event.character, this.currentGameScene.scene.key, event.direction);
}
+
+ loadMap(mapUrl: string, scene: ScenePlugin): string {
+ let sceneKey = getMapKeyByUrl(mapUrl);
+
+ let gameIndex = scene.getIndex(sceneKey);
+ let game : Phaser.Scene = null;
+ if(gameIndex === -1){
+ game = new GameScene(sceneKey, `${MAP_FILE_URL}${mapUrl}`);
+ scene.add(sceneKey, game, false);
+ }
+ return sceneKey;
+ }
}
export const gameManager = new GameManager();
private loadNextGame(layer: ITiledMapLayer, mapWidth: number, tileWidth: number, tileHeight: number){
let exitSceneUrl = this.getExitSceneUrl(layer);
- let exitSceneKey = getMapKeyByUrl(exitSceneUrl);
+ let exitSceneKey = gameManager.loadMap(exitSceneUrl, this.scene);
+ /*let exitSceneKey = getMapKeyByUrl(exitSceneUrl);
let gameIndex = this.scene.getIndex(exitSceneKey);
let game : Phaser.Scene = null;
}
if(!game){
return;
- }
+ }*/
let tiles : any = layer.data;
tiles.forEach((objectKey : number, key: number) => {
if(objectKey === 0){
if (!scene) {
return;
}
- let key = getMapKeyByUrl(scene.mapUrlStart);
- let game = new GameScene(key,`${MAP_FILE_URL}${scene.mapUrlStart}`);
- this.scene.add(key, game, false);
+ let key = gameManager.loadMap(scene.mapUrlStart, this.scene);
this.scene.start(key);
return scene;
}).catch((err) => {