Cleaning GameManager
This commit is contained in:
parent
403ea223a8
commit
1e4ffa20ab
@ -17,11 +17,6 @@ import {Scene} from "phaser";
|
|||||||
import Axios from "axios";
|
import Axios from "axios";
|
||||||
import {API_URL} from "../../Enum/EnvironmentVariable";
|
import {API_URL} from "../../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
/*export enum StatusGameManagerEnum {
|
|
||||||
IN_PROGRESS = 1,
|
|
||||||
CURRENT_USER_CREATED = 2
|
|
||||||
}*/
|
|
||||||
|
|
||||||
export interface HasMovedEvent {
|
export interface HasMovedEvent {
|
||||||
direction: string;
|
direction: string;
|
||||||
moving: boolean;
|
moving: boolean;
|
||||||
@ -35,27 +30,12 @@ export interface MapObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
//status: number;
|
|
||||||
//private ConnectionInstance: Connection;
|
|
||||||
private currentGameScene: GameScene|null = null;
|
|
||||||
private playerName: string;
|
private playerName: string;
|
||||||
SimplePeer : SimplePeer;
|
|
||||||
private characterUserSelected: string;
|
private characterUserSelected: string;
|
||||||
|
|
||||||
constructor() {
|
public storePlayerDetails(name: string, characterUserSelected : string): void {
|
||||||
//this.status = StatusGameManagerEnum.IN_PROGRESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public storePlayerDetails(name: string, characterUserSelected : string) /*: Promise<Connection>*/ {
|
|
||||||
this.playerName = name;
|
this.playerName = name;
|
||||||
this.characterUserSelected = characterUserSelected;
|
this.characterUserSelected = characterUserSelected;
|
||||||
/*this.ConnectionInstance = new Connection(this);
|
|
||||||
return this.ConnectionInstance.createConnection(name, characterUserSelected).then((data : Connection) => {
|
|
||||||
this.SimplePeer = new SimplePeer(this.ConnectionInstance);
|
|
||||||
return data;
|
|
||||||
}).catch((err) => {
|
|
||||||
throw err;
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadStartMap() : Promise<StartMapInterface> {
|
loadStartMap() : Promise<StartMapInterface> {
|
||||||
@ -68,20 +48,6 @@ export class GameManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentGameScene(gameScene: GameScene) {
|
|
||||||
this.currentGameScene = gameScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Permit to create player in started room
|
|
||||||
*/
|
|
||||||
/*createCurrentPlayer(): void {
|
|
||||||
//Get started room send by the backend
|
|
||||||
this.currentGameScene.createCurrentPlayer();
|
|
||||||
//this.status = StatusGameManagerEnum.CURRENT_USER_CREATED;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
getPlayerName(): string {
|
getPlayerName(): string {
|
||||||
return this.playerName;
|
return this.playerName;
|
||||||
}
|
}
|
||||||
@ -100,64 +66,6 @@ export class GameManager {
|
|||||||
}
|
}
|
||||||
return sceneKey;
|
return sceneKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private oldSceneKey : string;
|
|
||||||
private oldMapUrlFile : string;
|
|
||||||
private oldInstance : string;
|
|
||||||
private scenePlugin: ScenePlugin;
|
|
||||||
private reconnectScene: Scene|null = null;
|
|
||||||
switchToDisconnectedScene(): void {
|
|
||||||
if (this.currentGameScene === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Switching to disconnected scene');
|
|
||||||
this.oldSceneKey = this.currentGameScene.scene.key;
|
|
||||||
this.oldMapUrlFile = this.currentGameScene.MapUrlFile;
|
|
||||||
this.oldInstance = this.currentGameScene.instance;
|
|
||||||
this.currentGameScene.scene.start(ReconnectingSceneName);
|
|
||||||
this.reconnectScene = this.currentGameScene.scene.get(ReconnectingSceneName);
|
|
||||||
// Let's completely delete an purge the disconnected scene. We will start again from 0.
|
|
||||||
this.currentGameScene.scene.remove(this.oldSceneKey);
|
|
||||||
this.scenePlugin = this.currentGameScene.scene;
|
|
||||||
this.currentGameScene = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*private timeoutCallback: NodeJS.Timeout|null = null;
|
|
||||||
reconnectToGameScene(lastPositionShared: PointInterface): void {
|
|
||||||
if (this.timeoutCallback !== null) {
|
|
||||||
console.log('Reconnect called but setTimeout in progress for the reconnection');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.reconnectScene === null) {
|
|
||||||
console.log('Reconnect called without switchToDisconnectedScene called first');
|
|
||||||
|
|
||||||
if (!this.currentGameScene) {
|
|
||||||
console.error('Reconnect called but we are not on a GameScene');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep)
|
|
||||||
this.switchToDisconnectedScene();
|
|
||||||
// Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason.
|
|
||||||
this.timeoutCallback = setTimeout(() => {
|
|
||||||
console.log('Reconnecting to game scene from setTimeout');
|
|
||||||
this.timeoutCallback = null;
|
|
||||||
this.reconnectToGameScene(lastPositionShared);
|
|
||||||
}, 500);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Reconnecting to game scene');
|
|
||||||
const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance);
|
|
||||||
this.reconnectScene.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });
|
|
||||||
this.reconnectScene = null;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private getCurrentGameScene(): GameScene {
|
|
||||||
if (this.currentGameScene === null) {
|
|
||||||
throw new Error('No current game scene enabled');
|
|
||||||
}
|
|
||||||
return this.currentGameScene;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const gameManager = new GameManager();
|
export const gameManager = new GameManager();
|
||||||
|
Loading…
Reference in New Issue
Block a user