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:
David Négrier 2020-05-19 19:11:12 +02:00
parent 1e6f9bb8d9
commit 125a4d11af
12 changed files with 238 additions and 101 deletions

View file

@ -1,6 +1,6 @@
import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "./Animation";
import {GameSceneInterface, Textures} from "../Game/GameScene";
import {MessageUserPositionInterface} from "../../Connexion";
import {GameScene, Textures} from "../Game/GameScene";
import {MessageUserPositionInterface, PointInterface} from "../../Connexion";
import {ActiveEventList, UserInputEvent, UserInputManager} from "../UserInput/UserInputManager";
import {PlayableCaracter} from "../Entity/PlayableCaracter";
@ -15,7 +15,7 @@ export interface CurrentGamerInterface extends PlayableCaracter{
export interface GamerInterface extends PlayableCaracter{
userId : string;
initAnimation() : void;
updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
updatePosition(position: PointInterface): void;
say(text : string) : void;
}
@ -26,7 +26,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
constructor(
userId: string,
Scene: GameSceneInterface,
Scene: GameScene,
x: number,
y: number,
name: string,
@ -96,10 +96,10 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
}
//todo: put this method into the NonPlayer class instead
updatePosition(MessageUserPosition: MessageUserPositionInterface) {
playAnimation(this, MessageUserPosition.position.direction);
this.setX(MessageUserPosition.position.x);
this.setY(MessageUserPosition.position.y);
this.setDepth(MessageUserPosition.position.y);
updatePosition(position: PointInterface): void {
playAnimation(this, position.direction);
this.setX(position.x);
this.setY(position.y);
this.setDepth(position.y);
}
}