Removing dead code from previous messaging system
authorDavid Négrier <d.negrier@thecodingmachine.com>
Sun, 24 May 2020 21:27:32 +0000 (23:27 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Mon, 25 May 2020 20:36:44 +0000 (22:36 +0200)
Remvoing messages that were no more used in the new messaging system (the code used to handle the message that sent the position of all users on the front side)

front/src/Connection.ts
front/src/Phaser/Game/GameManager.ts
front/src/Phaser/Game/GameScene.ts

index 52d88da038f25c38e64d3d707a4fe49a6a8a2bde..99ff7bc3e16795a44c53aa6e9282cfc7616bc4d6 100644 (file)
@@ -134,8 +134,6 @@ export interface ConnectionInterface {
 
     sharePosition(x: number, y: number, direction: string, moving: boolean): void;
 
-    positionOfAllUser(): void;
-
     /*webrtc*/
     sendWebrtcSignal(signal: any, roomId: string, userId?: string, receiverId?: string): void;
 
@@ -187,7 +185,6 @@ export class Connection implements ConnectionInterface {
      */
     connectSocketServer(): Promise<ConnectionInterface>{
         //listen event
-        this.positionOfAllUser();
         this.disconnectServer();
         this.errorMessage();
         this.groupUpdatedOrCreated();
@@ -256,43 +253,19 @@ export class Connection implements ConnectionInterface {
         this.socket.emit(EventMessage.USER_POSITION, point);
     }
 
-    /**
-     * The data sent is an array with information for each user :
-     * [
-     * {
-     *       userId: <string>,
-     *       position: {
-     *           x : <number>,
-     *           y : <number>,
-     *           direction: <string>,
-     *           moving: <bool>
-     *       }
-     *     },
-     * ...
-     * ]
-     **/
-    positionOfAllUser(): void {
-        this.socket.on(EventMessage.USER_POSITION, (message: string) => {
-            let dataList = message;
-            let UserPositions : Array<any> = Object.values(dataList);
-            let listMessageUserPosition =  new ListMessageUserPosition(UserPositions[0], UserPositions[1]);
-            this.GameManager.shareUserPosition(listMessageUserPosition);
-        });
-    }
-
-    onUserJoins(): void {
+    private onUserJoins(): void {
         this.socket.on(EventMessage.JOIN_ROOM, (message: MessageUserJoined) => {
             this.GameManager.onUserJoins(message);
         });
     }
 
-    onUserMoved(): void {
+    private onUserMoved(): void {
         this.socket.on(EventMessage.USER_MOVED, (message: MessageUserMovedInterface) => {
             this.GameManager.onUserMoved(message);
         });
     }
 
-    onUserLeft(): void {
+    private onUserLeft(): void {
         this.socket.on(EventMessage.USER_LEFT, (userId: string) => {
             this.GameManager.onUserLeft(userId);
         });
@@ -328,13 +301,13 @@ export class Connection implements ConnectionInterface {
         return this.socket.on(EventMessage.WEBRTC_SIGNAL, callback);
     }
 
-    errorMessage(): void {
+    private errorMessage(): void {
         this.socket.on(EventMessage.MESSAGE_ERROR, (message: string) => {
             console.error(EventMessage.MESSAGE_ERROR, message);
         })
     }
 
-    disconnectServer(): void {
+    private disconnectServer(): void {
         this.socket.on(EventMessage.CONNECT_ERROR, () => {
             this.GameManager.switchToDisconnectedScene();
         });
index 1b1bd3370e3885ae260704f22fb303689bf6d991..1e582f4ba56fed0eeac275aa4e09e34b01224bf2 100644 (file)
@@ -98,22 +98,6 @@ export class GameManager {
         this.currentGameScene.removePlayer(userId);
     }
 
-    /**
-     * Share position in game
-     * @param ListMessageUserPosition
-     * @deprecated
-     */
-    shareUserPosition(ListMessageUserPosition: ListMessageUserPositionInterface): void {
-        if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
-            return;
-        }
-        try {
-            this.currentGameScene.shareUserPosition(ListMessageUserPosition.listUsersPosition)
-        } catch (e) {
-            console.error(e);
-        }
-    }
-
     initUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
         // Shall we wait for room to be loaded?
         /*if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
index dfaf376a2c7900b6399ed6f6f0fb97e4dd0e8b05..b7afed02a1442bbf6bac1119e3784730038c5b28 100644 (file)
@@ -362,49 +362,6 @@ export class GameScene extends Phaser.Scene {
         })
     }
 
-    /**
-     * Share position in scene
-     * @param UsersPosition
-     * @deprecated
-     */
-    shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
-        this.updateOrCreateMapPlayer(UsersPosition);
-    }
-
-    /**
-     * Create new player and clean the player on the map
-     * @param UsersPosition
-     */
-    updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
-        if(!this.CurrentPlayer){
-            return;
-        }
-
-        let currentPlayerId = this.GameManager.getPlayerId();
-
-        //add or create new user
-        UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
-            if(userPosition.userId === currentPlayerId){
-                return;
-            }
-            let player = this.findPlayerInMap(userPosition.userId);
-            if(!player){
-                this.addPlayer(userPosition);
-            }else{
-                player.updatePosition(userPosition.position);
-            }
-        });
-
-        //clean map
-        this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
-            if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
-                return;
-            }
-            player.destroy();
-            this.MapPlayers.remove(player);
-        });
-    }
-
     public initUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
         if(!this.CurrentPlayer){
             console.error('Cannot initiate users list because map is not loaded yet')