Fix update world back end and deleting group in front end

This commit is contained in:
gparant 2020-05-11 13:17:02 +02:00
parent 89c22e9964
commit e35c188854
3 changed files with 27 additions and 18 deletions

View File

@ -109,7 +109,7 @@ export class IoSocketController {
this.saveUserInformation(Client, messageUserPosition); this.saveUserInformation(Client, messageUserPosition);
//add function to refresh position user in real time. //add function to refresh position user in real time.
this.refreshUserPosition(); this.refreshUserPosition(Client);
socket.to(messageUserPosition.roomId).emit(SockerIoEvent.JOIN_ROOM, messageUserPosition.toString()); socket.to(messageUserPosition.roomId).emit(SockerIoEvent.JOIN_ROOM, messageUserPosition.toString());
}); });
@ -120,11 +120,13 @@ export class IoSocketController {
return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message})); return socket.emit(SockerIoEvent.MESSAGE_ERROR, JSON.stringify({message: messageUserPosition.message}));
} }
let Client = (socket as ExSocketInterface);
// sending to all clients in room except sender // sending to all clients in room except sender
this.saveUserInformation((socket as ExSocketInterface), messageUserPosition); this.saveUserInformation(Client, messageUserPosition);
//refresh position of all user in all rooms in real time //refresh position of all user in all rooms in real time
this.refreshUserPosition(); this.refreshUserPosition(Client);
}); });
socket.on(SockerIoEvent.WEBRTC_SIGNAL, (message: string) => { socket.on(SockerIoEvent.WEBRTC_SIGNAL, (message: string) => {
@ -155,7 +157,7 @@ export class IoSocketController {
this.sendDisconnectedEvent(Client); this.sendDisconnectedEvent(Client);
//refresh position of all user in all rooms in real time //refresh position of all user in all rooms in real time
this.refreshUserPosition(); this.refreshUserPosition(Client);
//leave room //leave room
this.leaveRoom(Client); this.leaveRoom(Client);
@ -299,13 +301,29 @@ export class IoSocketController {
socket.character = message.character; socket.character = message.character;
} }
refreshUserPosition() { refreshUserPosition(Client : ExSocketInterface) {
//refresh position of all user in all rooms in real time //refresh position of all user in all rooms in real time
let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface); let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface);
if (!rooms.refreshUserPosition) { if (!rooms.refreshUserPosition) {
rooms.refreshUserPosition = RefreshUserPositionFunction; rooms.refreshUserPosition = RefreshUserPositionFunction;
} }
rooms.refreshUserPosition(rooms, this.Io, this.Worlds); rooms.refreshUserPosition(rooms, this.Io);
// update position in the worl
let data = {
userId: Client.userId,
roomId: Client.roomId,
position: Client.position,
name: Client.name,
character: Client.character,
};
let messageUserPosition = new MessageUserPosition(data);
let world = this.Worlds.get(messageUserPosition.roomId);
if (!world) {
return;
}
world.updatePosition(messageUserPosition);
this.Worlds.set(messageUserPosition.roomId, world);
} }
//Hydrate and manage error //Hydrate and manage error

View File

@ -38,18 +38,6 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server
dataArray = [data]; dataArray = [data];
} }
mapPositionUserByRoom.set(data.roomId, dataArray); mapPositionUserByRoom.set(data.roomId, dataArray);
// update position in the worl
if (!Worlds) {
return;
}
let messageUserPosition = new MessageUserPosition(data);
let world = Worlds.get(messageUserPosition.roomId);
if (!world) {
return;
}
world.updatePosition(messageUserPosition);
Worlds.set(messageUserPosition.roomId, world);
} }
rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom); rooms.userPositionMapByRoom = Array.from(mapPositionUserByRoom);
} }

View File

@ -411,6 +411,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat
} }
deleteGroup(groupId: string): void { deleteGroup(groupId: string): void {
if(!this.groups.get(groupId)){
return;
}
this.groups.get(groupId).destroy(); this.groups.get(groupId).destroy();
this.groups.delete(groupId); this.groups.delete(groupId);
} }