partey_workadventure/front/src/Phaser/Game/GameManager.ts

62 lines
1.7 KiB
TypeScript
Raw Normal View History

import {GameScene} from "./GameScene";
import {
StartMapInterface
2020-09-25 18:29:22 +02:00
} from "../../Connexion/ConnexionModels";
import Axios from "axios";
import {API_URL} from "../../Enum/EnvironmentVariable";
2020-09-28 15:02:37 +02:00
import {connectionManager} from "../../Connexion/ConnectionManager";
export interface HasMovedEvent {
direction: string;
moving: boolean;
x: number;
y: number;
}
2020-04-07 20:41:35 +02:00
export class GameManager {
private playerName!: string;
private characterLayers!: string[];
2020-04-07 20:41:35 +02:00
2020-07-28 15:53:44 +02:00
public setPlayerName(name: string): void {
this.playerName = name;
2020-07-28 15:53:44 +02:00
}
public setCharacterUserSelected(characterUserSelected : string): void {
this.characterLayers = [characterUserSelected];
}
public setCharacterLayers(layers: string[]) {
this.characterLayers = layers;
}
loadStartMap() : Promise<StartMapInterface> {
2020-09-28 15:02:37 +02:00
return connectionManager.getMapUrlStart().then(mapUrlStart => {
return {
mapUrlStart: mapUrlStart,
startInstance: "global", //todo: is this property still usefull?
}
});
}
getPlayerName(): string {
return this.playerName;
}
2020-05-03 15:51:16 +02:00
getCharacterSelected(): string[] {
return this.characterLayers;
}
loadMap(mapUrl: string, scene: Phaser.Scenes.ScenePlugin, instance: string): string {
2020-06-09 23:13:26 +02:00
const sceneKey = GameScene.getMapKeyByUrl(mapUrl);
2020-06-09 23:13:26 +02:00
const gameIndex = scene.getIndex(sceneKey);
if(gameIndex === -1){
2020-06-09 23:13:26 +02:00
const game : Phaser.Scene = GameScene.createFromUrl(mapUrl, instance);
scene.add(sceneKey, game, false);
}
return sceneKey;
}
}
export const gameManager = new GameManager();