Fix feedback @moufmouf strategy of maps managing by back.
This commit is contained in:
parent
68ac145882
commit
58b65030bd
11 changed files with 35 additions and 33 deletions
|
@ -3,6 +3,7 @@ import {GameManager} from "./Phaser/Game/GameManager";
|
|||
const SocketIo = require('socket.io-client');
|
||||
import Axios from "axios";
|
||||
import {API_URL} from "./Enum/EnvironmentVariable";
|
||||
import {getMapKeyByUrl} from "./Phaser/Login/LogincScene";
|
||||
|
||||
enum EventMessage{
|
||||
WEBRTC_SIGNAL = "webrtc-signal",
|
||||
|
@ -182,7 +183,8 @@ export class Connexion implements ConnexionInterface {
|
|||
return Axios.post(`${API_URL}/login`, {email: this.email})
|
||||
.then((res) => {
|
||||
this.token = res.data.token;
|
||||
this.startedRoom = res.data.startedRoom.key;
|
||||
|
||||
this.startedRoom = getMapKeyByUrl(res.data.mapUrlStart);
|
||||
this.userId = res.data.userId;
|
||||
|
||||
this.socket = SocketIo(`${API_URL}`, {
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
ListMessageUserPositionInterface
|
||||
} from "../../Connexion";
|
||||
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
|
||||
import {API_URL} from "../../Enum/EnvironmentVariable";
|
||||
|
||||
export enum StatusGameManagerEnum {
|
||||
IN_PROGRESS = 1,
|
||||
|
@ -30,7 +31,6 @@ export class GameManager {
|
|||
private playerName: string;
|
||||
SimplePeer : SimplePeerInterface;
|
||||
private characterUserSelected: string;
|
||||
Maps: Array<MapObject>;
|
||||
|
||||
constructor() {
|
||||
this.status = StatusGameManagerEnum.IN_PROGRESS;
|
||||
|
@ -50,7 +50,6 @@ export class GameManager {
|
|||
|
||||
loadMaps(){
|
||||
return this.ConnexionInstance.loadMaps().then((data) => {
|
||||
this.Maps = data.maps;
|
||||
return data;
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
|
|
|
@ -12,6 +12,7 @@ import Texture = Phaser.Textures.Texture;
|
|||
import Sprite = Phaser.GameObjects.Sprite;
|
||||
import CanvasTexture = Phaser.Textures.CanvasTexture;
|
||||
import CreateSceneFromObjectConfig = Phaser.Types.Scenes.CreateSceneFromObjectConfig;
|
||||
import {getMapKeyByUrl} from "../Login/LogincScene";
|
||||
|
||||
export enum Textures {
|
||||
Player = "male1"
|
||||
|
@ -64,17 +65,18 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
|
|||
// Triggered when the map is loaded
|
||||
// Load tiles attached to the map recursively
|
||||
this.map = data.data;
|
||||
let url = this.MapUrlFile.substr(0, this.MapUrlFile.indexOf(`${this.MapKey}.json`));
|
||||
this.map.tilesets.forEach((tileset) => {
|
||||
if (typeof tileset.name === 'undefined' || typeof tileset.image === 'undefined') {
|
||||
console.warn("Don't know how to handle tileset ", tileset)
|
||||
return;
|
||||
}
|
||||
//TODO strategy to add access token
|
||||
this.load.image(tileset.name, `${this.MapUrlFile}/${tileset.image}`);
|
||||
this.load.image(tileset.name, `${url}/${tileset.image}`);
|
||||
})
|
||||
});
|
||||
//TODO strategy to add access token
|
||||
this.load.tilemapTiledJSON(this.MapKey, `${this.MapUrlFile}/${this.MapKey}.json`);
|
||||
this.load.tilemapTiledJSON(this.MapKey, this.MapUrlFile);
|
||||
|
||||
//add player png
|
||||
PLAYER_RESOURCES.forEach((playerResource: any) => {
|
||||
|
@ -164,16 +166,17 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
|
|||
*/
|
||||
private loadNextGame(layer: ITiledMapLayer, mapWidth: number, tileWidth: number, tileHeight: number){
|
||||
let properties : any = layer.properties;
|
||||
let nextSceneKey = properties.find((property:any) => property.name === "exitSceneKey");
|
||||
let nextMap : MapObject = gameManager.Maps.find((map: MapObject) => map.key === nextSceneKey.value);
|
||||
let exitSceneUrl = properties.find((property:any) => property.name === "exitSceneUrl");
|
||||
|
||||
let gameIndex = this.scene.getIndex(nextMap.key);
|
||||
let exitSceneKey = getMapKeyByUrl(exitSceneUrl.value);
|
||||
|
||||
let gameIndex = this.scene.getIndex(exitSceneKey);
|
||||
let game : Phaser.Scene = null;
|
||||
if(gameIndex === -1){
|
||||
game = new GameScene(nextMap.key, `${API_URL}${nextMap.url}`);
|
||||
this.scene.add(nextSceneKey, game, false);
|
||||
game = new GameScene(exitSceneKey, `${API_URL}${exitSceneUrl.value}`);
|
||||
this.scene.add(exitSceneKey, game, false);
|
||||
}else{
|
||||
game = this.scene.get(nextMap.key);
|
||||
game = this.scene.get(exitSceneKey);
|
||||
}
|
||||
if(!game){
|
||||
return;
|
||||
|
@ -192,7 +195,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
|
|||
yStart: (y * tileWidth),
|
||||
xEnd: ((x +1) * tileHeight),
|
||||
yEnd: ((y + 1) * tileHeight),
|
||||
key: nextMap.key
|
||||
key: exitSceneKey
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
|||
import {GroupCreatedUpdatedMessageInterface, MessageUserPositionInterface} from "../../Connexion";
|
||||
import {API_URL} from "../../Enum/EnvironmentVariable";
|
||||
|
||||
export function getMapKeyByUrl(mapUrlStart: string){
|
||||
let tab = mapUrlStart.split("/");
|
||||
return tab[tab.length -1].substr(0, tab[tab.length -1].indexOf(".json"));
|
||||
}
|
||||
|
||||
//todo: put this constants in a dedicated file
|
||||
export const LoginSceneName = "LoginScene";
|
||||
enum LoginTextures {
|
||||
|
@ -98,9 +103,10 @@ export class LogincScene extends Phaser.Scene implements GameSceneInterface {
|
|||
if (!scene) {
|
||||
return;
|
||||
}
|
||||
let game = new GameScene(scene.mapStart.key, `${API_URL}${scene.mapStart.url}`);
|
||||
this.scene.add(scene.mapStart.key, game, false);
|
||||
this.scene.start(scene.mapStart.key);
|
||||
let key = getMapKeyByUrl(scene.mapUrlStart);
|
||||
let game = new GameScene(key,`${API_URL}${scene.mapUrlStart}`);
|
||||
this.scene.add(key, game, false);
|
||||
this.scene.start(key);
|
||||
return scene;
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue