});
//if try to reconnect with last position
- if(this.lastRoom) {
+ /*if(this.lastRoom) {
//join the room
this.joinARoom(this.lastRoom,
this.lastPositionShared ? this.lastPositionShared.x : 0,
this.lastPositionShared ? this.lastPositionShared.y : 0,
this.lastPositionShared ? this.lastPositionShared.direction : PlayerAnimationNames.WalkDown,
this.lastPositionShared ? this.lastPositionShared.moving : false);
- }
+ }*/
/*if(this.lastPositionShared) {
disconnectServer(): void {
this.socket.on(EventMessage.CONNECT_ERROR, () => {
MessageUI.warningMessage("Trying to connect!");
+ this.GameManager.switchToDisconnectedScene();
});
this.socket.on(EventMessage.RECONNECT, () => {
MessageUI.removeMessage();
this.connectSocketServer();
+ this.GameManager.reconnectToGameScene(this.lastPositionShared);
});
}
import {
Connexion,
GroupCreatedUpdatedMessageInterface,
- ListMessageUserPositionInterface, MessageUserJoined, MessageUserMovedInterface, MessageUserPositionInterface, Point
+ ListMessageUserPositionInterface,
+ MessageUserJoined,
+ MessageUserMovedInterface,
+ MessageUserPositionInterface,
+ Point,
+ PointInterface
} from "../../Connexion";
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
import {getMapKeyByUrl} from "../Login/LogincScene";
import ScenePlugin = Phaser.Scenes.ScenePlugin;
import {AddPlayerInterface} from "./AddPlayerInterface";
+import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
export enum StatusGameManagerEnum {
IN_PROGRESS = 1,
}
return sceneKey;
}
+
+ private oldSceneKey : string;
+ switchToDisconnectedScene(): void {
+ this.oldSceneKey = this.currentGameScene.scene.key;
+ this.currentGameScene.scene.start(ReconnectingSceneName);
+ }
+
+ reconnectToGameScene(lastPositionShared: PointInterface) {
+ this.currentGameScene.scene.start(this.oldSceneKey, { initPosition: lastPositionShared });
+ }
}
export const gameManager = new GameManager();
GroupCreatedUpdatedMessageInterface,
MessageUserJoined,
MessageUserMovedInterface,
- MessageUserPositionInterface
+ MessageUserPositionInterface, PointInterface, PositionInterface
} from "../../Connexion";
import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
import { DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
Player = "male1"
}
+interface GameSceneInitInterface {
+ initPosition: PointInterface|null
+}
+
export class GameScene extends Phaser.Scene {
GameManager : GameManager;
Terrains : Array<Phaser.Tilemaps.Tileset>;
startX = 704;// 22 case
startY = 32; // 1 case
circleTexture: CanvasTexture;
+ initPosition: PositionInterface;
MapKey: string;
MapUrlFile: string;
}
//hook initialisation
- init() {}
+ init(initData : GameSceneInitInterface) {
+ this.initPosition = initData.initPosition;
+ }
//hook create scene
create(): void {
/**
* @param layer
*/
- private startUser(layer: ITiledMapLayer){
+ private startUser(layer: ITiledMapLayer): void {
+ if (this.initPosition !== undefined) {
+ this.startX = this.initPosition.x;
+ this.startY = this.initPosition.y;
+ return;
+ }
+
let tiles : any = layer.data;
tiles.forEach((objectKey : number, key: number) => {
if(objectKey === 0){
--- /dev/null
+import {gameManager} from "../Game/GameManager";
+import {TextField} from "../Components/TextField";
+import {TextInput} from "../Components/TextInput";
+import {ClickButton} from "../Components/ClickButton";
+import Image = Phaser.GameObjects.Image;
+import Rectangle = Phaser.GameObjects.Rectangle;
+import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
+import {cypressAsserter} from "../../Cypress/CypressAsserter";
+
+export const ReconnectingSceneName = "ReconnectingScene";
+enum ReconnectingTextures {
+ icon = "icon",
+ mainFont = "main_font"
+}
+
+export class ReconnectingScene extends Phaser.Scene {
+ private reconnectingField: TextField;
+ private logo: Image;
+
+ constructor() {
+ super({
+ key: ReconnectingSceneName
+ });
+ }
+
+ 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');
+ }
+
+ 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, 10, this.game.renderer.height - 35, "Connection lost. Reconnecting...");
+ }
+}
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
import {cypressAsserter} from "./Cypress/CypressAsserter";
import {LogincScene} from "./Phaser/Login/LogincScene";
+import {ReconnectingScene} from "./Phaser/Reconnecting/ReconnectingScene";
+import {gameManager} from "./Phaser/Game/GameManager";
const config: GameConfig = {
title: "Office game",
width: window.innerWidth / RESOLUTION,
height: window.innerHeight / RESOLUTION,
parent: "game",
- scene: [LogincScene],
+ scene: [LogincScene, ReconnectingScene],
zoom: RESOLUTION,
physics: {
default: "arcade",