Using Room class to load GameScene
This commit is contained in:
parent
aee06da7f9
commit
ec93891c6b
@ -5,9 +5,8 @@ export class Room {
|
|||||||
public readonly id: string;
|
public readonly id: string;
|
||||||
public readonly isPublic: boolean;
|
public readonly isPublic: boolean;
|
||||||
private mapUrl: string|undefined;
|
private mapUrl: string|undefined;
|
||||||
//public url: string
|
|
||||||
|
|
||||||
constructor(id: string/*, url: string*/) {
|
constructor(id: string) {
|
||||||
if (id.startsWith('/')) {
|
if (id.startsWith('/')) {
|
||||||
id = id.substr(1);
|
id = id.substr(1);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,7 @@ export class GameManager {
|
|||||||
|
|
||||||
public async init(scenePlugin: Phaser.Scenes.ScenePlugin) {
|
public async init(scenePlugin: Phaser.Scenes.ScenePlugin) {
|
||||||
this.startRoom = await connectionManager.initGameConnexion();
|
this.startRoom = await connectionManager.initGameConnexion();
|
||||||
const url = await this.startRoom.getMapUrl();
|
await this.loadMap(this.startRoom, scenePlugin);
|
||||||
this.loadMap(url, this.startRoom.id, scenePlugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setPlayerName(name: string): void {
|
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);
|
console.log('Loading map '+roomID+' at url '+mapUrl);
|
||||||
|
|
||||||
const gameIndex = scenePlugin.getIndex(mapUrl);
|
const gameIndex = scenePlugin.getIndex(mapUrl);
|
||||||
if(gameIndex === -1){
|
if(gameIndex === -1){
|
||||||
const game : Phaser.Scene = GameScene.createFromUrl(mapUrl, roomID);
|
const game : Phaser.Scene = GameScene.createFromUrl(mapUrl, roomID);
|
||||||
|
@ -46,6 +46,7 @@ import {RoomConnection} from "../../Connexion/RoomConnection";
|
|||||||
import {GlobalMessageManager} from "../../Administration/GlobalMessageManager";
|
import {GlobalMessageManager} from "../../Administration/GlobalMessageManager";
|
||||||
import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager";
|
import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager";
|
||||||
import {ResizableScene} from "../Login/ResizableScene";
|
import {ResizableScene} from "../Login/ResizableScene";
|
||||||
|
import {Room} from "../../Connexion/Room";
|
||||||
|
|
||||||
|
|
||||||
export enum Textures {
|
export enum Textures {
|
||||||
@ -690,8 +691,13 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: eventually compute a relative URL
|
// TODO: eventually compute a relative URL
|
||||||
|
|
||||||
|
// TODO: handle /@/ URL CASES!
|
||||||
|
|
||||||
const absoluteExitSceneUrl = new URL(exitSceneUrl, this.MapUrlFile).href;
|
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 exitSceneKey = instance;
|
||||||
|
|
||||||
const tiles : number[] = layer.data as number[];
|
const tiles : number[] = layer.data as number[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user