Redirect user on wait scene
- Create wait scene - Load wait scne with status close message
This commit is contained in:
parent
7ac4a2b849
commit
f9bb749c56
5 changed files with 121 additions and 21 deletions
|
@ -97,8 +97,7 @@ class ConnectionManager {
|
|||
return new Promise<RoomConnection>((resolve, reject) => {
|
||||
const connection = new RoomConnection(this.localUser.jwtToken, roomId, name, characterLayers, position, viewport);
|
||||
connection.onConnectError((error: object) => {
|
||||
console.log(error);
|
||||
if (false) { //todo: how to check error type?
|
||||
if (error) { //todo: how to check error type?
|
||||
reject(connexionErrorTypes.tooManyUsers);
|
||||
} else {
|
||||
reject(connexionErrorTypes.serverError);
|
||||
|
|
|
@ -56,6 +56,7 @@ import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMes
|
|||
import {ResizableScene} from "../Login/ResizableScene";
|
||||
import {Room} from "../../Connexion/Room";
|
||||
import {MessageUI} from "../../Logger/MessageUI";
|
||||
import {WaitScene} from "../Reconnecting/WaitScene";
|
||||
|
||||
|
||||
export enum Textures {
|
||||
|
@ -620,7 +621,32 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
|
||||
connection.onCloseMessage((status: number) => {
|
||||
console.log(`close message status : ${status}`);
|
||||
|
||||
//TODO show wait room
|
||||
this.connection.closeConnection();
|
||||
this.simplePeer.unregister();
|
||||
connection.closeConnection();
|
||||
|
||||
const waitGameSceneKey = 'somekey' + Math.round(Math.random() * 10000);
|
||||
//show wait scene
|
||||
setTimeout(() => {
|
||||
const game: Phaser.Scene = new WaitScene(waitGameSceneKey, status);
|
||||
this.scene.add(waitGameSceneKey, game, true, {
|
||||
initPosition: {
|
||||
x: this.CurrentPlayer.x,
|
||||
y: this.CurrentPlayer.y
|
||||
}
|
||||
});
|
||||
this.scene.stop(this.scene.key);
|
||||
this.scene.start(waitGameSceneKey);
|
||||
}, 500);
|
||||
|
||||
//trying to reload map
|
||||
setTimeout(() => {
|
||||
this.scene.stop(waitGameSceneKey);
|
||||
this.scene.remove(waitGameSceneKey);
|
||||
this.scene.start(this.scene.key);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
// When connection is performed, let's connect SimplePeer
|
||||
|
@ -1168,6 +1194,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
const positionX = 48;
|
||||
const positionY = 48;
|
||||
|
||||
console.log('doShareGroupPosition', groupSize);
|
||||
let texture = 'circleSprite-red';
|
||||
if(groupSize < 4){
|
||||
texture = 'circleSprite-white';
|
||||
|
|
70
front/src/Phaser/Reconnecting/WaitScene.ts
Normal file
70
front/src/Phaser/Reconnecting/WaitScene.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import {TextField} from "../Components/TextField";
|
||||
import Image = Phaser.GameObjects.Image;
|
||||
|
||||
enum ReconnectingTextures {
|
||||
icon = "icon",
|
||||
mainFont = "main_font"
|
||||
}
|
||||
|
||||
export class WaitScene extends Phaser.Scene {
|
||||
private reconnectingField!: TextField;
|
||||
private logo!: Image;
|
||||
private text: string = '';
|
||||
|
||||
constructor(key: string, private readonly status: number) {
|
||||
super({
|
||||
key: key
|
||||
});
|
||||
this.initialiseText();
|
||||
}
|
||||
|
||||
initialiseText() {
|
||||
this.text = `${this.status}` + '\n' + '\n';
|
||||
switch (this.status) {
|
||||
case 302:
|
||||
this.text += 'Aie ! Work Adventure est victime de son succes, ' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
'le nombre maximum de joueurs a ete atteint !' +
|
||||
'\n' +
|
||||
'\n' +
|
||||
`Reconnexion dans 30 secondes ...`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
preload() {
|
||||
this.load.image(ReconnectingTextures.icon, "resources/logos/tcm_full.png");
|
||||
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
||||
this.load.bitmapFont(ReconnectingTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
||||
this.load.spritesheet(
|
||||
'cat',
|
||||
'resources/characters/pipoya/Cat 01-1.png',
|
||||
{frameWidth: 32, frameHeight: 32}
|
||||
);
|
||||
}
|
||||
|
||||
create() {
|
||||
this.logo = new Image(this, this.game.renderer.width - 30, this.game.renderer.height - 20, ReconnectingTextures.icon);
|
||||
this.add.existing(this.logo);
|
||||
|
||||
this.reconnectingField = new TextField(
|
||||
this,
|
||||
this.game.renderer.width / 2,
|
||||
this.game.renderer.height / 2,
|
||||
this.text);
|
||||
|
||||
const cat = this.physics.add.sprite(
|
||||
this.game.renderer.width / 2,
|
||||
this.game.renderer.height / 2 - 70,
|
||||
'cat');
|
||||
|
||||
this.anims.create({
|
||||
key: 'right',
|
||||
frames: this.anims.generateFrameNumbers('cat', {start: 6, end: 8}),
|
||||
frameRate: 10,
|
||||
repeat: -1
|
||||
});
|
||||
cat.play('right');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue