Merge branch 'develop' into usersLimit

# Conflicts:
#	back/src/Controller/IoSocketController.ts
#	front/src/Phaser/Game/GameScene.ts
This commit is contained in:
Gregoire Parant 2020-10-22 01:56:57 +02:00
commit 4f8b315727
5 changed files with 542 additions and 1809 deletions

View file

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"tsc": "tsc", "tsc": "tsc",
"dev": "ts-node-dev --respawn ./server.ts", "dev": "ts-node-dev --respawn ./server.ts",
"prod": "tsc && node ./dist/server.js", "prod": "tsc && node --max-old-space-size=4096 ./dist/server.js",
"profile": "tsc && node --prof ./dist/server.js", "profile": "tsc && node --prof ./dist/server.js",
"test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json", "test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
"lint": "node_modules/.bin/eslint src/ . --ext .ts", "lint": "node_modules/.bin/eslint src/ . --ext .ts",

View file

@ -109,6 +109,10 @@ export class GameRoom {
} }
} }
get isFull(): boolean {
return this.users.size >= MAX_USERS_PER_ROOM;
}
public isEmpty(): boolean { public isEmpty(): boolean {
return this.users.size === 0; return this.users.size === 0;
} }

View file

@ -2,6 +2,7 @@ import {RoomConnection} from "../front/src/Connexion/RoomConnection";
import {connectionManager} from "../front/src/Connexion/ConnectionManager"; import {connectionManager} from "../front/src/Connexion/ConnectionManager";
import * as WebSocket from "ws" import * as WebSocket from "ws"
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
@ -11,15 +12,18 @@ RoomConnection.setWebsocketFactory((url: string) => {
}); });
async function startOneUser(): Promise<void> { async function startOneUser(): Promise<void> {
const connection = await connectionManager.connectToRoomSocket(); await connectionManager.anonymousLogin(true);
connection.emitPlayerDetailsMessage('foo', ['male3']); const connection = await connectionManager.connectToRoomSocket(process.env.ROOM_ID ? process.env.ROOM_ID : '_/global/maps.workadventure.localhost/Floor0/floor0.json', 'TEST', ['male3'],
{
x: 783,
y: 170
}, {
top: 0,
bottom: 200,
left: 500,
right: 800
});
await connection.joinARoom('global__maps.workadventure.localhost/Floor0/floor0', 783, 170, 'down', true, {
top: 0,
bottom: 200,
left: 500,
right: 800
});
console.log(connection.getUserId()); console.log(connection.getUserId());
let angle = Math.random() * Math.PI * 2; let angle = Math.random() * Math.PI * 2;

File diff suppressed because it is too large Load diff

View file

@ -1015,9 +1015,9 @@ export class GameScene extends ResizableScene implements CenterListener {
this.goToNextScene(nextSceneKey.key); this.goToNextScene(nextSceneKey.key);
} }
} }
private goToNextScene(nextSceneKey: string): void { private goToNextScene(nextSceneKey: string): void {
// We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map.
this.connection.closeConnection(); this.connection.closeConnection();
this.simplePeer.unregister(); this.simplePeer.unregister();
@ -1183,32 +1183,21 @@ export class GameScene extends ResizableScene implements CenterListener {
} }
private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) { private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
const groupId = groupPositionMessage.groupId; //delete previous group
const groupSize = groupPositionMessage.groupSize; this.doDeleteGroup(groupPositionMessage.groupId);
const group = this.groups.get(groupId); // TODO: circle radius should not be hard stored
if (group !== undefined) { //create new group
group.setPosition(Math.round(groupPositionMessage.position.x), Math.round(groupPositionMessage.position.y)); const sprite = new Sprite(
} else { this,
// TODO: circle radius should not be hard stored Math.round(groupPositionMessage.position.x),
const positionX = 48; Math.round(groupPositionMessage.position.y),
const positionY = 48; groupPositionMessage.groupSize === 4 ? 'circleSprite-red' : 'circleSprite-white'
);
console.log('doShareGroupPosition', groupSize); sprite.setDisplayOrigin(48, 48);
let texture = 'circleSprite-red'; this.add.existing(sprite);
if(groupSize < 4){ this.groups.set(groupPositionMessage.groupId, sprite);
texture = 'circleSprite-white'; return sprite;
}
const sprite = new Sprite(
this,
Math.round(groupPositionMessage.position.x),
Math.round(groupPositionMessage.position.y),
texture
);
sprite.setDisplayOrigin(positionX, positionY);
this.add.existing(sprite);
this.groups.set(groupId, sprite);
}
} }
deleteGroup(groupId: number): void { deleteGroup(groupId: number): void {