When sharing user position, only position is sent now!
This commit is contained in:
parent
cdfa9acf01
commit
4d1c3517ec
5 changed files with 40 additions and 55 deletions
|
@ -149,7 +149,7 @@ export class Connexion implements ConnexionInterface {
|
|||
|
||||
GameManager: GameManager;
|
||||
|
||||
lastPositionShared: MessageUserPosition = null;
|
||||
lastPositionShared: PointInterface = null;
|
||||
lastRoom: string|null = null;
|
||||
|
||||
constructor(GameManager: GameManager) {
|
||||
|
@ -185,26 +185,6 @@ export class Connexion implements ConnexionInterface {
|
|||
* @param character
|
||||
*/
|
||||
connectSocketServer(): Promise<ConnexionInterface>{
|
||||
//if try to reconnect with last position
|
||||
if(this.lastRoom) {
|
||||
//join the room
|
||||
this.joinARoom(
|
||||
this.lastRoom
|
||||
);
|
||||
}
|
||||
|
||||
if(this.lastPositionShared) {
|
||||
|
||||
//share your first position
|
||||
this.sharePosition(
|
||||
this.lastPositionShared ? this.lastPositionShared.position.x : 0,
|
||||
this.lastPositionShared ? this.lastPositionShared.position.y : 0,
|
||||
this.lastPositionShared.character,
|
||||
this.lastPositionShared.roomId,
|
||||
this.lastPositionShared.position.direction
|
||||
);
|
||||
}
|
||||
|
||||
//listen event
|
||||
this.positionOfAllUser();
|
||||
this.disconnectServer();
|
||||
|
@ -219,6 +199,25 @@ export class Connexion implements ConnexionInterface {
|
|||
} as SetPlayerDetailsMessage, (id: string) => {
|
||||
this.userId = id;
|
||||
});
|
||||
|
||||
//if try to reconnect with last position
|
||||
if(this.lastRoom) {
|
||||
//join the room
|
||||
this.joinARoom(
|
||||
this.lastRoom
|
||||
);
|
||||
}
|
||||
|
||||
if(this.lastPositionShared) {
|
||||
|
||||
//share your first position
|
||||
this.sharePosition(
|
||||
this.lastPositionShared ? this.lastPositionShared.x : 0,
|
||||
this.lastPositionShared ? this.lastPositionShared.y : 0,
|
||||
this.lastPositionShared.direction
|
||||
);
|
||||
}
|
||||
|
||||
resolve(this);
|
||||
});
|
||||
}
|
||||
|
@ -252,19 +251,13 @@ export class Connexion implements ConnexionInterface {
|
|||
* @param roomId
|
||||
* @param direction
|
||||
*/
|
||||
sharePosition(x : number, y : number, character : string, roomId : string, direction : string = "none") : void{
|
||||
sharePosition(x : number, y : number, direction : string = "none") : void{
|
||||
if(!this.socket){
|
||||
return;
|
||||
}
|
||||
let messageUserPosition = new MessageUserPosition(
|
||||
this.userId,
|
||||
roomId,
|
||||
new Point(x, y, direction),
|
||||
this.name,
|
||||
character
|
||||
);
|
||||
this.lastPositionShared = messageUserPosition;
|
||||
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition);
|
||||
let point = new Point(x, y, direction);
|
||||
this.lastPositionShared = point;
|
||||
this.socket.emit(EventMessage.USER_POSITION, point);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,6 @@ export interface HasMovedEvent {
|
|||
direction: string;
|
||||
x: number;
|
||||
y: number;
|
||||
character: string;
|
||||
}
|
||||
|
||||
export interface MapObject {
|
||||
|
@ -71,8 +70,8 @@ export class GameManager {
|
|||
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
||||
}
|
||||
|
||||
joinRoom(sceneKey : string, character: string){
|
||||
this.ConnexionInstance.joinARoom(sceneKey, character);
|
||||
joinRoom(sceneKey : string){
|
||||
this.ConnexionInstance.joinARoom(sceneKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,7 +127,7 @@ export class GameManager {
|
|||
}
|
||||
|
||||
pushPlayerPosition(event: HasMovedEvent) {
|
||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.character, this.currentGameScene.scene.key, event.direction);
|
||||
this.ConnexionInstance.sharePosition(event.x, event.y, event.direction);
|
||||
}
|
||||
|
||||
loadMap(mapUrl: string, scene: ScenePlugin): string {
|
||||
|
|
|
@ -284,7 +284,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
|
|||
this.createCollisionObject();
|
||||
|
||||
//join room
|
||||
this.GameManager.joinRoom(this.scene.key, this.CurrentPlayer.PlayerTexture);
|
||||
this.GameManager.joinRoom(this.scene.key);
|
||||
|
||||
//listen event to share position of user
|
||||
this.CurrentPlayer.on(hasMovedEventName, this.pushPlayerPosition.bind(this))
|
||||
|
|
|
@ -81,12 +81,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, character: this.PlayerTexture});
|
||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
|
||||
} else {
|
||||
if (this.previousMove !== PlayerAnimationNames.None) {
|
||||
direction = PlayerAnimationNames.None;
|
||||
this.stop();
|
||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y, character: this.PlayerTexture});
|
||||
this.emit(hasMovedEventName, {direction, x: this.x, y: this.y});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue