Improving error handling upon unknown URL
This commit is contained in:
parent
02c193a262
commit
2852f204f5
@ -53,7 +53,7 @@ class ConnectionManager {
|
|||||||
return Promise.reject('Could not find a user in localstorage');
|
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 {
|
public initBenchmark(): void {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {GameScene} from "./GameScene";
|
import {GameScene} from "./GameScene";
|
||||||
import {connectionManager} from "../../Connexion/ConnectionManager";
|
import {connectionManager} from "../../Connexion/ConnectionManager";
|
||||||
import {Room} from "../../Connexion/Room";
|
import {Room} from "../../Connexion/Room";
|
||||||
|
import {FourOFourSceneName} from "../Reconnecting/FourOFourScene";
|
||||||
|
|
||||||
export interface HasMovedEvent {
|
export interface HasMovedEvent {
|
||||||
direction: string;
|
direction: string;
|
||||||
@ -17,7 +18,13 @@ export class GameManager {
|
|||||||
|
|
||||||
public async init(sceneManager: Phaser.Scenes.SceneManager) {
|
public async init(sceneManager: Phaser.Scenes.SceneManager) {
|
||||||
this.sceneManager = 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);
|
this.loadMap(this.startRoom.url, this.startRoom.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ export class FourOFourScene extends Phaser.Scene {
|
|||||||
private fileNameField!: Text;
|
private fileNameField!: Text;
|
||||||
private logo!: Image;
|
private logo!: Image;
|
||||||
private cat!: Sprite;
|
private cat!: Sprite;
|
||||||
private file!: string;
|
private file: string|undefined;
|
||||||
|
private url: string|undefined;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
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.file = file;
|
||||||
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
preload() {
|
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 = 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.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.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' });
|
const url = this.file ? this.file : this.url;
|
||||||
this.fileNameField.setOrigin(0.5, 0.5);
|
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 = this.physics.add.sprite(this.game.renderer.width / 2, this.game.renderer.height / 2 - 32, 'cat', 6);
|
||||||
this.cat.flipY=true;
|
this.cat.flipY=true;
|
||||||
|
@ -16,7 +16,7 @@ class UrlManager {
|
|||||||
return GameConnexionTypes.anonymous;
|
return GameConnexionTypes.anonymous;
|
||||||
} else if (url.indexOf('@/') > -1) {
|
} else if (url.indexOf('@/') > -1) {
|
||||||
return GameConnexionTypes.organization;
|
return GameConnexionTypes.organization;
|
||||||
} else if(url.indexOf('register/')) {
|
} else if(url.indexOf('register/') > -1) {
|
||||||
return GameConnexionTypes.register
|
return GameConnexionTypes.register
|
||||||
} else {
|
} else {
|
||||||
return GameConnexionTypes.unknown
|
return GameConnexionTypes.unknown
|
||||||
|
Loading…
Reference in New Issue
Block a user