Putting the name in GameManager rather than passing it from scene to scene.
authorDavid Négrier <d.negrier@thecodingmachine.com>
Sun, 3 May 2020 13:29:40 +0000 (15:29 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Sun, 3 May 2020 13:29:40 +0000 (15:29 +0200)
front/src/Phaser/Game/GameManager.ts
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/Game/GameSceneInitDataInterface.ts [deleted file]

index 1877b29a003c8fbf948ce8ee6a887306a48f9b7a..83e205ec171cf158a08d8ded3e5db6aad6825d99 100644 (file)
@@ -15,14 +15,16 @@ export class GameManager {
     status: number;
     private ConnexionInstance: Connexion;
     private currentGameScene: GameScene;
+    private playerName: string;
     SimplePeer : SimplePeerInterface;
 
     constructor() {
         this.status = StatusGameManagerEnum.IN_PROGRESS;
     }
-    
-    connect(email:string) {
-        this.ConnexionInstance = new Connexion(email, this);
+
+    connect(name:string) {
+        this.playerName = name;
+        this.ConnexionInstance = new Connexion(name, this);
         ConnexionInstance = this.ConnexionInstance;
         return this.ConnexionInstance.createConnexion().then(() => {
             this.SimplePeer = new SimplePeer(ConnexionInstance);
@@ -57,6 +59,10 @@ export class GameManager {
             console.error(e);
         }
     }
+
+    getPlayerName(): string {
+        return this.playerName;
+    }
 }
 
-export const gameManager = new GameManager();
\ No newline at end of file
+export const gameManager = new GameManager();
index f5a7728a4963a9684f07b92d898fd9434a2f2560..47499da6042767397f7189aeab95beca4d7129ed 100644 (file)
@@ -5,7 +5,6 @@ import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVa
 import Tile = Phaser.Tilemaps.Tile;
 import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
 import {cypressAsserter} from "../../Cypress/CypressAsserter";
-import { GameSceneInitDataInterface } from "./GameSceneInitDataInterface";
 
 export const GameSceneName = "GameScene";
 export enum Textures {
@@ -29,7 +28,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
     map: ITiledMap;
     startX = (window.innerWidth / 2) / RESOLUTION;
     startY = (window.innerHeight / 2) / RESOLUTION;
-    playerName: string;
 
 
     constructor() {
@@ -69,8 +67,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
     }
 
     //hook initialisation
-    init(data: GameSceneInitDataInterface) {
-        this.playerName = data.name;
+    init() {
     }
 
     //hook create scene
@@ -168,7 +165,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             this,
             this.startX,
             this.startY,
-            this.playerName
+            this.GameManager.getPlayerName()
         );
         this.CurrentPlayer.initAnimation();
 
diff --git a/front/src/Phaser/Game/GameSceneInitDataInterface.ts b/front/src/Phaser/Game/GameSceneInitDataInterface.ts
deleted file mode 100644 (file)
index 0014e1b..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-export interface GameSceneInitDataInterface {
-    name: string
-}