From 1f7f94ea9c35011456b5f2df932ca65c0170dfd0 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Wed, 4 Nov 2020 12:39:28 +0100 Subject: [PATCH] Feedback review MR - Extend the ResizableScene instead. - Remove ErrorScene - Add git ignore --- front/dist/.gitignore | 1 + front/src/Phaser/Game/GameScene.ts | 22 ++++++++--- .../{WaitScene.ts => ErrorScene.ts} | 37 ++++++++++--------- 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 front/dist/.gitignore rename front/src/Phaser/Reconnecting/{WaitScene.ts => ErrorScene.ts} (65%) diff --git a/front/dist/.gitignore b/front/dist/.gitignore new file mode 100644 index 00000000..20b097e9 --- /dev/null +++ b/front/dist/.gitignore @@ -0,0 +1 @@ +tests/* \ No newline at end of file diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index b46551ec..80648dd2 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -55,7 +55,7 @@ import {ResizableScene} from "../Login/ResizableScene"; import {Room} from "../../Connexion/Room"; import {jitsiFactory} from "../../WebRtc/JitsiFactory"; import {MessageUI} from "../../Logger/MessageUI"; -import {WaitScene} from "../Reconnecting/WaitScene"; +import {ErrorScene} from "../Reconnecting/ErrorScene"; export enum Textures { @@ -610,9 +610,6 @@ 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(); @@ -620,7 +617,11 @@ export class GameScene extends ResizableScene implements CenterListener { const waitGameSceneKey = 'somekey' + Math.round(Math.random() * 10000); //show wait scene setTimeout(() => { - const game: Phaser.Scene = new WaitScene(waitGameSceneKey, status); + /** + * Note: the ErrorScene could then become a singleton. In the future, + * an error message could originate from the server directly. + * **/ + const game: Phaser.Scene = new ErrorScene(waitGameSceneKey); this.scene.add(waitGameSceneKey, game, true, { initPosition: { x: this.CurrentPlayer.x, @@ -628,7 +629,16 @@ export class GameScene extends ResizableScene implements CenterListener { } }); this.scene.stop(this.scene.key); - this.scene.start(waitGameSceneKey); + this.scene.start(waitGameSceneKey, { + status: status, + text : 'Oups! Work Adventure is too popular, ' + + '\n' + + '\n' + + 'the maximum number of players has been reached!' + + '\n' + + '\n' + + `Reconnect in 30 secondes ...` + }); }, 500); //trying to reload map diff --git a/front/src/Phaser/Reconnecting/WaitScene.ts b/front/src/Phaser/Reconnecting/ErrorScene.ts similarity index 65% rename from front/src/Phaser/Reconnecting/WaitScene.ts rename to front/src/Phaser/Reconnecting/ErrorScene.ts index 0d4df895..53080c55 100644 --- a/front/src/Phaser/Reconnecting/WaitScene.ts +++ b/front/src/Phaser/Reconnecting/ErrorScene.ts @@ -1,36 +1,28 @@ import {TextField} from "../Components/TextField"; import Image = Phaser.GameObjects.Image; +import {ResizableScene} from "../Login/ResizableScene"; enum ReconnectingTextures { icon = "icon", mainFont = "main_font" } -export class WaitScene extends Phaser.Scene { +export class ErrorScene extends ResizableScene { private reconnectingField!: TextField; + private catImage!: Phaser.Physics.Arcade.Sprite; private logo!: Image; private text: string = ''; + private status: number = 404; - constructor(key: string, private readonly status: number) { + constructor(key: string) { 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; - } + init(data: {status: number, text: string}){ + this.text = data.text; + this .status = data.status; } preload() { @@ -54,7 +46,7 @@ export class WaitScene extends Phaser.Scene { this.game.renderer.height / 2, this.text); - const cat = this.physics.add.sprite( + this.catImage = this.physics.add.sprite( this.game.renderer.width / 2, this.game.renderer.height / 2 - 70, 'cat'); @@ -65,6 +57,15 @@ export class WaitScene extends Phaser.Scene { frameRate: 10, repeat: -1 }); - cat.play('right'); + this.catImage.play('right'); + } + + onResize(){ + this.reconnectingField.x = this.game.renderer.width / 2; + this.reconnectingField.y = this.game.renderer.height / 2; + this.catImage.x = this.game.renderer.width / 2; + this.catImage.y = this.game.renderer.height / 2 - 70; + this.logo.x = this.game.renderer.width - 30; + this.logo.y = this.game.renderer.height - 30; } }