Merge pull request #122 from thecodingmachine/reconnecting_scene
[libreadventure.git] / front / src / Phaser / Game / GameScene.ts
index 9aa6ece74fde137a299ec7d4f972a5cf602ce9e5..2ec6ea13f445890cf42f9c594c91931593a7e4bb 100644 (file)
@@ -1,12 +1,11 @@
-import {GameManager, gameManager, HasMovedEvent, MapObject, StatusGameManagerEnum} from "./GameManager";
+import {GameManager, gameManager, HasMovedEvent} from "./GameManager";
 import {
     GroupCreatedUpdatedMessageInterface,
-    MessageUserJoined,
     MessageUserMovedInterface,
     MessageUserPositionInterface, PointInterface, PositionInterface
 } from "../../Connexion";
 import {CurrentGamerInterface, GamerInterface, hasMovedEventName, Player} from "../Player/Player";
-import { DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
+import { DEBUG_MODE, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
 import {ITiledMap, ITiledMapLayer, ITiledTileSet} from "../Map/ITiledMap";
 import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
 import Texture = Phaser.Textures.Texture;
@@ -423,6 +422,14 @@ export class GameScene extends Phaser.Scene {
      * Create new player
      */
     public addPlayer(addPlayerData : AddPlayerInterface) : void{
+        //check if exist player, if exist, move position
+        if(this.MapPlayersByKey.has(addPlayerData.userId)){
+            this.updatePlayerPosition({
+                userId: addPlayerData.userId,
+                position: addPlayerData.position
+            });
+            return;
+        }
         //initialise player
         let player = new Player(
             addPlayerData.userId,