Improving error handling upon unknown URL

This commit is contained in:
David Négrier 2020-10-12 17:42:37 +02:00
parent 02c193a262
commit 2852f204f5
4 changed files with 32 additions and 12 deletions

View File

@ -53,7 +53,7 @@ class ConnectionManager {
return Promise.reject('Could not find a user in localstorage');
}
}
return Promise.reject('ConnexionManager initialization failed');
return Promise.reject('ConnexionManager initialization failed: invalid URL');
}
public initBenchmark(): void {

View File

@ -1,6 +1,7 @@
import {GameScene} from "./GameScene";
import {connectionManager} from "../../Connexion/ConnectionManager";
import {Room} from "../../Connexion/Room";
import {FourOFourSceneName} from "../Reconnecting/FourOFourScene";
export interface HasMovedEvent {
direction: string;
@ -14,10 +15,16 @@ export class GameManager {
private characterLayers!: string[];
private startRoom!:Room;
private sceneManager!: Phaser.Scenes.SceneManager;
public async init(sceneManager: Phaser.Scenes.SceneManager) {
this.sceneManager = sceneManager;
this.startRoom = await connectionManager.initGameConnexion();
try {
this.startRoom = await connectionManager.initGameConnexion();
} catch (e) {
this.sceneManager.start(FourOFourSceneName, {
url: window.location.pathname.toString()
});
}
this.loadMap(this.startRoom.url, this.startRoom.ID);
}
@ -40,8 +47,8 @@ export class GameManager {
getCharacterSelected(): string[] {
return this.characterLayers;
}
public loadMap(mapUrl: string, roomID: string): void {
console.log('Loading map '+roomID+' at url '+mapUrl);
const gameIndex = this.sceneManager.getIndex(roomID);
@ -57,7 +64,7 @@ export class GameManager {
const endPos = mapUrlStart.indexOf(".json");
return mapUrlStart.substring(startPos, endPos);
}
public async goToStartingMap() {
this.sceneManager.start(this.startRoom.ID, {startLayerName: 'global'});
}

View File

@ -15,7 +15,8 @@ export class FourOFourScene extends Phaser.Scene {
private fileNameField!: Text;
private logo!: Image;
private cat!: Sprite;
private file!: string;
private file: string|undefined;
private url: string|undefined;
constructor() {
super({
@ -23,8 +24,9 @@ export class FourOFourScene extends Phaser.Scene {
});
}
init({ file }: { file: string }) {
init({ file, url }: { file?: string, url?: string }) {
this.file = file;
this.url = url;
}
preload() {
@ -45,11 +47,22 @@ export class FourOFourScene extends Phaser.Scene {
this.mapNotFoundField = new TextField(this, this.game.renderer.width / 2, this.game.renderer.height / 2, "404 - File not found");
this.mapNotFoundField.setOrigin(0.5, 0.5).setCenterAlign();
this.couldNotFindField = new TextField(this, this.game.renderer.width / 2, this.game.renderer.height / 2 + 24, "Could not load file");
let text: string = '';
if (this.file !== undefined) {
text = "Could not load map"
}
if (this.url !== undefined) {
text = "Invalid URL"
}
this.couldNotFindField = new TextField(this, this.game.renderer.width / 2, this.game.renderer.height / 2 + 24, text);
this.couldNotFindField.setOrigin(0.5, 0.5).setCenterAlign();
this.fileNameField = this.add.text(this.game.renderer.width / 2, this.game.renderer.height / 2 + 38, this.file, { fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif', fontSize: '10px' });
this.fileNameField.setOrigin(0.5, 0.5);
const url = this.file ? this.file : this.url;
if (url !== undefined) {
this.fileNameField = this.add.text(this.game.renderer.width / 2, this.game.renderer.height / 2 + 38, url, { fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif', fontSize: '10px' });
this.fileNameField.setOrigin(0.5, 0.5);
}
this.cat = this.physics.add.sprite(this.game.renderer.width / 2, this.game.renderer.height / 2 - 32, 'cat', 6);
this.cat.flipY=true;

View File

@ -16,7 +16,7 @@ class UrlManager {
return GameConnexionTypes.anonymous;
} else if (url.indexOf('@/') > -1) {
return GameConnexionTypes.organization;
} else if(url.indexOf('register/')) {
} else if(url.indexOf('register/') > -1) {
return GameConnexionTypes.register
} else {
return GameConnexionTypes.unknown