Cleanup: renaming "frame" to "character"
authorDavid Négrier <d.negrier@thecodingmachine.com>
Fri, 8 May 2020 13:18:22 +0000 (15:18 +0200)
committerDavid Négrier <d.negrier@thecodingmachine.com>
Fri, 8 May 2020 13:18:22 +0000 (15:18 +0200)
The "frame" variable actually contains a string pointing to the character selected.
It has nothing to do with a frame which is usually a particular image in an animation.

I'm renaming the variable accross the application to avoid confusion.

back/src/Controller/IoSocketController.ts
back/src/Model/Websocket/ExSocketInterface.ts
back/src/Model/Websocket/ExtRoom.ts
back/src/Model/Websocket/Message.ts
back/tests/MessageTest.ts
front/src/Connexion.ts
front/src/Phaser/Game/GameManager.ts
front/src/Phaser/Game/GameScene.ts
front/src/Phaser/Player/Player.ts

index 64012349b5b3d996a625d1605bf9400b77f8dd4d..c37165bb896f307a5eddfc5dd2cd9bca57a81d4e 100644 (file)
@@ -216,7 +216,7 @@ export class IoSocketController {
         socket.roomId = message.roomId;
         socket.userId = message.userId;
         socket.name = message.name;
-        socket.frame = message.frame;
+        socket.character = message.character;
     }
 
     refreshUserPosition() {
index 7798509b1e062654a2d25051036576c9b875964f..22cd29c2dfdaa65534c43843ad4e96396acab85d 100644 (file)
@@ -7,6 +7,6 @@ export interface ExSocketInterface extends Socket {
     webRtcRoomId: string;
     userId: string;
     name: string;
-    frame: string;
+    character: string;
     position: PointInterface;
-}
\ No newline at end of file
+}
index a1b2cb6579997ca524bafd7dd676bb643975aef7..723fff0b5da59d28650871abe21972a8a6b8398f 100644 (file)
@@ -25,7 +25,7 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
             roomId: socket.roomId,
             position: socket.position,
             name: socket.name,
-            frame: socket.frame,
+            character: socket.character,
         };
         let dataArray = <any>[];
         if (mapPositionUserByRoom.get(data.roomId)) {
@@ -41,4 +41,4 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
 
 export {
     RefreshUserPositionFunction
-}
\ No newline at end of file
+}
index 16589e3b306212ca45cbe0d084b468d69defa3ff..20df9801946c84a12c1beb9d5bd4dbd279ca09ac 100644 (file)
@@ -2,7 +2,7 @@ export class Message {
     userId: string;
     roomId: string;
     name: string;
-    frame: string;
+    character: string;
 
     constructor(data: any) {
         if (!data.userId || !data.roomId) {
@@ -11,7 +11,7 @@ export class Message {
         this.userId = data.userId;
         this.roomId = data.roomId;
         this.name = data.name;
-        this.frame = data.frame;
+        this.character = data.character;
     }
 
     toJson() {
@@ -19,7 +19,7 @@ export class Message {
             userId: this.userId,
             roomId: this.roomId,
             name: this.name,
-            frame: this.frame
+            character: this.character
         }
     }
-}
\ No newline at end of file
+}
index 47e4cac1beafc324a44c4c41d7f966932dd99fa8..71a79e67ce18b0936f1e7a19b8ab87474d2dbe83 100644 (file)
@@ -8,7 +8,7 @@ describe("Message Model", () => {
         expect(messageObject.userId).toBe("test1");
         expect(messageObject.roomId).toBe("test2");
         expect(messageObject.name).toBe("foo");
-        expect(messageObject.frame).toBe("user");
+        expect(messageObject.character).toBe("user");
     })
 
     it("should expose a toJson method", () => {
@@ -37,4 +37,4 @@ describe("Message Model", () => {
             let messageObject = new Message(message);
         }).toThrow(new Error("userId or roomId cannot be null"));
     });
-})
\ No newline at end of file
+})
index 4dfddee1d7e77e9c98ea74e715f9dad51f45b520..315c67a93296fdbf4dd23491316d1b5df9559d13 100644 (file)
@@ -18,13 +18,13 @@ class Message {
     userId: string;
     roomId: string;
     name: string;
-    frame: string;
+    character: string;
 
-    constructor(userId : string, roomId : string, name: string, frame: string) {
+    constructor(userId : string, roomId : string, name: string, character: string) {
         this.userId = userId;
         this.roomId = roomId;
         this.name = name;
-        this.frame = frame;
+        this.character = character;
     }
 
     toJson() {
@@ -32,7 +32,7 @@ class Message {
             userId: this.userId,
             roomId: this.roomId,
             name: this.name,
-            frame: this.frame
+            character: this.character
         }
     }
 }
@@ -71,15 +71,15 @@ export interface MessageUserPositionInterface {
     userId: string;
     roomId: string;
     name: string;
-    frame: string;
+    character: string;
     position: PointInterface;
 }
 
 class MessageUserPosition extends Message implements MessageUserPositionInterface{
     position: PointInterface;
 
-    constructor(userId : string, roomId : string, point : Point, name: string, frame: string) {
-        super(userId, roomId, name, frame);
+    constructor(userId : string, roomId : string, point : Point, name: string, character: string) {
+        super(userId, roomId, name, character);
         this.position = point;
     }
 
@@ -116,7 +116,7 @@ class ListMessageUserPosition {
                     userPosition.position.direction
                 ),
                 userPosition.name,
-                userPosition.frame
+                userPosition.character
             ));
         });
     }
