Using Room class to load GameScene

This commit is contained in:
David Négrier 2020-10-13 17:08:24 +02:00
parent aee06da7f9
commit ec93891c6b
3 changed files with 13 additions and 6 deletions

View File

@ -5,9 +5,8 @@ export class Room {
public readonly id: string;
public readonly isPublic: boolean;
private mapUrl: string|undefined;
//public url: string
constructor(id: string/*, url: string*/) {
constructor(id: string) {
if (id.startsWith('/')) {
id = id.substr(1);
}

View File

@ -17,8 +17,7 @@ export class GameManager {
public async init(scenePlugin: Phaser.Scenes.ScenePlugin) {
this.startRoom = await connectionManager.initGameConnexion();
const url = await this.startRoom.getMapUrl();
this.loadMap(url, this.startRoom.id, scenePlugin);
await this.loadMap(this.startRoom, scenePlugin);
}
public setPlayerName(name: string): void {
@ -42,8 +41,11 @@ export class GameManager {
}
public loadMap(mapUrl: string, roomID: string, scenePlugin: Phaser.Scenes.ScenePlugin): void {
public async loadMap(room: Room, scenePlugin: Phaser.Scenes.ScenePlugin): Promise<void> {
const roomID = room.id;
const mapUrl = await room.getMapUrl();
console.log('Loading map '+roomID+' at url '+mapUrl);
const gameIndex = scenePlugin.getIndex(mapUrl);
if(gameIndex === -1){
const game : Phaser.Scene = GameScene.createFromUrl(mapUrl, roomID);

View File

@ -46,6 +46,7 @@ import {RoomConnection} from "../../Connexion/RoomConnection";
import {GlobalMessageManager} from "../../Administration/GlobalMessageManager";
import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager";
import {ResizableScene} from "../Login/ResizableScene";
import {Room} from "../../Connexion/Room";
export enum Textures {
@ -690,8 +691,13 @@ export class GameScene extends ResizableScene implements CenterListener {
}
// TODO: eventually compute a relative URL
// TODO: handle /@/ URL CASES!
const absoluteExitSceneUrl = new URL(exitSceneUrl, this.MapUrlFile).href;
gameManager.loadMap(absoluteExitSceneUrl, instance, this.scene);
const absoluteExitSceneUrlWithoutProtocol = absoluteExitSceneUrl.toString().substr(absoluteExitSceneUrl.toString().indexOf('://')+3);
const roomId = '_/'+instance+'/'+absoluteExitSceneUrlWithoutProtocol;
gameManager.loadMap(new Room(roomId), this.scene);
const exitSceneKey = instance;
const tiles : number[] = layer.data as number[];