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

72 lines
2.0 KiB
TypeScript
Raw Normal View History

import {GameScene} from "./GameScene";
import {
Connection,
GroupCreatedUpdatedMessageInterface,
ListMessageUserPositionInterface,
MessageUserJoined,
MessageUserMovedInterface,
MessageUserPositionInterface,
Point,
PointInterface, StartMapInterface
} from "../../Connection";
2020-06-03 22:32:43 +02:00
import {SimplePeer} from "../../WebRtc/SimplePeer";
import {AddPlayerInterface} from "./AddPlayerInterface";
import {ReconnectingScene, ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
import ScenePlugin = Phaser.Scenes.ScenePlugin;
import {Scene} from "phaser";
import Axios from "axios";
import {API_URL} from "../../Enum/EnvironmentVariable";
export interface HasMovedEvent {
direction: string;
moving: boolean;
x: number;
y: number;
}
2020-04-07 20:41:35 +02:00
export interface MapObject {
key: string,
url: string
}
export class GameManager {
private playerName: string;
private characterUserSelected: string;
2020-04-07 20:41:35 +02:00
2020-06-22 16:10:34 +02:00
public storePlayerDetails(name: string, characterUserSelected : string): void {
this.playerName = name;
this.characterUserSelected = characterUserSelected;
}
loadStartMap() : Promise<StartMapInterface> {
return Axios.get(`${API_URL}/start-map`)
.then((res) => {
return res.data;
}).catch((err) => {
console.error(err);
throw err;
});
}
getPlayerName(): string {
return this.playerName;
}
2020-05-03 15:51:16 +02:00
getCharacterSelected(): string {
return this.characterUserSelected;
}
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();