Fix feedback @kharhamel
This commit is contained in:
parent
d257b2b944
commit
bbc3935d60
@ -99,8 +99,18 @@ class ListMessageUserPosition{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export interface ConnexionInterface {
|
||||||
export class Connexion {
|
socket : any;
|
||||||
|
token : string;
|
||||||
|
email : string;
|
||||||
|
userId: string;
|
||||||
|
startedRoom : string;
|
||||||
|
createConnexion() : Promise<any>;
|
||||||
|
joinARoom(roomId : string) : void;
|
||||||
|
sharePosition(roomId : string, x : number, y : number, direction : string) : void;
|
||||||
|
positionOfAllUser() : void;
|
||||||
|
}
|
||||||
|
export class Connexion implements ConnexionInterface{
|
||||||
socket : any;
|
socket : any;
|
||||||
token : string;
|
token : string;
|
||||||
email : string;
|
email : string;
|
||||||
@ -114,7 +124,7 @@ export class Connexion {
|
|||||||
this.GameManager = GameManager;
|
this.GameManager = GameManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
createConnexion(){
|
createConnexion() : Promise<ConnexionInterface>{
|
||||||
return Axios.post(`${API_URL}/login`, {email: this.email})
|
return Axios.post(`${API_URL}/login`, {email: this.email})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.token = res.data.token;
|
this.token = res.data.token;
|
||||||
@ -137,10 +147,7 @@ export class Connexion {
|
|||||||
|
|
||||||
this.errorMessage();
|
this.errorMessage();
|
||||||
|
|
||||||
return{
|
return this;
|
||||||
userId: this.userId,
|
|
||||||
roomId: this.startedRoom
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -152,7 +159,7 @@ export class Connexion {
|
|||||||
* Permit to join a room
|
* Permit to join a room
|
||||||
* @param roomId
|
* @param roomId
|
||||||
*/
|
*/
|
||||||
joinARoom(roomId : string){
|
joinARoom(roomId : string) : void {
|
||||||
let messageUserPosition = new MessageUserPosition(this.userId, this.startedRoom, new Point(0, 0));
|
let messageUserPosition = new MessageUserPosition(this.userId, this.startedRoom, new Point(0, 0));
|
||||||
this.socket.emit('join-room', messageUserPosition.toString());
|
this.socket.emit('join-room', messageUserPosition.toString());
|
||||||
}
|
}
|
||||||
@ -164,7 +171,7 @@ export class Connexion {
|
|||||||
* @param y
|
* @param y
|
||||||
* @param direction
|
* @param direction
|
||||||
*/
|
*/
|
||||||
sharePosition(roomId : string, x : number, y : number, direction : string = "none"){
|
sharePosition(roomId : string, x : number, y : number, direction : string = "none") : void{
|
||||||
if(!this.socket){
|
if(!this.socket){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -187,7 +194,7 @@ export class Connexion {
|
|||||||
* ...
|
* ...
|
||||||
* ]
|
* ]
|
||||||
**/
|
**/
|
||||||
positionOfAllUser() {
|
positionOfAllUser() : void {
|
||||||
this.socket.on("user-position", (message: string) => {
|
this.socket.on("user-position", (message: string) => {
|
||||||
let dataList = JSON.parse(message);
|
let dataList = JSON.parse(message);
|
||||||
dataList.forEach((UserPositions: any) => {
|
dataList.forEach((UserPositions: any) => {
|
||||||
@ -197,7 +204,7 @@ export class Connexion {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
errorMessage(){
|
errorMessage() : void {
|
||||||
this.socket.on('message-error', (message : string) => {
|
this.socket.on('message-error', (message : string) => {
|
||||||
console.error("message-error", message);
|
console.error("message-error", message);
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
||||||
import {Player} from "../Player/Player";
|
import {Player} from "../Player/Player";
|
||||||
import {MapManagerInterface} from "./MapManager";
|
import {MapManagerInterface} from "./MapManager";
|
||||||
import {PlayerAnimationNames} from "../Player/Animation";
|
|
||||||
|
|
||||||
export interface CameraManagerInterface {
|
export interface CameraManagerInterface {
|
||||||
MapManager : MapManagerInterface;
|
MapManager : MapManagerInterface;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import {GameSceneInterface, GameScene} from "./GameScene";
|
import {GameSceneInterface, GameScene} from "./GameScene";
|
||||||
import {ROOM} from "../../Enum/EnvironmentVariable"
|
import {ROOM} from "../../Enum/EnvironmentVariable"
|
||||||
import {Connexion, ListMessageUserPositionInterface} from "../../Connexion";
|
import {Connexion, ConnexionInterface, ListMessageUserPositionInterface} from "../../Connexion";
|
||||||
|
|
||||||
export enum StatusGameManagerEnum {
|
export enum StatusGameManagerEnum {
|
||||||
IN_PROGRESS = 1,
|
IN_PROGRESS = 1,
|
||||||
CURRENT_USER_CREATED = 2
|
CURRENT_USER_CREATED = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
export let ConnexionInstance : Connexion;
|
export let ConnexionInstance : ConnexionInterface;
|
||||||
|
|
||||||
export interface GameManagerInterface {
|
export interface GameManagerInterface {
|
||||||
GameScenes: Array<GameSceneInterface>;
|
GameScenes: Array<GameSceneInterface>;
|
||||||
@ -25,7 +25,7 @@ export class GameManager implements GameManagerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createGame(){
|
createGame(){
|
||||||
return ConnexionInstance.createConnexion().then((data: any) => {
|
return ConnexionInstance.createConnexion().then(() => {
|
||||||
this.configureGame();
|
this.configureGame();
|
||||||
/** TODO add loader in the page **/
|
/** TODO add loader in the page **/
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
import {CameraManager, CameraManagerInterface} from "./CameraManager";
|
||||||
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
import {RESOLUTION} from "../../Enum/EnvironmentVariable";
|
||||||
import {Player} from "../Player/Player";
|
import {CurrentGamerInterface, GamerInterface, Player} from "../Player/Player";
|
||||||
import {GameSceneInterface} from "./GameScene";
|
import {GameSceneInterface} from "./GameScene";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
import {MessageUserPositionInterface} from "../../Connexion";
|
||||||
|
|
||||||
@ -37,8 +37,8 @@ export class MapManager implements MapManagerInterface{
|
|||||||
|
|
||||||
Terrain : Phaser.Tilemaps.Tileset;
|
Terrain : Phaser.Tilemaps.Tileset;
|
||||||
Camera: CameraManagerInterface;
|
Camera: CameraManagerInterface;
|
||||||
CurrentPlayer: Player;
|
CurrentPlayer: CurrentGamerInterface;
|
||||||
MapPlayers : Player[];
|
MapPlayers : GamerInterface[];
|
||||||
Scene: GameSceneInterface;
|
Scene: GameSceneInterface;
|
||||||
Map: Phaser.Tilemaps.Tilemap;
|
Map: Phaser.Tilemaps.Tilemap;
|
||||||
startX = (window.innerWidth / 2) / RESOLUTION;
|
startX = (window.innerWidth / 2) / RESOLUTION;
|
||||||
@ -59,7 +59,7 @@ export class MapManager implements MapManagerInterface{
|
|||||||
//initialise camera
|
//initialise camera
|
||||||
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
|
this.Camera = new CameraManager(this.Scene, this.Scene.cameras.main, this);
|
||||||
//initialise list of other player
|
//initialise list of other player
|
||||||
this.MapPlayers = new Array<Player>();
|
this.MapPlayers = new Array<GamerInterface>();
|
||||||
}
|
}
|
||||||
|
|
||||||
createCurrentPlayer(UserId : string){
|
createCurrentPlayer(UserId : string){
|
||||||
|
@ -5,7 +5,25 @@ import {ConnexionInstance} from "../Game/GameManager";
|
|||||||
import {CameraManagerInterface} from "../Game/CameraManager";
|
import {CameraManagerInterface} from "../Game/CameraManager";
|
||||||
import {MessageUserPositionInterface} from "../../Connexion";
|
import {MessageUserPositionInterface} from "../../Connexion";
|
||||||
|
|
||||||
export class Player extends Phaser.GameObjects.Sprite{
|
export interface CurrentGamerInterface{
|
||||||
|
userId : string;
|
||||||
|
MapManager : MapManagerInterface;
|
||||||
|
PlayerValue : string;
|
||||||
|
CameraManager: CameraManagerInterface;
|
||||||
|
initAnimation() : void;
|
||||||
|
move() : void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GamerInterface{
|
||||||
|
userId : string;
|
||||||
|
MapManager : MapManagerInterface;
|
||||||
|
PlayerValue : string;
|
||||||
|
CameraManager: CameraManagerInterface;
|
||||||
|
initAnimation() : void;
|
||||||
|
updatePosition(MessageUserPosition : MessageUserPositionInterface) : void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Player extends Phaser.GameObjects.Sprite implements CurrentGamerInterface, GamerInterface{
|
||||||
userId : string;
|
userId : string;
|
||||||
MapManager : MapManagerInterface;
|
MapManager : MapManagerInterface;
|
||||||
PlayerValue : string;
|
PlayerValue : string;
|
||||||
@ -28,7 +46,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
this.CameraManager = CameraManager;
|
this.CameraManager = CameraManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
initAnimation(){
|
initAnimation() : void{
|
||||||
getPlayerAnimations(this.PlayerValue).forEach(d => {
|
getPlayerAnimations(this.PlayerValue).forEach(d => {
|
||||||
this.scene.anims.create({
|
this.scene.anims.create({
|
||||||
key: d.key,
|
key: d.key,
|
||||||
@ -39,7 +57,7 @@ export class Player extends Phaser.GameObjects.Sprite{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
move(){
|
move() : void{
|
||||||
//if user client on shift, camera and player speed
|
//if user client on shift, camera and player speed
|
||||||
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
|
let speedMultiplier = this.MapManager.keyShift.isDown ? 5 : 1;
|
||||||
let haveMove = false;
|
let haveMove = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user