From f5dd5efc0ea92c6a2e261c890581919d2e214caf Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Fri, 18 Dec 2020 13:56:25 +0100 Subject: [PATCH 1/3] Manage Local Storage customers player error --- front/src/Phaser/Entity/Character.ts | 8 ++++++-- front/src/Phaser/Game/GameScene.ts | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/front/src/Phaser/Entity/Character.ts b/front/src/Phaser/Entity/Character.ts index a1ed30d5..13d0b637 100644 --- a/front/src/Phaser/Entity/Character.ts +++ b/front/src/Phaser/Entity/Character.ts @@ -106,7 +106,9 @@ export abstract class Character extends Container { }); }) // Needed, otherwise, animations are not handled correctly. - this.scene.sys.updateList.add(sprite); + if(this.scene) { + this.scene.sys.updateList.add(sprite); + } this.sprites.set(texture, sprite); } } @@ -229,7 +231,9 @@ export abstract class Character extends Container { this.scene.events.removeListener('postupdate', this.postupdate.bind(this)); } for (const sprite of this.sprites.values()) { - this.scene.sys.updateList.remove(sprite); + if(this.scene) { + this.scene.sys.updateList.remove(sprite); + } } super.destroy(fromScene); this.playerName.destroy(); diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index a5248ff7..8ac7ef85 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -63,6 +63,7 @@ import {urlManager} from "../../Url/UrlManager"; import {PresentationModeIcon} from "../Components/PresentationModeIcon"; import {ChatModeIcon} from "../Components/ChatModeIcon"; import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon"; +import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene"; export interface GameSceneInitInterface { initPosition: PointInterface|null, @@ -375,7 +376,13 @@ export class GameScene extends ResizableScene implements CenterListener { mediaManager.setUserInputManager(this.userInputManager); //notify game manager can to create currentUser in map - this.createCurrentPlayer(); + try { + this.createCurrentPlayer(); + }catch (err){ + //permit to return on character custom if any there any changes frame in the new version + gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); + throw 'characterLayers are not invalid'; + } //initialise camera this.initCamera(); @@ -670,8 +677,12 @@ export class GameScene extends ResizableScene implements CenterListener { public cleanupClosingScene(): void { // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. - this.connection.closeConnection(); - this.simplePeer.unregister(); + if(this.connection) { + this.connection.closeConnection(); + } + if(this.simplePeer) { + this.simplePeer.unregister(); + } } private switchLayoutMode(): void { From 323fa6abba3f98afc94112d6776409994f26290e Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Fri, 18 Dec 2020 14:30:46 +0100 Subject: [PATCH 2/3] Create exception error --- front/src/Exception/TextureError.ts | 1 + front/src/Phaser/Entity/Character.ts | 9 +++---- front/src/Phaser/Game/GameScene.ts | 36 +++++++++++++++------------- 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 front/src/Exception/TextureError.ts diff --git a/front/src/Exception/TextureError.ts b/front/src/Exception/TextureError.ts new file mode 100644 index 00000000..39a339f6 --- /dev/null +++ b/front/src/Exception/TextureError.ts @@ -0,0 +1 @@ +export class TextureError extends Error{} \ No newline at end of file diff --git a/front/src/Phaser/Entity/Character.ts b/front/src/Phaser/Entity/Character.ts index 13d0b637..5c89447e 100644 --- a/front/src/Phaser/Entity/Character.ts +++ b/front/src/Phaser/Entity/Character.ts @@ -3,6 +3,7 @@ import {SpeechBubble} from "./SpeechBubble"; import BitmapText = Phaser.GameObjects.BitmapText; import Container = Phaser.GameObjects.Container; import Sprite = Phaser.GameObjects.Sprite; +import {TextureError} from "../../Exception/TextureError"; export interface PlayerResourceDescriptionInterface { name: string, @@ -94,6 +95,9 @@ export abstract class Character extends Container { public addTextures(textures: string[], frame?: string | number): void { for (const texture of textures) { + if(!this.scene.textures.exists(texture)){ + throw new TextureError('texture not found'); + } const sprite = new Sprite(this.scene, 0, 0, texture, frame); sprite.setInteractive({useHandCursor: true}); this.add(sprite); @@ -154,10 +158,7 @@ export abstract class Character extends Container { if (moving && (!sprite.anims.currentAnim || sprite.anims.currentAnim.key !== direction)) { sprite.play(texture+'-'+direction, true); } else if (!moving) { - /*if (this.anims.currentAnim) { - this.anims.stop(); - }*/ - sprite.play(texture+'-'+direction, true); + sprite.anims.play(texture + '-' + direction, true); sprite.anims.stop(); } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 8ac7ef85..8dbbea8c 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -64,6 +64,7 @@ import {PresentationModeIcon} from "../Components/PresentationModeIcon"; import {ChatModeIcon} from "../Components/ChatModeIcon"; import {OpenChatIcon, openChatIconName} from "../Components/OpenChatIcon"; import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCharacterScene"; +import {TextureError} from "../../Exception/TextureError"; export interface GameSceneInitInterface { initPosition: PointInterface|null, @@ -376,13 +377,7 @@ export class GameScene extends ResizableScene implements CenterListener { mediaManager.setUserInputManager(this.userInputManager); //notify game manager can to create currentUser in map - try { - this.createCurrentPlayer(); - }catch (err){ - //permit to return on character custom if any there any changes frame in the new version - gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); - throw 'characterLayers are not invalid'; - } + this.createCurrentPlayer(); //initialise camera this.initCamera(); @@ -829,16 +824,23 @@ export class GameScene extends ResizableScene implements CenterListener { createCurrentPlayer(){ //initialise player //TODO create animation moving between exit and start - this.CurrentPlayer = new Player( - this, - this.startX, - this.startY, - this.playerName, - this.characterLayers, - PlayerAnimationNames.WalkDown, - false, - this.userInputManager - ); + try { + this.CurrentPlayer = new Player( + this, + this.startX, + this.startY, + this.playerName, + this.characterLayers, + PlayerAnimationNames.WalkDown, + false, + this.userInputManager + ); + }catch (err){ + if(err instanceof TextureError) { + gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); + throw err; + } + } //create collision this.createCollisionWithPlayer(); From a1fd209578344e11c58cfa40b44c8f616378f0e0 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Fri, 18 Dec 2020 16:30:22 +0100 Subject: [PATCH 3/3] Fix catch error --- front/src/Phaser/Game/GameScene.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 8dbbea8c..89fb03bd 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -838,8 +838,8 @@ export class GameScene extends ResizableScene implements CenterListener { }catch (err){ if(err instanceof TextureError) { gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); - throw err; } + throw err; } //create collision