Refactored and optimized messages
Now, when a user moves, only his/her position is sent back to the other users. The position of all users is not sent each time. The messages sent to the browser are now: - the list of all users as a return to the join_room event (you can send responses to events in socket.io) - a "join_room" event sent when a new user joins the room - a "user_moved" event when a user moved - a "user_left" event when a user left the room The GameScene tracks all these events and reacts accordingly. Also, I made a number of refactoring in the classes and removed the GameSceneInterface that was useless (it was implemented by the LogincScene for no reason at all)
This commit is contained in:
parent
1e6f9bb8d9
commit
125a4d11af
12 changed files with 238 additions and 101 deletions
5
back/src/Model/Websocket/MessageUserJoined.ts
Normal file
5
back/src/Model/Websocket/MessageUserJoined.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
export class MessageUserJoined {
|
||||
constructor(public userId: string, public name: string, public character: string) {
|
||||
}
|
||||
}
|
6
back/src/Model/Websocket/MessageUserMoved.ts
Normal file
6
back/src/Model/Websocket/MessageUserMoved.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import {PointInterface} from "./PointInterface";
|
||||
|
||||
export class MessageUserMoved {
|
||||
constructor(public userId: string, public position: PointInterface) {
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
export interface PointInterface {
|
||||
x: number;
|
||||
y: number;
|
||||
direction: string;
|
||||
readonly x: number;
|
||||
readonly y: number;
|
||||
readonly direction: string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue