From: gparant Date: Mon, 11 May 2020 11:17:02 +0000 (+0200) Subject: Fix update world back end and deleting group in front end X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e35c188854c1c6e0cb1fe931f1e40c39a1c0edb5;p=libreadventure.git Fix update world back end and deleting group in front end --- diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index e0840c6..c855c66 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -109,7 +109,7 @@ export class IoSocketController { this.saveUserInformation(Client, messageUserPosition); //add function to refresh position user in real time. - this.refreshUserPosition(); + this.refreshUserPosition(Client); 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})); } + let Client = (socket as ExSocketInterface); + // 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 - this.refreshUserPosition(); + this.refreshUserPosition(Client); }); socket.on(SockerIoEvent.WEBRTC_SIGNAL, (message: string) => { @@ -155,7 +157,7 @@ export class IoSocketController { this.sendDisconnectedEvent(Client); //refresh position of all user in all rooms in real time - this.refreshUserPosition(); + this.refreshUserPosition(Client); //leave room this.leaveRoom(Client); @@ -299,13 +301,29 @@ export class IoSocketController { socket.character = message.character; } - refreshUserPosition() { + refreshUserPosition(Client : ExSocketInterface) { //refresh position of all user in all rooms in real time let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface); if (!rooms.refreshUserPosition) { 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 diff --git a/back/src/Model/Websocket/ExtRooms.ts b/back/src/Model/Websocket/ExtRooms.ts index 22db4fd..bb49283 100644 --- a/back/src/Model/Websocket/ExtRooms.ts +++ b/back/src/Model/Websocket/ExtRooms.ts @@ -38,18 +38,6 @@ let RefreshUserPositionFunction = function(rooms : ExtRooms, Io: socketIO.Server dataArray = [data]; } 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); } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 26b4fe9..86988a8 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -411,6 +411,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface, Creat } deleteGroup(groupId: string): void { + if(!this.groups.get(groupId)){ + return; + } this.groups.get(groupId).destroy(); this.groups.delete(groupId); }