Merge remote-tracking branch 'github.com/master' into webrtc

# Conflicts:
#	front/src/Connexion.ts
#	front/src/Phaser/Game/GameManager.ts
#	front/src/Phaser/Game/GameScene.ts
#	front/src/index.ts
This commit is contained in:
gparant 2020-04-29 17:37:17 +02:00
commit 91851c95f3
5 changed files with 34 additions and 65 deletions

View File

@ -1,8 +1,8 @@
import {GameManagerInterface} from "./Phaser/Game/GameManager"; import {GameManager} from "./Phaser/Game/GameManager";
const SocketIo = require('socket.io-client'); const SocketIo = require('socket.io-client');
import Axios from "axios"; import Axios from "axios";
import {API_URL} from "./Enum/EnvironmentVariable"; import {API_URL, ROOM} from "./Enum/EnvironmentVariable";
enum EventMessage{ enum EventMessage{
WEBRTC_SIGNAL = "webrtc-signal", WEBRTC_SIGNAL = "webrtc-signal",
@ -121,7 +121,7 @@ export interface ConnexionInterface {
joinARoom(roomId: string): void; joinARoom(roomId: string): void;
sharePosition(roomId: string, x: number, y: number, direction: string): void; sharePosition(x: number, y: number, direction: string): void;
positionOfAllUser(): void; positionOfAllUser(): void;
@ -140,9 +140,9 @@ export class Connexion implements ConnexionInterface {
userId: string; userId: string;
startedRoom: string; startedRoom: string;
GameManager: GameManagerInterface; GameManager: GameManager;
constructor(email: string, GameManager: GameManagerInterface) { constructor(email : string, GameManager: GameManager) {
this.email = email; this.email = email;
this.GameManager = GameManager; this.GameManager = GameManager;
} }
@ -164,7 +164,7 @@ export class Connexion implements ConnexionInterface {
this.joinARoom(this.startedRoom); this.joinARoom(this.startedRoom);
//share your first position //share your first position
this.sharePosition(this.startedRoom, 0, 0); this.sharePosition(0, 0);
this.positionOfAllUser(); this.positionOfAllUser();
@ -189,16 +189,15 @@ export class Connexion implements ConnexionInterface {
/** /**
* *
* @param roomId
* @param x * @param x
* @param y * @param y
* @param direction * @param direction
*/ */
sharePosition(roomId: string, x: number, y: number, direction: string = "none"): void { sharePosition(x : number, y : number, direction : string = "none") : void{
if (!this.socket) { if(!this.socket){
return; return;
} }
let messageUserPosition = new MessageUserPosition(this.userId, roomId, new Point(x, y, direction)); let messageUserPosition = new MessageUserPosition(this.userId, ROOM[0], new Point(x, y, direction));
this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString()); this.socket.emit(EventMessage.USER_POSITION, messageUserPosition.toString());
} }

View File

@ -1,4 +1,4 @@
import {GameSceneInterface, GameScene} from "./GameScene"; import {GameScene} from "./GameScene";
import {ROOM} from "../../Enum/EnvironmentVariable" import {ROOM} from "../../Enum/EnvironmentVariable"
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion"; import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer"; import {SimplePeerInterface, SimplePeer} from "../../WebRtc/SimplePeer";
@ -11,60 +11,35 @@ export enum StatusGameManagerEnum {
export let ConnexionInstance : ConnexionInterface; export let ConnexionInstance : ConnexionInterface;
export interface GameManagerInterface { export class GameManager {
GameScenes: Array<GameSceneInterface>;
status : number;
SimplePeer: SimplePeerInterface;
createCurrentPlayer() : void;
shareUserPosition(ListMessageUserPosition : ListMessageUserPositionInterface): void;
connect(email : string) : Promise<any>;
}
export class GameManager implements GameManagerInterface {
GameScenes: Array<GameSceneInterface> = [];
status: number; status: number;
private ConnexionInstance: Connexion;
private currentGameScene: GameScene;
SimplePeer : SimplePeerInterface; SimplePeer : SimplePeerInterface;
constructor() { constructor() {
this.status = StatusGameManagerEnum.IN_PROGRESS; this.status = StatusGameManagerEnum.IN_PROGRESS;
this.configureGame();
} }
/** connect(email:string) {
* this.ConnexionInstance = new Connexion(email, this);
* @param email ConnexionInstance = this.ConnexionInstance;
*/ return this.ConnexionInstance.createConnexion().then(() => {
connect(email : string) : Promise<any> {
ConnexionInstance = new Connexion(email, this);
return ConnexionInstance.createConnexion().then(() => {
this.SimplePeer = new SimplePeer(ConnexionInstance); this.SimplePeer = new SimplePeer(ConnexionInstance);
}); });
} }
/** setCurrentGameScene(gameScene: GameScene) {
* permit to config rooms this.currentGameScene = gameScene;
*/
configureGame() {
//create login scene
let LoginScene = new LogincScene();
this.GameScenes.push(LoginScene)
//create scene
ROOM.forEach((roomId) => {
let newGame = new GameScene(roomId, this);
this.GameScenes.push((newGame as GameSceneInterface));
});
} }
/** /**
* * 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
let game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ConnexionInstance.startedRoom); this.currentGameScene.createCurrentPlayer(this.ConnexionInstance.userId);
if(!game){
return;
}
game.createCurrentPlayer(ConnexionInstance.userId);
this.status = StatusGameManagerEnum.CURRENT_USER_CREATED; this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
} }
@ -77,11 +52,7 @@ export class GameManager implements GameManagerInterface {
return; return;
} }
try { try {
let Game: GameSceneInterface = this.GameScenes.find((Game: GameSceneInterface) => Game.RoomId === ListMessageUserPosition.roomId); this.currentGameScene.shareUserPosition(ListMessageUserPosition.listUsersPosition)
if (!Game) {
return;
}
Game.shareUserPosition(ListMessageUserPosition.listUsersPosition)
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }

View File

@ -1,7 +1,8 @@
import {GameManagerInterface} from "./GameManager"; import {GameManager, gameManager, StatusGameManagerEnum} from "./GameManager";
import {MessageUserPositionInterface} from "../../Connexion"; import {MessageUserPositionInterface} from "../../Connexion";
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player"; import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
import {DEBUG_MODE, RESOLUTION, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable"; import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable";
import Tile = Phaser.Tilemaps.Tile;
import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap"; import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap";
import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {cypressAsserter} from "../../Cypress/CypressAsserter";
@ -12,14 +13,12 @@ export enum Textures {
} }
export interface GameSceneInterface extends Phaser.Scene { export interface GameSceneInterface extends Phaser.Scene {
RoomId : string;
Map: Phaser.Tilemaps.Tilemap; Map: Phaser.Tilemaps.Tilemap;
createCurrentPlayer(UserId : string) : void; createCurrentPlayer(UserId : string) : void;
shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void; shareUserPosition(UsersPosition : Array<MessageUserPositionInterface>): void;
} }
export class GameScene extends Phaser.Scene implements GameSceneInterface{ export class GameScene extends Phaser.Scene implements GameSceneInterface{
GameManager : GameManagerInterface; GameManager : GameManager;
RoomId : string;
Terrains : Array<Phaser.Tilemaps.Tileset>; Terrains : Array<Phaser.Tilemaps.Tileset>;
CurrentPlayer: CurrentGamerInterface; CurrentPlayer: CurrentGamerInterface;
MapPlayers : Phaser.Physics.Arcade.Group; MapPlayers : Phaser.Physics.Arcade.Group;
@ -31,17 +30,17 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
startY = (window.innerHeight / 2) / RESOLUTION; startY = (window.innerHeight / 2) / RESOLUTION;
constructor(RoomId : string, GameManager : GameManagerInterface) { constructor() {
super({ super({
key: "GameScene" key: "GameScene"
}); });
this.RoomId = RoomId; this.GameManager = gameManager;
this.GameManager = GameManager;
this.Terrains = []; this.Terrains = [];
} }
//hook preload scene //hook preload scene
preload(): void { preload(): void {
this.GameManager.setCurrentGameScene(this);
cypressAsserter.preloadStarted(); cypressAsserter.preloadStarted();
let mapUrl = 'maps/map.json'; let mapUrl = 'maps/map.json';
this.load.on('filecomplete-tilemapJSON-'+Textures.Map, (key: string, type: string, data: any) => { this.load.on('filecomplete-tilemapJSON-'+Textures.Map, (key: string, type: string, data: any) => {

View File

@ -95,7 +95,7 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
private sharePosition(direction: string) { private sharePosition(direction: string) {
if (ConnexionInstance) { if (ConnexionInstance) {
ConnexionInstance.sharePosition((this.scene as GameSceneInterface).RoomId, this.x, this.y, direction); ConnexionInstance.sharePosition(this.x, this.y, direction);
} }
} }

View File

@ -1,16 +1,16 @@
import 'phaser'; import 'phaser';
import GameConfig = Phaser.Types.Core.GameConfig; import GameConfig = Phaser.Types.Core.GameConfig;
import {gameManager, GameManager} from "./Phaser/Game/GameManager";
import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable"; import {DEBUG_MODE, RESOLUTION} from "./Enum/EnvironmentVariable";
import {cypressAsserter} from "./Cypress/CypressAsserter"; import {cypressAsserter} from "./Cypress/CypressAsserter";
import {LogincScene} from "./Phaser/Login/LogincScene"; import {LogincScene} from "./Phaser/Login/LogincScene";
import {GameScene} from "./Phaser/Game/GameScene";
const config: GameConfig = { const config: GameConfig = {
title: "Office game", title: "Office game",
width: window.innerWidth / RESOLUTION, width: window.innerWidth / RESOLUTION,
height: window.innerHeight / RESOLUTION, height: window.innerHeight / RESOLUTION,
parent: "game", parent: "game",
scene: gameManager.GameScenes, scene: [LogincScene, GameScene],
zoom: RESOLUTION, zoom: RESOLUTION,
physics: { physics: {
default: "arcade", default: "arcade",