Merge pull request #127 from thecodingmachine/remove_dead_code

Removing dead code from previous messaging system
This commit is contained in:
David Négrier 2020-05-25 22:44:33 +02:00 committed by GitHub
commit a0ce57e582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 126 deletions

View File

@ -87,29 +87,6 @@ export interface ListMessageUserPositionInterface {
listUsersPosition: Array<MessageUserPosition>; listUsersPosition: Array<MessageUserPosition>;
} }
class ListMessageUserPosition {
roomId: string;
listUsersPosition: Array<MessageUserPosition>;
constructor(roomId: string, data: any) {
this.roomId = roomId;
this.listUsersPosition = new Array<MessageUserPosition>();
data.forEach((userPosition: any) => {
this.listUsersPosition.push(new MessageUserPosition(
userPosition.userId,
new Point(
userPosition.position.x,
userPosition.position.y,
userPosition.position.direction,
userPosition.position.moving
),
userPosition.name,
userPosition.character
));
});
}
}
export interface PositionInterface { export interface PositionInterface {
x: number, x: number,
y: number y: number
@ -134,8 +111,6 @@ export interface ConnectionInterface {
sharePosition(x: number, y: number, direction: string, moving: boolean): void; sharePosition(x: number, y: number, direction: string, moving: boolean): void;
positionOfAllUser(): void;
/*webrtc*/ /*webrtc*/
sendWebrtcSignal(signal: any, roomId: string, userId?: string, receiverId?: string): void; sendWebrtcSignal(signal: any, roomId: string, userId?: string, receiverId?: string): void;
@ -187,7 +162,6 @@ export class Connection implements ConnectionInterface {
*/ */
connectSocketServer(): Promise<ConnectionInterface>{ connectSocketServer(): Promise<ConnectionInterface>{
//listen event //listen event
this.positionOfAllUser();
this.disconnectServer(); this.disconnectServer();
this.errorMessage(); this.errorMessage();
this.groupUpdatedOrCreated(); this.groupUpdatedOrCreated();
@ -256,43 +230,19 @@ export class Connection implements ConnectionInterface {
this.socket.emit(EventMessage.USER_POSITION, point); this.socket.emit(EventMessage.USER_POSITION, point);
} }
/** private onUserJoins(): void {
* The data sent is an array with information for each user :
* [
* {
* userId: <string>,
* position: {
* x : <number>,
* y : <number>,
* direction: <string>,
* moving: <bool>
* }
* },
* ...
* ]
**/
positionOfAllUser(): void {
this.socket.on(EventMessage.USER_POSITION, (message: string) => {
let dataList = message;
let UserPositions : Array<any> = Object.values(dataList);
let listMessageUserPosition = new ListMessageUserPosition(UserPositions[0], UserPositions[1]);
this.GameManager.shareUserPosition(listMessageUserPosition);
});
}
onUserJoins(): void {
this.socket.on(EventMessage.JOIN_ROOM, (message: MessageUserJoined) => { this.socket.on(EventMessage.JOIN_ROOM, (message: MessageUserJoined) => {
this.GameManager.onUserJoins(message); this.GameManager.onUserJoins(message);
}); });
} }
onUserMoved(): void { private onUserMoved(): void {
this.socket.on(EventMessage.USER_MOVED, (message: MessageUserMovedInterface) => { this.socket.on(EventMessage.USER_MOVED, (message: MessageUserMovedInterface) => {
this.GameManager.onUserMoved(message); this.GameManager.onUserMoved(message);
}); });
} }
onUserLeft(): void { private onUserLeft(): void {
this.socket.on(EventMessage.USER_LEFT, (userId: string) => { this.socket.on(EventMessage.USER_LEFT, (userId: string) => {
this.GameManager.onUserLeft(userId); this.GameManager.onUserLeft(userId);
}); });
@ -328,13 +278,13 @@ export class Connection implements ConnectionInterface {
return this.socket.on(EventMessage.WEBRTC_SIGNAL, callback); return this.socket.on(EventMessage.WEBRTC_SIGNAL, callback);
} }
errorMessage(): void { private errorMessage(): void {
this.socket.on(EventMessage.MESSAGE_ERROR, (message: string) => { this.socket.on(EventMessage.MESSAGE_ERROR, (message: string) => {
console.error(EventMessage.MESSAGE_ERROR, message); console.error(EventMessage.MESSAGE_ERROR, message);
}) })
} }
disconnectServer(): void { private disconnectServer(): void {
this.socket.on(EventMessage.CONNECT_ERROR, () => { this.socket.on(EventMessage.CONNECT_ERROR, () => {
this.GameManager.switchToDisconnectedScene(); this.GameManager.switchToDisconnectedScene();
}); });

View File

@ -13,10 +13,10 @@ import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
import {AddPlayerInterface} from "./AddPlayerInterface"; import {AddPlayerInterface} from "./AddPlayerInterface";
import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene"; import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
export enum StatusGameManagerEnum { /*export enum StatusGameManagerEnum {
IN_PROGRESS = 1, IN_PROGRESS = 1,
CURRENT_USER_CREATED = 2 CURRENT_USER_CREATED = 2
} }*/
export interface HasMovedEvent { export interface HasMovedEvent {
direction: string; direction: string;
@ -31,7 +31,7 @@ export interface MapObject {
} }
export class GameManager { export class GameManager {
status: number; //status: number;
private ConnectionInstance: Connection; private ConnectionInstance: Connection;
private currentGameScene: GameScene; private currentGameScene: GameScene;
private playerName: string; private playerName: string;
@ -39,7 +39,7 @@ export class GameManager {
private characterUserSelected: string; private characterUserSelected: string;
constructor() { constructor() {
this.status = StatusGameManagerEnum.IN_PROGRESS; //this.status = StatusGameManagerEnum.IN_PROGRESS;
} }
connect(name: string, characterUserSelected : string) { connect(name: string, characterUserSelected : string) {
@ -70,11 +70,11 @@ export class GameManager {
/** /**
* Permit to create player in started room * Permit to create player in started room
*/ */
createCurrentPlayer(): void { /*createCurrentPlayer(): void {
//Get started room send by the backend //Get started room send by the backend
this.currentGameScene.createCurrentPlayer(); this.currentGameScene.createCurrentPlayer();
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED; //this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
} }*/
joinRoom(sceneKey: string, startX: number, startY: number, direction: string, moving: boolean){ joinRoom(sceneKey: string, startX: number, startY: number, direction: string, moving: boolean){
this.ConnectionInstance.joinARoom(sceneKey, startX, startY, direction, moving); this.ConnectionInstance.joinARoom(sceneKey, startX, startY, direction, moving);
@ -98,22 +98,6 @@ export class GameManager {
this.currentGameScene.removePlayer(userId); this.currentGameScene.removePlayer(userId);
} }
/**
* Share position in game
* @param ListMessageUserPosition
* @deprecated
*/
shareUserPosition(ListMessageUserPosition: ListMessageUserPositionInterface): void {
if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
return;
}
try {
this.currentGameScene.shareUserPosition(ListMessageUserPosition.listUsersPosition)
} catch (e) {
console.error(e);
}
}
initUsersPosition(usersPosition: MessageUserPositionInterface[]): void { initUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
// Shall we wait for room to be loaded? // Shall we wait for room to be loaded?
/*if (this.status === StatusGameManagerEnum.IN_PROGRESS) { /*if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
@ -130,9 +114,9 @@ export class GameManager {
* Share group position in game * Share group position in game
*/ */
shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface): void { shareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface): void {
if (this.status === StatusGameManagerEnum.IN_PROGRESS) { /*if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
return; return;
} }*/
try { try {
this.currentGameScene.shareGroupPosition(groupPositionMessage) this.currentGameScene.shareGroupPosition(groupPositionMessage)
} catch (e) { } catch (e) {
@ -141,9 +125,9 @@ export class GameManager {
} }
deleteGroup(groupId: string): void { deleteGroup(groupId: string): void {
if (this.status === StatusGameManagerEnum.IN_PROGRESS) { /*if (this.status === StatusGameManagerEnum.IN_PROGRESS) {
return; return;
} }*/
try { try {
this.currentGameScene.deleteGroup(groupId) this.currentGameScene.deleteGroup(groupId)
} catch (e) { } catch (e) {

View File

@ -145,7 +145,7 @@ export class GameScene extends Phaser.Scene {
this.MapPlayers = this.physics.add.group({ immovable: true }); this.MapPlayers = this.physics.add.group({ immovable: true });
//notify game manager can to create currentUser in map //notify game manager can to create currentUser in map
this.GameManager.createCurrentPlayer(); this.createCurrentPlayer();
//initialise camera //initialise camera
this.initCamera(); this.initCamera();
@ -362,49 +362,6 @@ export class GameScene extends Phaser.Scene {
}) })
} }
/**
* Share position in scene
* @param UsersPosition
* @deprecated
*/
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void {
this.updateOrCreateMapPlayer(UsersPosition);
}
/**
* Create new player and clean the player on the map
* @param UsersPosition
*/
updateOrCreateMapPlayer(UsersPosition : Array<MessageUserPositionInterface>){
if(!this.CurrentPlayer){
return;
}
let currentPlayerId = this.GameManager.getPlayerId();
//add or create new user
UsersPosition.forEach((userPosition : MessageUserPositionInterface) => {
if(userPosition.userId === currentPlayerId){
return;
}
let player = this.findPlayerInMap(userPosition.userId);
if(!player){
this.addPlayer(userPosition);
}else{
player.updatePosition(userPosition.position);
}
});
//clean map
this.MapPlayers.getChildren().forEach((player: GamerInterface) => {
if(UsersPosition.find((message : MessageUserPositionInterface) => message.userId === player.userId)){
return;
}
player.destroy();
this.MapPlayers.remove(player);
});
}
public initUsersPosition(usersPosition: MessageUserPositionInterface[]): void { public initUsersPosition(usersPosition: MessageUserPositionInterface[]): void {
if(!this.CurrentPlayer){ if(!this.CurrentPlayer){
console.error('Cannot initiate users list because map is not loaded yet') console.error('Cannot initiate users list because map is not loaded yet')