@@ -129,11 +129,11 @@ export interface ConnexionInterface {
     userId: string;
     startedRoom: string;
 
-    createConnexion(frameSelected: string): Promise<any>;
+    createConnexion(characterSelected: string): Promise<any>;
 
-    joinARoom(roomId: string, frame: string): void;
+    joinARoom(roomId: string, character: string): void;
 
-    sharePosition(x: number, y: number, direction: string, frame: string): void;
+    sharePosition(x: number, y: number, direction: string, character: string): void;
 
     positionOfAllUser(): void;
 
@@ -161,7 +161,7 @@ export class Connexion implements ConnexionInterface {
         this.GameManager = GameManager;
     }
 
-    createConnexion(frameSelected: string): Promise<ConnexionInterface> {
+    createConnexion(characterSelected: string): Promise<ConnexionInterface> {
         return Axios.post(`${API_URL}/login`, {email: this.email})
             .then((res) => {
                 this.token = res.data.token;
@@ -175,10 +175,10 @@ export class Connexion implements ConnexionInterface {
                 });
 
                 //join the room
-                this.joinARoom(this.startedRoom, frameSelected);
+                this.joinARoom(this.startedRoom, characterSelected);
 
                 //share your first position
-                this.sharePosition(0, 0, frameSelected);
+                this.sharePosition(0, 0, characterSelected);
 
                 this.positionOfAllUser();
 
@@ -195,15 +195,15 @@ export class Connexion implements ConnexionInterface {
     /**
      *
      * @param roomId
-     * @param frame
+     * @param character
      */
-    joinARoom(roomId: string, frame: string): void {
+    joinARoom(roomId: string, character: string): void {
         let messageUserPosition = new MessageUserPosition(
             this.userId,
             this.startedRoom,
             new Point(0, 0),
             this.email,
-            frame
+            character
         );
         this.socket.emit(EventMessage.JOIN_ROOM, messageUserPosition.toString());
     }
@@ -212,10 +212,10 @@ export class Connexion implements ConnexionInterface {
      *
      * @param x
      * @param y
-     * @param frame
+     * @param character
      * @param direction
      */
-    sharePosition(x : number, y : number, frame : string, direction : string = "none") : void{
+    sharePosition(x : number, y : number, character : string, direction : string = "none") : void{
         if(!this.socket){
             return;
         }
@@ -224,7 +224,7 @@ export class Connexion implements ConnexionInterface {
             ROOM[0],
             new Point(x, y, direction),
             this.email,
-            frame
+            character
         );
         this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
     }
@@ -280,4 +280,4 @@ export class Connexion implements ConnexionInterface {
     disconnectMessage(callback: Function): void {
         this.socket.on(EventMessage.WEBRTC_DISCONNECT, callback);
     }
-}
\ No newline at end of file
+}
index 4cc95c2a0661079b16441d9aaff573b08965c817..dd3d6e58af289d7e252f24fb324ab593ab03d8ec 100644 (file)
@@ -13,7 +13,7 @@ export interface HasMovedEvent {
     direction: string;
     x: number;
     y: number;
-    frame: string;
+    character: string;
 }
 
 export class GameManager {
@@ -22,17 +22,17 @@ export class GameManager {
     private currentGameScene: GameScene;
     private playerName: string;
     SimplePeer : SimplePeerInterface;
-    private frameUserSelected: string;
+    private characterUserSelected: string;
 
     constructor() {
         this.status = StatusGameManagerEnum.IN_PROGRESS;
     }
 
-    connect(name: string, frameUserSelected : string) {
+    connect(name: string, characterUserSelected : string) {
         this.playerName = name;
-        this.frameUserSelected = frameUserSelected;
+        this.characterUserSelected = characterUserSelected;
         this.ConnexionInstance = new Connexion(name, this);
-        return this.ConnexionInstance.createConnexion(frameUserSelected).then(() => {
+        return this.ConnexionInstance.createConnexion(characterUserSelected).then(() => {
             this.SimplePeer = new SimplePeer(this.ConnexionInstance);
         });
     }
@@ -70,12 +70,12 @@ export class GameManager {
         return this.playerName;
     }
 
-    getFrameSelected(): string {
-        return this.frameUserSelected;
+    getCharacterSelected(): string {
+        return this.characterUserSelected;
     }
 
     pushPlayerPosition(event: HasMovedEvent) {
-        this.ConnexionInstance.sharePosition(event.x, event.y, event.frame, event.direction);
+        this.ConnexionInstance.sharePosition(event.x, event.y, event.character, event.direction);
     }
 }
 
index f449f0766117a4916d25388e3cf797c7b3571a49..c506dadb421a9d281d4697a40218323939967caa 100644 (file)
@@ -167,7 +167,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             this.startX,
             this.startY,
             this.GameManager.getPlayerName(),
-            this.GameManager.getFrameSelected()
+            this.GameManager.getCharacterSelected()
         );
         this.CurrentPlayer.initAnimation();
 
@@ -261,15 +261,15 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
             MessageUserPosition.position.x,
             MessageUserPosition.position.y,
             MessageUserPosition.name,
-            MessageUserPosition.frame
+            MessageUserPosition.character
         );
         player.initAnimation();
         this.MapPlayers.add(player);
         player.updatePosition(MessageUserPosition);
 
-        //init colision
-        this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
+        //init collision
+        /*this.physics.add.collider(this.CurrentPlayer, player, (CurrentPlayer: CurrentGamerInterface, MapPlayer: GamerInterface) => {
             CurrentPlayer.say("Hello, how are you ? ");
-        });
+        });*/
     }
 }
index 4dbda5bb46691bb3cfdb6477ec239f914ae5e078..572dcd8e91845ac824065c17a4f6c27345f7a635 100644 (file)
@@ -83,12 +83,12 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
         }
         if (x !== 0 || y !== 0) {
             this.move(x, y);
-            this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, frame: this.PlayerTexture});
+            this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, character: this.PlayerTexture});
         } else {
             if (this.previousMove !== PlayerAnimationNames.None) {
                 direction = PlayerAnimationNames.None;
                 this.stop();
-                this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, frame: this.PlayerTexture});
+                this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, character: this.PlayerTexture});
             }
         }